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

SourceForge.net noreply at sourceforge.net
Sat May 3 15:17:56 EDT 2003


Patches item #727555, was opened at 2003-04-25 17:46
Message generated for change (Settings changed) made by freddy77
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=407808&aid=727555&group_id=33106

Category: odbc
Group: None
>Status: Closed
>Resolution: Accepted
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.


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.



----------------------------------------------------------------------

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

Message:
Logged In: YES 
user_id=698709


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.

  gerhard


----------------------------------------------------------------------

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

Message:
Logged In: YES 
user_id=75766

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

Have you a test for this change?

freddy77


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=407808&aid=727555&group_id=33106



More information about the FreeTDS mailing list