Re: "DB-lib error, no 20050, Attempt to convert data stopped by syntax error in source field" - FreeTDS trying to convert to SYBMONEY for some reason?

Frediano Ziglio <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <CAHt6W4ep-oCUQzFn8RCuXaj+JsT0H6DwZD3U4Hac0en-R6YSrQ@mail.gmail.com>
2016-08-06 18:58 GMT+01:00 Karen Pease <[email protected]>:
> That indeed was the problem - thanks a bunch  :)  I didn't have the sybase package installed, which was confusing, but apparently our app has some of the sybase headers in its include directory; I had to remove them.
>
> One more piece of weirdness I'm hitting... and it took me a long time to track down:
>
>         int32 count;
> ...
>         dbcmd (ET_fillas_dbp1, " select count(*) ");
>         dbcmd (ET_fillas_dbp1, " from AIRSPACE_BOUND ");
>         dbfcmd (ET_fillas_dbp1, " where Airspace_Vol_Name = '%s' ", volname);
>         dbsqlexec (ET_fillas_dbp1);
>         if (dbresults (ET_fillas_dbp1) != SUCCEED)
>             return;
>         dbbind (ET_fillas_dbp1, 1, INTBIND, (DBINT) 0, &count);
>         dbnextrow (ET_fillas_dbp1);
>         printf("%d, %X, %lX\n", __LINE__, count, count, count);
>
> So, obviously, count is just an integer, it should never be negative.  For example, if I run that query in in tsql, it returns '4'.  But the output in the code is:
>
> 4 4 7FFF00000004
>
> ... as if it's doing some sort of weird negative conversion (???).  It took a long time to catch because when I was just printing it out with "%d" it looked fine, but it was crashing me in a calloc statement.
>

I don't know your system but I suppose that sizeof(int) == 4 and
sizeof(long) == 8 and you are doing something bad with printf. INTBIND
is supposed to write a 4 byte integer. Explaining what's going on
requires to understand how does variadic functions work and the
architecture you are using.
I cannot see the calloc call.
How is defined the int32? Usually DBINT is safer.

> Any clue what's going on there?  The dump ends:
>
> dblib.c:2031:dbnextrow(0x1afeb80)
> dblib.c:2043:dbnextrow() dbresults_state = 2 (_DB_RES_RESULTSET_ROWS)
> token.c:549:tds_process_tokens(0x1aff550, 0x7ffe79928be4, (nil), 0x1508)
> util.c:165:Changed query state from PENDING to READING
> token.c:564:processing result tokens.  marker is  d1(ROW)
> token.c:1951:tds_process_row(): reading column 0
> data.c:534:tds_get_data: type 56, varint size 0
> data.c:587:tds_get_data(): wire column size is 4
> util.c:165:Changed query state from READING to PENDING
> buffering.h:305:buffer_transfer_bound_data(0x1afeb90 4040 -1 0x1afeb80 0)
> dblib.c:7210:copy_data_to_host_var(56 [SYBINT4] len 4 => 56 [SYBINT4] len 0)
> dblib.c:7252:copy_data_to_host_var() srctype == desttype
> dblib.c:2117:leaving dbnextrow() returning REG_ROW/MORE_ROWS
>
>  - kv, Karen
>

Frediano
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.