Skip to Content.
Sympa Menu

freetds - [freetds] SQLGetData returns same value for subsequent calls?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Matt Lilley <matt.lilley AT securitease.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] SQLGetData returns same value for subsequent calls?
  • Date: Thu, 23 Nov 2006 11:28:58 +1300

Hi,

I've been trying to connect to my MS SQL 2k database using freeTDS and noticed that subsequent calls to SQLGetData seem to return the same value, at least on the columns I am interested in (large VARCHAR columns). My understanding is that even if all the data is returned in the first call then a subsequent call should return SQL_NO_DATA, but the case I was testing had only returned the first 128 bytes of the column. According to tds.h VARCHAR is not a blob_type, so in src/odbc/odbc.c (around line 4100) colinfo->column_text_sqlgetdatapos doesn't get incremented. Attached is a patch which fixes the symptoms for me, but is unlikely to be the correct solution (given that I know almost nothing about the internal workings of databases) In any case it should be sufficient for someone to spot the real problem and correct it. The patch is against the nightly build freetds-0.65.dev.20061121. I hope the format etc is acceptable - I only rarely submit patches!

Regards,
Matt

-- _____________________________________________
Matt Lilley
Software Engineer
SecuritEase

Tel: +64 4 917-6670
Fax: +64 4 917-6671
E-mail: matt.lilley AT securitease.com
Web: http://www.securitease.com
_____________________________________________

This e-mail passed SSS's content security scan.
It is covered by the confidentiality clauses at
http://www.sss.co.nz/content_and_confidentiality

--- freetds-0.65.dev.20061121/src/odbc/odbc.c	2006-10-19 08:39:47.000000000 +1300
+++ patched/src/odbc/odbc.c	2006-11-23 11:02:06.838665800 +1300
@@ -4139,6 +4139,11 @@
 			src = ((TDSBLOB *) src)->textvalue + colinfo->column_text_sqlgetdatapos;
 			srclen = colinfo->column_cur_size - colinfo->column_text_sqlgetdatapos;
 		} else {
+       if (colinfo->column_type == SYBVARCHAR)
+       {
+          src = (TDS_CHAR *) colinfo->column_data + colinfo->column_text_sqlgetdatapos;
+       }
 			srclen = colinfo->column_cur_size;
 		}
 		nSybType = tds_get_conversion_type(colinfo->column_type, colinfo->column_size);
@@ -4153,6 +4158,8 @@
 			/* calc how many bytes was readed */
 			int readed = cbValueMax;
 
+      
+
 			/* FIXME test on destination char ??? */
 			if (stmt->dbc->env->attr.output_nts != SQL_FALSE && nSybType == SYBTEXT && readed > 0)
 				--readed;
@@ -4164,6 +4171,19 @@
 				/* TODO add diagnostic */
 				ODBC_RETURN(stmt, SQL_SUCCESS_WITH_INFO);
 		}
+    else if (colinfo->column_type == SYBVARCHAR)
+    {
+       int readed = cbValueMax;
+       if (stmt->dbc->env->attr.output_nts != SQL_FALSE && readed > 0)
+       {
+          --readed;
+       }
+       if (*pcbValue < readed)
+          readed = *pcbValue;
+
+       colinfo->column_text_sqlgetdatapos += readed; 
+    }
 	}
 	ODBC_RETURN_(stmt);
 }


  • [freetds] SQLGetData returns same value for subsequent calls?, Matt Lilley, 11/22/2006

Archive powered by MHonArc 2.6.24.

Top of Page