Databases Reference
In-Depth Information
Example 4-38 Updating XML column in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlenv.h>
#include <sqlutil.h>
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char xmldata[2000];
char parse_option[30];
static SQL TYPE IS XML AS CLOB(1k) xmlclob1=SQL_CLOB_INIT(" ") ;
EXEC SQL END DECLARE SECTION;
int main(int argc, char *argv[])
{
int rc = 0;
/* Create a XML document that will be used to INSERT in the table */
strcpy (xmldata, "<product xmlns=\"http://posample.org\"
pid=\"102-102-02\">"
"<description><name> Shovel </name>"
"<details>Basic Shovel, 22 inches wide, straight
handle with D-Grip</details>"
"<price>9.99</price>"
"<weight>1.5 kg</weight>"
"</description></product>");
strcpy(xmlclob1.data, xmldata);
xmlclob1.length = strlen(xmldata) + 1;
/* check the command line arguments */
EXEC SQL CONNECT TO sample;
/* Update the XML column using host variable of type XML */
printf(" Update XML column using variable of type XML\n");
EXEC SQL UPDATE product SET DESCRIPTION = :xmlclob1 WHERE pid =
'102-102-02';
if (sqlca.sqlcode != 0)
{
printf("\nUpdate failed\n");
Search WWH ::




Custom Search