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

Andrew Victor avictor.za at gmail.com
Sun May 24 17:47:56 EDT 2009


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?

  Andrew Victor

More information about the FreeTDS mailing list