2 Using The Product : Persisting a Result Set as an XML Data File

Persisting a Result Set as an XML Data File
The DataDirect Connect Series for ODBC drivers allow you to persist a result set as an XML data file with embedded schema. To implement XML persistence, a client application must do the following:
1
SQLSetStmtAttr (hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_STATIC, SQL_IS_INTEGER)
NOTE: A result set can be persisted as an XML data file only if the result set is generated using STATIC cursors. Otherwise, the following error is returned:
Driver only supports XML persistence when using driver’s static cursors.
2
SQLExecDirect (hstmt, "SELECT * FROM GTABLE", SQL_NTS)
3
SQLSetStmtAttr (hstmt, SQL_PERSIST_AS_XML, "C:\temp\GTABLE.XML", SQL_NTS)
NOTE: A statement attribute is available to support XML persistence, SQL_PERSIST_AS_XML. A client application must call SQLSetStmtAttr with this attribute as an argument. See the following table for the definition of valid arguments for SQLSetStmtAttr.
SQL_PERSIST_AS_XML. This statement attribute can be found in the file qesqlext.h, which is installed with the driver.
Pointer to a URL that specifies the full path name of the XML data file to be generated. The directory specified in the path name must exist, and if the specified file name exists, the file will be overwritten.
The length of the string pointed to by ValuePtr or SQL_NTS if ValuePtr points to a NULL-terminated string.
A client application can choose to persist the data at any time that the statement is in an executed or cursor-positioned state. At any other time, the driver returns the following message:
Function Sequence Error
Using the Windows XML Persistence Demo Tool
The 32-bit drivers for Windows are shipped with an XML persistence demo tool. This tool is installed in the product installation directory.
The tool has a graphical user interface and allows you to persist data as an XML data file.
To use the Windows XML Persistence Demo tool:
1
From the product program group, select XML Persistence Demo. The XMLPersistence dialog box appears.
XML Persistence dialog box
2
First, you must connect to the database. Click Connect. The Select Data Source dialog box appears.
Select Data Source dialog box (File Data Source tab)
3
Create a new file data source by clicking New. The Create New Data Source dialog box appears. Follow the instructions in the dialog box.
Create a new machine data source by clicking the Machine Data Source tab and clicking New. The Create New Data Source dialog box appears. Follow the instructions in the dialog box.
4
After you have connected to a database, type a SQL Select statement in the Query text box of the XML Persistence dialog box. Then, click Persist. The Save As dialog box appears.
5
Note that the Status box in the XML Persistence dialog box displays whether the action failed or succeeded.
6
Click Disconnect to disconnect from the database.
7
Click Close to exit the tool.
Using the UNIX/Linux XML Persistence Demo Tool
On UNIX and Linux, the drivers are shipped with an XML persistence demo tool named demoodbc. This tool is installed in the installation directory, in the /samples/demo subdirectory. For information about how to use this tool, refer to the demoodbc.txt file installed in the demo subdirectory.