XML column inserts and updates in CLI applications
For XML data, when you use SQLBindParameter() to
bind parameter markers to input data buffers, you can specify the
data type of the input data buffer as SQL_C_BINARY, SQL_C_CHAR, SQL_C_DBCHAR
or SQL_C_WCHAR. When you bind a data buffer that contains XML data
as SQL_C_BINARY, CLI processes
the XML data as internally encoded data. This is the preferred method
because it avoids additional resource usage and potential data loss
of character conversion when character types are used.
- If the C type is SQL_C_WCHAR, CLI assumes that the data is encoded as UCS-2.
- If the C type is SQL_C_CHAR or SQL_C_DBCHAR, CLI assumes that the data is encoded in the application code page encoding scheme.
If you want the database server to implicitly parse the data before
storing it in an XML column, the parameter marker data type in SQLBindParameter() should
be specified as SQL_XML.
Implicit parsing is recommended, because explicit parsing of a character type with XMLPARSE can introduce encoding issues.
char xmlBuffer[10240];
integer length;
// Assume a table named dept has been created with the following statement:
// CREATE TABLE dept (id CHAR(8), deptdoc XML)
// xmlBuffer contains an internally encoded XML document that is to replace
// the existing XML document
length = strlen (xmlBuffer);
SQLPrepare (hStmt, "UPDATE dept SET deptdoc = ? WHERE id = '001'", SQL_NTS);
SQLBindParameter (hStmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_XML, 0, 0,
xmlBuffer, 10240, &length);
SQLExecute (hStmt);