I am using FreeTDS to process simple SELECT statements.
My problem is that I cannot get more than the first 4096 bytes of a large column value.
Let's say we have a table like this:
CREATE TABLE tab (
largecol varbinary(max),
othercol int PRIMARY KEY
);
My code looks like this (simplified and omitting error checks):
#include <sybfront.h>
#include <sybdb.h>
int main ()
{
DBPROCESS *dbproc;
LOGINREC *login;
char *data;
DBINT len;
/* setup */
dbinit();
login = dblogin();
DBSETLUSER(login, "username");
DBSETLPWD(login, "password");
DBSETLAPP(login, "my_program");
DBSETLPACKET(login, 10000);
DBSETLNATLANG(login, "us_english");
DBSETLCHARSET(login, "UTF-8");
/* connect */
dbproc = dbopen(login, "hostname");
dbuse(dbproc, "dbname");
/* execute query */
dbcmd(dbproc, "SELECT largecol, othercol FROM tab");
dbsqlexec(dbproc);
dbresults(dbproc);
/* retrieve result */
dbnextrow(dbproc);
data = (char *)dbdata(dbproc, 1);
len = dbdatlen(dbproc, 1);
/* more processing */
}
Now no matter how large the data in largecol are, I never get more than 4096 bytes in data and len.
The only lead I have to make this work is the dbreadtext function, but I don't understand how to use it. The only bit of information I get is:
Use
dbreadtextinstead ofdbnextrowto readSQLTEXTandSQLIMAGEvalues.
That function does not take a column number as argument, so I have no idea how to use it. Can it only be used with queries that retrieve only a single column?
How can I retrieve large column data?