[freetds] FreeTDS dbwillconvert discrepancy
Joe Losco
joe at sqpuv.com
Sun Nov 30 10:46:53 EST 2008
James K. Lowden wrote:
> 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. :-(
>
>
No problem at all, I was just confused by the documentation that I had
found later.
>> 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.
>
>
I am linking to a compiled framework however it is the same framework
for both the C and the Obj-C version.
> 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?
>
>
This is probably what is happening as it makes the most sense. No glue
code is needed. Obj-C can directly call all C programs and all C code
is valid Obj-C code. But what you said about Obj-C interpreting any non
zero value as true makes the most sense to me. What I wonder then is
there something I can do to make this work without having to change the
FreeTDS headers (because I would assue a type change would be a
recompile and change to the actual library? I am relatively new to C
and ObjC, so I'm not too experienced in this department.
>> 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.
>
No problem, glad I could help, and thanks for the feedback :)
Joe
More information about the FreeTDS
mailing list