Skip to Content.
Sympa Menu

freetds - [freetds] Row-wise parameter array binding bug in 0.64

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Levente Tamási (IJ/ETH) <Levente.Tamasi AT ericsson.com>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Row-wise parameter array binding bug in 0.64
  • Date: Thu, 7 Sep 2006 15:06:28 +0200

Dear All,

I have found a bug concerning row-wise parameter array binding in the ODBC
interface of freetds 0.64. When trying to insert multiple rows with row-wise
binding (using the SQL_ATTR_PARAMSET_SIZE and SQL_ATTR_PARAM_BIND_TYPE
statement attributes), I found that the first two rows are inserted
correctly; however, instead of the rest of the rows in the batch, the second
line is inserted over and over. Upon inspecting the problem, I have found
that the error is in odbc/sql2tds.c, near line 207:

<snip>
src = drec_apd->sql_desc_data_ptr;
if (src && stmt->curr_param_row) {
if (stmt->apd->header.sql_desc_bind_type !=
SQL_BIND_BY_COLUMN) {
src += stmt->apd->header.sql_desc_bind_type;
if (stmt->apd->header.sql_desc_bind_offset_ptr)
src +=
*stmt->apd->header.sql_desc_bind_offset_ptr;
} else {
</snip>

It can be seen that the address of the parameter value is calculated by
adding the row size to the start address for all rows except for the first
one. Thus, the code gives the correct address for only the first two rows.
Fix:

<snip>
src = drec_apd->sql_desc_data_ptr;
if (src && stmt->curr_param_row) {
if (stmt->apd->header.sql_desc_bind_type !=
SQL_BIND_BY_COLUMN) { src +=
stmt->curr_param_row * stmt->apd->header.sql_desc_bind_type;
if (stmt->apd->header.sql_desc_bind_offset_ptr)
src +=
*stmt->apd->header.sql_desc_bind_offset_ptr;
} else {
</snip>

This calculates the correct address for all rows.

Cheers,
Levi






Archive powered by MHonArc 2.6.24.

Top of Page