Implementing XML Persistence
With the addition of one or two lines of code to existing ODBC applications, you can use a new feature in MERANT's DataDirect Connect ODBC 3.7 drivers to retrieve result sets from a relational database (such as Oracle, Informix, DB2, or Sybase) and store the result sets as XML data files.
A new feature in MERANT's DataDirect Connect ODBC 3.7 release enables you to retrieve result sets from a relational database (such as Oracle, Informix, DB2, or Sybase) and store the result sets as XML data files. You don't have to replicate the data or manually reformat the data-you just add one or two lines of code to your existing ODBC application and an XML data file is created.
The ODBC application must:
1. Turn on STATIC cursors. For example:
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.
2. Execute a SQL statement. For example:
SQLExecDirect (hstmt, "Select * from GTABLE", SQL_NTS)
3. Persist the result set as an XML data file. For example:
SQLSetStmtAttr (hstmt, SQL_PERSIST_AS_XML, "c:tempGTABLE.XML", SQL_NTS)
Note: A new statement attribute is available to support XML persistence, SQL_PERSIST_AS_XML. A client application must call SQLSetStmtAttr with this new attribute as an argument. See the following table for the definition of valid arguments for SQLSetStmtAttr.
|StatementHandle||The handle of the statement that contains the result set to persist as XML.|
|Attribute||SQL_PERSIST_AS_XML. This new statement attribute can be found in the file qesqlext.h, which is installed with the driver.|
|ValuePtr||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.|
|StringLength||The length of the string pointed to by ValuePtr or SQL_NTS if ValuePtr points to a null terminated string.|
An ODBC application can choose to persist the data at any time that the statement is in an executed or cursor-positioned state.
The ability to persist result sets as XML data files helps you take advantage of XML faster as you adopt advanced B2B and B2C business processes on the Web. MERANT Connect ODBC drivers provide a simple way for you to use existing data and publish it on the Web. You just add one or two lines of code to your existing ODBC application and an XML data file is created.
John Goodson is vice president of research and development for the enterprise data connectivity technologies at MERANT, a leading provider of software solutions for enterprise change management; development, transformation and integration of legacy applications; and data connectivity. MERANT provides advanced data connectivity based on industry standards like ODBC, JDBC and ADO, to the commercial market.
Did you like this tip? We'd like to know what you think, so if you email us we can find out.
OLE DB and ODBC Developer's Guide
Author: Chuck Wood
Publisher: Hungry Minds
Published : Oct 1999
Starting where most books end, this savvy guide shows you how to hone your Visual C++ 6 data-access skills and develop sophisticated programs with new OLE DB and COM components, as well as the more traditional ODBC technologies.