Databases Reference
In-Depth Information
Now let us try connecting to an invalid database and see what is provided by the
diagnostic function. We run a program with the following lines:
SQLConnect(conn_handle, "samdple", SQL_NTS, NULL, SQL_NTS, NULL,
SQL_NTS);
SQLGetDiagRec(SQL_HANDLE_DBC, conn_handle, 1, SQLState,
&nativeErrorCode, msgText, sizeof(msgText), &msgTextLength);
printf("SQLState: %s\nNative Error: %d\nError Message Text:
%s",SQLState, nativeErrorCode,msgText);
This produces the following output to let us know the database name was
incorrectly specified:
SQLState: 08001
Native Error: -1013
Error Message Text: [IBM][CLI Driver] SQL1013N The database alias name
or database name "SAMDPLE" could not be found. SQLSTATE=42705
4.6 XML support
The XML data type is supported for use in embedded SQL and CLI applications.
We briefly discuss how to work with the data type within C/C++ applications.
4.6.1 Embedded SQL
Embedded applications can make use of XML, LOB, or LOB_FILE data types
when working with XML data in a DB2 database. If you choose to use XML host
variables, they will be implicitly parsed, whereas using host variables of
character and binary data type might not be. For dynamic SQL, CLOB, and
BLOB are also implicitly parsed. For static SQL, an explicit XMLPARSE() will be
injected in the SQL statement, but only for CLOB and BLOB (not DBCLOB). To
declare host variables to handle XML data, we do so in the DECLARE section as
we normally would for host variables of other data types. For XML host variables,
we can use declarations of the form:
SQL TYPE IS XML AS < base type > < host var >
In the above statement, < host var > denotes the host variable name, and < base
type > denotes the data type of the XML host variable. The possible values are
listed in Table 4-12 on page 192.
Search WWH ::




Custom Search