[freetds] [PATCH] Problem with VARCHAR in sybase.

James K. Lowden jklowden at freetds.org
Mon Jun 30 23:13:23 EDT 2008


Eddy Pronk wrote:
> My database had a table with a column which was VARCHAR(20)
> One of the rows had exactly 20 characters.
> With a simple SELECT it hit this piece of code which returns CS_FAIL
> without logging anything:
> 
> 538                 case CS_FMT_NULLTERM:
...
> I included a patch below.
...
> If I allocate 1 byte extra for the null terminator my query works.

Thank you for the patch.  You've highlighted a problem, but I don't think
your fix is the right one.  

In the first place, ct-lib needs some time and attention paid to error
messages.  There are many places where it works if used correctly but
fails silently (except for the return code) if not.  We need a function
similar to dbperror().  

Second, afaict CS_FMT_NULLTERM is invalid in cs_convert (cf. 
http://manuals.sybase.com:80/onlinebooks/group-oc/ocg1250e/occpr/@ebt-link;pt=2420?target=%25N%14_2686_START_RESTART_N%25).
 

Third, even if valid, istm the code is basically right: if the destination
buffer does not have room for a NULL terminator and the format
specification for the conversion demands one, the conversion should fail. 


If I'm missing something, please explain.  

Regards, 

--jkl



More information about the FreeTDS mailing list