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

Levente Tamási (IJ/ETH) Levente.Tamasi at ericsson.com
Thu Sep 7 09:06:28 EDT 2006


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





More information about the FreeTDS mailing list