[freetds] Re: Inserting empty strings into MS SQL Server

Charles Bearden Charles.F.Bearden at uth.tmc.edu
Mon Aug 9 17:58:35 EDT 2004


> -----Original Message-----
> From: freetds-bounces at lists.ibiblio.org [mailto:freetds-
> bounces at lists.ibiblio.org] On Behalf Of Scott Johnson
> Sent: Monday, August 09, 2004 3:35 PM
> 
> *This message was transferred with a trial version of CommuniGate(tm)
Pro*
> ahh ok, my mistake.  Could have been an easy fix :)

Nice thought.

I googled on the error message "Length or precision specification 0 is
invalid" and found a bug[1] in Mono concerning the SqlClient component
throwing an exception with the same message when preparing a statement
in which a string or binary parameter value has a length of 0 (for
strings, an empty string).  Judging from the TDSDUMP trace I included
previously, my INSERTs are also failing at the prepare stage
("Statement(s) could not be prepared").

A patch[2] was also posted in bugzilla and integrated into the code.  I
don't know C or C++, so I can't necessarily identify the corresponding
part of the FreeTDS source code, but I did find what looks like a
similar part of the FreeTDS code (freetds-0.62.4/src/tds/convert.c,
starting at line 1598).  In the definition of the tds_convert function
is the following assert statement (line 1621):

  assert(srclen >= 0 && srclen <= 2147483647u);

However, the comments indicate that srclen is assumed to be greater than
0 (lines 1606f):

 * This function do not handle NULL, srclen should be >0, if not
undefinited
 * behaviour...

I also note that in freetds-0.62.4/src/tds/convert.c (line 702ff) is a
tds_submit_prepare function definition.  I seem to see the
"s\0p\0_\0p\0r\0e\0p\0a\0r\0e" string at line 793 in the TDSDUMP output,
which makes me wonder if the error is raised after that point (in
tds7_put_query_params?).

I may have this all wrong, but I thought I'd at least make the effort to
look at the source code to see if I could help think this problem
through.

Thanks in advance for any further ideas,
Chuck

[1] http://bugzilla.ximian.com/show_bug.cgi?id=49856
[2] http://bugzilla.ximian.com/showattachment.cgi?attach_id=5668

> ----- Original Message -----
> From: "Joseph Geiser" <joe at mail.paravisions.com>
> To: "'FreeTDS Development Group'" <freetds at lists.ibiblio.org>
> Sent: Monday, August 09, 2004 4:06 PM
> Subject: RE: [freetds] Re: Inserting empty strings into MS SQL Server
> 
> 
> > *This message was transferred with a trial version of
CommuniGate(tm)
> Pro*
> > Scott Johnson writes,
> >
> > > I might be incorrect in stating this, but doesn't ('') equate
> > > itself to
> > > one apostrophe for the purpose of inserting that?
> > >
> > >
> > > (1, 'foo', ' ', '', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo',
'foo',
> > > 'foo',
> > >  'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo', 'foo')
> >
> >
> > Not in an INSERT, where the only characters in a column are '' --
this
> > translates to "empty string" (not NULL).  If the value had
characters
> and
> a
> > double-apostrophe (ie: 'O''Malley') - then it would be an escaped
> > apostrophe.
> >
> > HTH...
> >
> > Joe
> >
> > _______________________________________________
> > FreeTDS mailing list
> > FreeTDS at lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/freetds
> 
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds



More information about the FreeTDS mailing list