Skip to Content.
Sympa Menu

freetds - Re: [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: Re: [freetds] Rows truncated at 176 chars when using CT-Lib interface
  • Date: Wed, 29 Apr 2009 11:04:58 +0200

Frediano,
Thanks for replying.

I've just solved the issue. The problem was with the CS_DATAFMT structure
member not being a pointer. I've replaced by:

struct data_s {

CS_CHAR *data;

CS_DATAFMT *format;

CS_INT size;

CS_SMALLINT ind;

};

struct data_s *data;

And fixed the references on the code:

data[i].format = malloc(sizeof(CS_DATAFMT));

memset(data[i].format, 0, sizeof(CS_DATAFMT));

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].format->datatype = CS_CHAR_TYPE;

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);

And that was it :)

Regarding the select, it's a simple command:

ct_command(conn->command, CS_LANG_CMD,

"SELECT col1, col2, col3 FROM table",

CS_NULLTERM, CS_UNUSED);


Regards,

Alejandro

On Wed, Apr 29, 2009 at 9:21 AM, Frediano Ziglio <freddy77 AT gmail.com> wrote:

> 2009/4/27 Alejandro Guerrieri <alejandro.guerrieri AT gmail.com>:
> > 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;
> >
> > .....
> >
>
> I'm interested on how you send the query. Did you issue a prepared
> query? Please post missing code
>
> > 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 ...
> > }
> > ....
>
> freddy77
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>




Archive powered by MHonArc 2.6.24.

Top of Page