Skip to Content.
Sympa Menu

freetds - [freetds] Rows truncated at 176 chars when using CT-Lib interface

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Alejandro Guerrieri <alejandro.guerrieri AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Rows truncated at 176 chars when using CT-Lib interface
  • Date: Mon, 27 Apr 2009 16:49:28 +0200

Hi,
This is my first post to the list. I've started playing with FreeTDS a few
days ago, and I'm having some issues getting more than 176 characters back
using the ct-lib interface.

The code fragment I'm pasting below works fine when the data does not exceed
176 bytes, but anything over that value gets truncated. The fields I'm
retrieving are VARCHAR(255) and VARCHAR(4000) (it doesn't matter the size,
the problem occurs anyways).

Maybe I'm doing something really stupid (these are my first attempts at
coding with FreeTDS and ct-lib, and I found Sybase docs a little cryptic on
the "examples" side).

I'm using Mac OSX Leopard with gcc 4.0.1. and FreeTDS 0.82 (tried with the
MacPorts version and also compiling it myself from code downloaded from the
FreeTDS site. Same results).

Does anybody knows what I'm doing wrong? I don't believe this is a bug, I
guess somebody would have noticed before me (I did my homework and googled
around for similar problems, to no avail).

Thank you in advance,

Alex

....

struct data_s {

CS_CHAR *data;

CS_DATAFMT format;

CS_INT size;

CS_SMALLINT ind;

};

struct data_s *data;

.....

while((ret = ct_results(conn->command, &res_type)) == CS_SUCCEED)

{

switch (res_type)

{

case CS_ROW_RESULT:

if (ct_res_info(conn->command, CS_NUMDATA, (CS_INT *)&columns,

CS_UNUSED, NULL) != CS_SUCCEED) {

error(0, "Error fetching attributes");

return -1;

}

data = malloc(sizeof(struct data_s)*columns);

for (i = 0; i < columns; i++) {

if (ct_describe(conn->command, i+1, &data[i].format) != CS_SUCCEED) {

error(0, "Error fetching column description");

free(data);

return -1;

}

data[i].format.maxlength++;

data[i].data = malloc(data[i].format.maxlength);

data[i].size = data[i].format.maxlength;

data[i].format.format = CS_FMT_NULLTERM;

ct_bind(conn->command, i+1, &data[i].format, &data[i].data,

&data[i].size, &data[i].ind);

fprintf(stderr, "Col %d\tSize: %d\tMaxlen %d\n", i,

data[i].size, data[i].format.maxlength);

}

while(((ret = ct_fetch(conn->command, CS_UNUSED, CS_UNUSED,

CS_UNUSED, &count)) == CS_SUCCEED) || (ret == CS_ROW_FAIL)) {

if( ret == CS_ROW_FAIL ) {

fprintf(stderr, "** Error on row %d in this fetch batch.\n",
count+1);

} else {

for (i=0;i<columns;i++) {

fprintf(stdout, "[%d:%d:%s]\n", i,

strlen((char *)&data[i].data), &data[i].data);

}

}

}

case ...
}
....




Archive powered by MHonArc 2.6.24.

Top of Page