Skip to Content.
Sympa Menu

freetds - [freetds] FreeTDS always setting empty VARCHAR's to NULL

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Andrew Victor <avictor.za AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] FreeTDS always setting empty VARCHAR's to NULL
  • Date: Sun, 24 May 2009 23:47:56 +0200

hi,

It seems that calling ct_param() with an empty string (ie, data !=
NULL and datalen = 0), a NULL gets passed to the database rather than
an empty string.

According to the Sybase documentation for ct_param:

"There are two ways to indicate a parameter with a null value:
- Pass indicator as -1. In this case, data and datalen are ignored.
- Pass data as NULL and datalen as 0 or CS_UNUSED"

As far as I can determine, ct_param() calls _ct_fill_param() which
does all the proper checks as per the Sybase docs, but then it does:
if (*(param->datalen) && data) {
...
}
else {
param->value = NULL;
*(param->datalen) = 0;
param_is_null = 1;
}

So the data pointer ("value") gets changed to NULL.


Then later when ct_send() is called, paraminfoalloc() is called which
calls paramrowalloc() which has the code:
if (size > 0 && value) {
....
}
else {
tdsdump_log(TDS_DBG_FUNC, "paramrowalloc(): setting parameter
#%d to NULL\n", param_num);
curcol->column_cur_size = -1;
}

And since value was changed to NULL (in _ct_fill_param()), this is
where the NULL gets sent to the DB.


This is in FreeTDS 0.82. I don't see any changes to these function in
the latest development version, so the problem most likely occurs with
it aswell.

Is there a fix/patch available?
Any suggestions on the proper way to fix it?


Regards,
Andrew Victor



  • [freetds] FreeTDS always setting empty VARCHAR's to NULL, Andrew Victor, 05/24/2009

Archive powered by MHonArc 2.6.24.

Top of Page