Example: Query tool B

This example illustrates using one allocation statement for the entire call.

Query tool B allows you to update a spreadsheet of rows and then send the updates to the database. It makes the following ODBC calls:

   FOR every_row_updated DO
 
      SQLAllocHandle(SQL_HANDLE_STMT)
      SQLExecDirect("UPDATE...SET COLn='literal'...WHERE COLn='oldval'...")
      SQLFreeHandle( SQL_HANDLE_STMT )
 
   END LOOP

The first thing to note is that the tool performs a statement allocation-and-drop for every row. Only one allocate statement is needed. This change would save the overhead of creating and destroying a statement handle for every operation. Another performance concern is the use of SQL with literals instead of with parameter markers. The SQLExecDirect() call causes an SQLPrepare and SQLExecute every time. A faster way to perform this operation would be as follows:

   SQLAllocHandle(SQL_HANDLE_STMT)
   SQLPrepare("UPDATE...SET COL1=?...WHERE COL1=?...")
   SQLBindParameter( new_column_buffers )
   SQLBindParameter( old_column_buffers )
   FOR every_row_updated DO
 
      ...move each rows data into the SQLBindParameter buffers
      SQLExecute()
      SQLFreeHandle( SQL_HANDLE_STMT )
 
   END LOOP

These sets of ODBC calls will outperform the original set by a large factor when you are using the iSeries™ Access for Windows® ODBC driver. The server CPU utilization will decrease to 10 percent of what it was, which pushes the scaling threshold out a lot farther.