Re: FreeTDS dbwillconvert discrepancy

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.