Skip to Content.
Sympa Menu

freetds - [freetds] Patch for ODBC binary data.

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Gerhard Esterhuizen <gerhard.esterhuizen AT swistgroup.com>
  • To: freetds <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Patch for ODBC binary data.
  • Date: 25 Apr 2003 12:18:18 -0200


Hi,

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
src/odbc/convert_sql2string.c:convert_sql2string().

2. Add src/odbc/convert_sql2string.c:convert_binary2string().

3. Add handling of SQL_C_BINARY to
src/odbc/convert_tds2sql.c:convert_tds2sql().

4. Add handling of SQL_BINARY and SQL_VARBINARY in
src/odbc/prepare_query:_get_sql_textsize().


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.


Regards,

gerhard.




--

Gerhard Esterhuizen
Software Engineer
SWiST Group Technologies (Pty) Ltd
email: gerhard.esterhuizen AT swistgroup.com
Cell: +27 82 370 9737

Web: http://www.swistgroup.com
Voice: +27 21 888 7920, Fax: +27 21 888 7979
Click here to view our e-mail legal notice:
http://www.swistgroup.com/email.htm or call: +27 21 888 7920.





Archive powered by MHonArc 2.6.24.

Top of Page