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.

XML data is stored in an XML data type column in a table. Columns with the 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 or the SQL/XML extensions. 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.

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. graphic, and binary types, which include CHAR, VARCHAR, CLOB, DBCLOB, 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 whitespace stripping is applied.

To declare XML host variables in embedded SQL applications, in the declaration section of the application declare the XML host variables AS LOB data types. The examples shown here are for C, but similar syntax exists for the other supported languages.

  • SQL TYPE IS XML AS CLOB(n) <hostvar_name> to define a CLOB host variable that contains XML data encoded in the CCSID specified by the SQL_XML_DATA_CCSID QAQQINI file option.
  • SQL TYPE IS XML AS DBCLOB(n) <hostvar_name> to define a DBCLOB host variable that contains XML data. It is encoded in the CCSID specified by the SQL_XML_DATA_CCSID QAQQINI file option if the option is UCS-2 or UTF-16, otherwise the default CCSID is UTF-16.
  • SQL TYPE IS XML AS BLOB(n) <hostvar_name> to define a BLOB host variable that contains XML data internally encoded.
  • SQL TYPE IS XML AS LOCATOR <hostvar_name> to define a locator that contains XML data.
  • SQL TYPE IS XML AS CLOB_FILE <hostvar_name> to define a CLOB file that contains XML data encoded in the file CCSID.
  • SQL TYPE IS XML AS DBCLOB_FILE <hostvar_name> to define a DBCLOB file that contains XML data encoded in the application double-byte default CCSID.
  • SQL TYPE IS XML AS BLOB_FILE <hostvar_name> to define a BLOB file that contains XML data internally encoded.