parameters using 
SQLBindParameter(),
 and finally execution of the 
query using 
SQLExecute()
. Example 7 48 shows an example for 
prepared statements.
  Prepare and execute in a single step
If your query is executed only once, then you can use 
SQLExecDirect() 
to directly call, prepare, and execute in a single step. Example 7 49 
shows the usage of this method.
c. Processing results
Processing query results involves binding application variables to columns 
of a result set, and then fetching the rows of data into the application 
variables. This is done by calling 
SQLBindCol()
 followed by 
SQLFetch() 
as 
shown in Example 7 48. 
Another way to get data without binding the column is by calling 
SQLFetch()
 and 
SQLGetData()
, this technique is used in Example 7 49.
d. Committing or rolling back 
DB2 UDB supports two commit modes: auto commit and manual commit. 
This can be set using 
SQLSetConnectAttr()
 with the parameter 
SQL_AUTOCOMMIT_ON
 or
SQL_AUTOCOMMIT_OFF
. If a transaction is set to 
SQL_AUTOCOMMIT_OFF
 it is the programmer's responsibility to end the 
transaction. This can be done using 
SQLEndTran()
 to either rollback or 
commit the transaction using parameter 
SQL_COMMIT
 or 
SQL_ROLLBACK
. 
e. Deallocating statement handle
This requires unbinding of the variables, columns, or cursors (if allocated) 
using 
SQLFreeStmt()
 with the option of 
SQL_CLOSE
, SQL_UNBIND 
or 
SQL_RESET_PARAMS,
 and then finally calling
 SQLFreeHandle()
 to 
deallocate the statement handle.
Example 7 48   DB2 CLI prepared statement with column binding, auto commit on
SQLHANDLE hstmt; /* statement handle */
SQLINTEGER wk_id=10;
SQLINTEGER user_id;
SQLCHAR val[15];
/* SQL statements to execute */
SQLCHAR *stmt1 = (SQLCHAR *)"SELECT user_id,status FROM warenkorb where 
wk_id=?";
/* set AUTOCOMMIT on */
ret = SQLSetConnectAttr(hdbc,
SQL_ATTR_AUTOCOMMIT,
 Chapter 7. Application porting 
207






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

san diego web hosting

 

Our partners: PHP: Hypertext Preprocessor Cheap Web Hosting JSP Web Hosting Ontario Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Java Hosting Cheapest Hosting

Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved