Declaring XML host variables in embedded SQL applications
To exchange XML data between the database server and an embedded SQL application, you need to declare host variables in your application source code.
About this task
DB2® V9.1 introduces an XML data type that stores XML data in a structured set of nodes in a tree format. Columns with this XML data type are described as an SQL_TYP_XML column SQLTYPE, and applications can bind various language-specific data types for input to and output from these columns or parameters. XML columns can be accessed directly using SQL, the SQL/XML extensions, or XQuery. The XML data type applies to more than just columns. Functions can have XML value arguments and produce XML values as well. Similarly, stored procedures can take XML values as both input and output parameters. Finally, XQuery expressions produce XML values regardless of whether they access XML columns.
XML data is character in nature and has an encoding that specifies the character set used. The encoding of XML data can be determined externally, derived from the base application type containing the serialized string representation of the XML document. It can also be determined internally, which requires interpretation of the data. For Unicode encoded documents, a byte order mark (BOM), consisting of a Unicode character code at the beginning of a data stream is recommended. The BOM is used as a signature that defines the byte order and Unicode encoding form.
Existing character and binary types, which include CHAR, VARCHAR, CLOB, and BLOB may be used in addition to XML host variables for fetching and inserting data. However, they will not be subject to implicit XML parsing, as XML host variables would. Instead, an explicit XMLPARSE function with default white space stripping is injected and applied.
XML and XQuery restrictions on developing embedded SQL applications
To declare XML host variables in embedded SQL applications:
-
where <hostvar_name> is a CLOB host variable that contains XML data encoded in the mixed code page of the application.SQL TYPE IS XML AS CLOB(n) <hostvar_name> -
where <hostvar_name> is a DBCLOB host variable that contains XML data encoded in the application graphic code page.SQL TYPE IS XML AS DBCLOB(n) <hostvar_name> -
where <hostvar_name> is a BLOB host variable that contains XML data internally encoded1.SQL TYPE IS XML AS BLOB(n) <hostvar_name> -
where <hostvar_name> is a CLOB file that contains XML data encoded in the application mixed code page.SQL TYPE IS XML AS CLOB_FILE <hostvar_name> -
where <hostvar_name> is a DBCLOB file that contains XML data encoded in the application graphic code page.SQL TYPE IS XML AS DBCLOB_FILE <hostvar_name> -
where <hostvar_name> is a BLOB file that contains XML data internally encoded1.SQL TYPE IS XML AS BLOB_FILE <hostvar_name>