Subject API: Retrieve/fetch numerical data from database (like an integer/long)
Author Henrik Sitter
Hello,

I'm working on and off with the Firebird API, and right now I'm trying
to retrieve/fetch data from my test database.

As long as the data is stored as VarChar or char, everything works like
it should, but when it's stored as numerical data (like an integer), the
database returns just BS.

In the coercing and allocating part of my code I use (I suspect
something is wrong here):

#define ALIGN(ptr, n) ((ptr + n - 1) & ~(n - 1))
char *r_buffer, *rec_buffer;
.
.
case SQL_LONG:
r_buffer = (char *)malloc(sizeof(long)+sizeof(int));
rec_buffer = (char *)ALIGN((long)r_buffer, (sizeof(long)+sizeof(int)));
var->sqldata = (char *)((long)rec_buffer);
break;
.
.

In the fetching part I use (this part works, at least when fetching char
and VarChar):

.
.
int fetch_stat;
while ((fetch_stat = isc_dsql_fetch(status_vector, &st1, 1, my_xsqlda))
== 0)
{
for (i = 0; i < my_xsqlda->sqld; i++)
{
// process_column is a function that prints the content of
my_xsqlda->sqlvar[i] to the console.
process_column(&(my_xsqlda->sqlvar[i]));
}
}
.
.

Anybody have a clue?