Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you fetch or insert rows in batches using ODBC? ( in C or C++ )

Tags:

c++

c

odbc

I am trying to understand which ODBC functions to call and how to call them in order to fetch rows in batches or insert rows in batches ( inserts that use bind variables not just an array of insert statements ).

I can fetch one row at a time by calling these functions in order

SQLBindParameter
SQLExecute
SQLFetch

Also if doing inserts / updates I can do one row at a time by calling these functions

SQLBindParameter
SQLExecute

What I don't know is what I need to change in these calls in order to:

1) Fetch rows in batches e.g. 150 rows per batch
2) Insert several rows per SQLExcecute call e.g. 150 rows per call

Short contained examples ( not necessarily compilable since ODBC progs tend to be long .. so ignore setup/initialization, ignore error checking ) demonstrating how this is done would be helpful. Or a pointer to a comprehensible open source code that is doing this sort of thing

like image 686
user754425 Avatar asked Jun 29 '11 18:06

user754425


1 Answers

The following article tells you how to send rows of parameters in one go:

http://www.easysoft.com/products/data_access/odbc_odbc_bridge/performance_white_paper.html#3_1_2

Basically, you need to search for SQLSetStmtAttr and SQL_ATTR_PARAMSET_SIZE.

To fetch multiple rows in one go see http://www.easysoft.com/developer/languages/c/odbc-tutorial-fetching-results.html

Search for SQL_ATTR_ROW_ARRAY_SIZE.

like image 52
bohica Avatar answered Sep 25 '22 00:09

bohica