简体   繁体   中英

How to retrieve large values from SQL Server columns using DB Library for C?

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 dbreadtext instead of dbnextrow to read SQLTEXT and SQLIMAGE values.

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?

FreeTDS has an option, text size , which can be set in freetds.conf :

See table 3.3, text size : https://www.freetds.org/userguide/freetdsconf.html

Give that a try?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM