Databases Reference
In-Depth Information
DESCRIPTION column from the PRODUCT table. The column in the database is
of type xml. We can do the following (Example 4-39).
Example 4-39 Retrieving an XML column using CLI
SQLCHAR description[10001];
SQLINTEGER ind;
SQLAllocHandle(SQL_HANDLE_STMT, conn_handle, &stmt_handle);
SQLExecDirect(stmt_handle, "select description from product where
PID='100-100-01'", SQL_NTS);
SQLBindCol(stmt_handle, 1, SQL_C_CHAR, description,
sizeof(description), &ind);
SQLFetch(stmt_handle);
printf("%s",description);
In Example 4-39, we declare a buffer called DESCRIPTION to hold the returned
value from the database. We call SQLExecDirect() to execute the SELECT
statement, and call SQLBindCol() to bind the returned column value to the
application storage buffer named description. We specify SQL_C_CHAR as the
C data type because we are expecting the xml to be converted to a CLOB in our
XMLSERIALIZE call. Running the program produces the output as shown in
Example 4-40.
Example 4-40 Output from running Example 4-39
<?xml version="1.0" encoding="ISO-8859-1" ?>
<product xmlns="http://posample.org"
pid="100-100-01"><description><name>Snow Shovel, Basic 22
inch</name><details>Basic Snow Shovel, 22 inches wide, straight handle
with D-Grip</details><price>9.99</price><weight>1
kg</weight></description></product>
Search WWH ::




Custom Search