[freetds] [ freetds-Patches-727555 ] Patch for ODBC binary data.

SourceForge.net noreply at sourceforge.net
Tue Apr 29 04:59:15 EDT 2003

Patches item #727555, was opened at 2003-04-25 15:46
Message generated for change (Comment added) made by gmpff
You can respond by visiting: 

Category: odbc
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Gerhard Esterhuizen (gmpff)
Assigned to: Nobody/Anonymous (nobody)
Summary: Patch for ODBC binary data.

Initial Comment:

Sorry for the double post, but the mailing list
stripped the attachment from my first attempt. Please
let met know if there are any other issues.


Attached is a patch that allows the FreeTDS ODBC driver
to handle binary data (SQL types SQL_BINARY and
SQL_VARBINARY and C type SQL_C_BINARY). This allows
binary data (IMAGE fields and void*/length) to be read
and written using the ODBC interface.

The patches were created against nightly snapshot of
17/03/2003 (i.e. freetds-0.62.dev.20030317). I didn't
do it against the CVS snapshot as my automake/autoconf
complained about missing files (e.g. config.h.in) -
probably due to old autotools). The latest nightly
snapshot (25/04/2003) built fine, but refused to
authenticate (unixODBC gave "Login incorrect.").

The patch does the following:

1. Add handling of SQL_C_BINARY to

2. Add

3. Add handling of SQL_C_BINARY to

4. Add handling of SQL_BINARY and SQL_VARBINARY in

My motivation for creating these patches are:

1. The existing convert_sql2string didn't handle a
source type of
SQL_C_BINARY specially, but forwarded to tds_convert() (in
src/tds/convert.c) which didn't work (due to the
omission of the "0x" prefix in the encoded string -
changing this would probably have broken other
interfaces depending on tds_convert).

2. Returning a binary field as a hex-encoded C string
(i.e. SQL type SQL_BINARY and C type SQL_C_CHAR)
doesn't work properly due to a bug in SQLGetData() (in
src/odbc/odbc.c): convert_tds2sql() returns the size of
the converted buffer, but it is used as an offset into
the source buffer. As each binary source byte gets
converted to two bytes, this doesn't work.

I hope these patches don't break anything else and
works as advertised.




>Comment By: Gerhard Esterhuizen (gmpff)
Date: 2003-04-29 08:59

Logged In: YES 

Thanks for incorporating the patch. Attached is a test for
it. It writes a binary pattern into an IMAGE field, reads it
back an compares the input and output buffers. Instructions
are in the README file.

As for the terminator: if I understand
start_parse_prepared_query() correctly and it reserves space
for a terminator (mallocs len + 1), it would be right to
change the +3 into a +2.



Comment By: Frediano Ziglio (freddy77)
Date: 2003-04-25 17:07

Logged In: YES 

Seem correct (not tested, also cause it fix a memory leak).
Perhaps +3 in prepare_call.c should be 2 (terminator

Have you a test for this change?



You can respond by visiting: 

More information about the FreeTDS mailing list