[freetds] "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?

Karen Pease Karen.Pease at isavia.is
Tue Aug 9 03:57:50 EDT 2016

Thank you.  The calloc call is in a subfunction, with the following local variables:

   p_nbblk: count     
   p_size: sizeof(Con_area)

The code therein, with added debugging info (four attempts to narrow down the problem), is:

bufp = (char *) calloc (1, 1); // Attempt #1: Smallest possible calloc
printf("%d: %d: %d, %s\n", __LINE__, bufp, errno, strerror(errno));
if (bufp) free(bufp);
bufp = (char *) calloc (4, 184); // Attempt #2: Actual values of what we should be allocating
printf("%d: %d: %d, %s\n", __LINE__, bufp, errno, strerror(errno));
if (bufp) free(bufp);
size_t a = p_nbblk, b=p_size;
bufp = (char *) calloc (a, b); // Attempt #3: using temporary variables
printf("%d: %d: %d, %s\n", __LINE__, bufp, errno, strerror(errno));
if (bufp) free(bufp);
        bufp = (char *) calloc ((size_t) p_nbblk, (size_t) p_size); // Attempt #4: Actual code
printf("%d: %d: %d, %s\n", __LINE__, bufp, errno, strerror(errno));

 * The first attempt works
 * The second attempt works
 * The third attempt fails, errno 12
 * The fourth attempt fails, errno 12

So, as you can see, passing in the value of "count" returned from the select statement and fetched by dbnextrow causes a failure.

int32 is defined as:

  typedef long int int32;

I can't speak to what the standard is supposed to do, I can only attest to the fact that the code worked when linked with sybase and is no longer working now that I'm trying to use it with FreeTDS.

 - kv, Karen

Frá: FreeTDS <freetds-bounces at lists.ibiblio.org> fyrir hönd Frediano Ziglio <freddy77 at gmail.com>
Sent: 7. ágúst 2016 15:00
Til: FreeTDS Development Group
Efni: Re: [freetds] "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?

2016-08-06 18:58 GMT+01:00 Karen Pease <Karen.Pease at isavia.is>:
> 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

FreeTDS mailing list
FreeTDS at lists.ibiblio.org

More information about the FreeTDS mailing list