Skip to Content.
Sympa Menu

freetds - Re: [freetds] FreeTDS dbwillconvert discrepancy

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] FreeTDS dbwillconvert discrepancy
  • Date: Sat, 29 Nov 2008 20:38:53 -0500

Joe Losco wrote:
>
> My problem that I've narrowed it down to is with this stub of code
> if (SYBCHAR != pcol->type) {
> pcol->size = dbwillconvert(pcol->type, SYBCHAR);
> }
>
> I've placed "printf("name:%s type:%d size:%d\n", pcol->name,
> pcol->type, pcol->size);" around this piece of code so that I can see
> the before and after effects. In the command line pure C application
> dbwillconvert returns the size of the would be data converted to the
> correct type. This then lets the memory be allocated properly in the
> later calloc that uses pcol->size+1, as well as everything else to work
> as intended.

Yes, that's my code.

db-lib as specified and implemented by the vendors offers no way to
discover the printed length of a non-character value. FreeTDS extends
dbwillconvert() to do that: instead of a simple boolean, it returns the
number of bytes needed for a character representation. I'm sorry it's not
better documented. :-(

> However, in the Objective C/GUI version it appears to return a Bool. It
>
> seems to return 1 if it is convertable and 0 if it is not. This
> obviously messes up the rest of the allocations in the sample resulting
> in truncation and overflow errors.

My first instinct was to wonder if in fact you're linking to FreeTDS and
not one of the vendor libraries, or perhaps to a version prior to 0.82. I
assume none of those is the case.

My second guess is to wonder if Objective C is looking at the header file
(or something like that), interpreting each nonzero return code as "true",
and returning only 0 or 1. Is there glue code that allows Objective C to
call a C library? Is there some preprocessing that gets done to make C
functions available to it?

If so, the solution might be to define the function as returning DBINT
instead of DBBOOL. Or something like that.

> I then looked into this farther and
> found http://www.freetds.org/reference/a00275.html#ga24 which from what
> I can tell is that the desired effect of that function is to return the
> bool.

Ouch. Yes. I'll update that. Thanks for pointing it out.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page