Databases Reference
In-Depth Information
Table 4-12 Allowed XML host variable data types
Data type
XML data encoding
CLOB( n )
Application mixed code page stored in CLOB host variable.
DBCLOB( n )
Application graphic code page stored in DBCLOB host variable.
BLOB( n )
Internally encoded in a BLOB host variable.
CLOB_FILE
Application mixed code page stored in CLOB file.
DBCLOB_FILE
Application graphic code page stored in DBCLOB file.
BLOB_FILE
Internally encoded in a BLOB file.
Once the host variable declarations are done, we can write code to process SQL
statements using XML data in the same way we write code to process other
types of SQL statements. Refer to Chapter 2, “Application development with DB2
pureXML” on page 49 to obtain information about how to write SQL statements to
interact with data of the DB2 XML data type.
Selecting XML data using embedded SQL
Example 4-35 below shows a simple example of how to retrieve an XML column
in embedded SQL.
Example 4-35 Retrieving an XML column using embedded SQL
EXEC SQL BEGIN DECLARE SECTION;
SQL TYPE IS CLOB(10K) clob1;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO sample;
EXEC SQL SELECT description INTO :xmlClob1 FROM product WHERE
PID='100-100-01';
printf("XML data length: %d\nXML data: %s",clob1.length,clob1.data);
EXEC SQL COMMIT;
EXEC SQL CONNECT RESET;
In Example 4-35, we first declare a host variable of character LOB type to hold
the serialized string format of our XML data. The precompile form of the clob1
host variable shows that clob1 is a structure with a length and data field:
struct clob1_t {
sqluint32 length;;
char data[10240];
} clob1;
 
Search WWH ::




Custom Search