Skip to Content.
Sympa Menu

freetds - RE: [freetds] Accessing Ms SQL Server queries through FREETDS C Apis

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Accessing Ms SQL Server queries through FREETDS C Apis
  • Date: Mon, 19 Apr 2004 13:21:46 +0200

>
> Hi,
>
> I have written a C program using FreeTDS apis to access MS
> SQL Server. I am able
> to connect to SQL Server using C apis. But my problem is that
> I am not able to
> fetch the proper results for the queries I had sent through C
> program. I will
> give my sample code which can be great help. Pls help me.
>
> I am sending my sample code as attachment in this mail.
>
> One Note : I am not using any ODBC apis in this program. I am
> using only freetds
> apis only
>
> Thanks and regards
> Sajeesh Kumar
>

We never recommend the use of libTDS API (we always suggest one library
between dblib/ctlib/obdc). libTDS is subject to change without any
notice.

printf("Its Regular Row\n");
result = tds->curr_resinfo;
if(result == NULL)
printf("No Results\n");
buff = tds_alloc_row(result);

libTDS allocate buffer for you :)

printf ("No of coloumns = %d\n", result->num_cols);
rowcol = *(result->columns);
printf("Column Size = %d\n", rowcol->column_size);
if(result->current_row == NULL)
printf("No contents in the row\n");
printf("Size of the row = %d\n", result->row_size);
tds_clr_null(result->current_row, 1);
buff = (char *) calloc(rowcol->column_cur_size + 1,
sizeof(char));
column_data = tds_get_char_data(tds, buff,
rowcol->column_cur_size + 1, *(result->columns));
tds_clr_null(buff, 1);

no, you should just read data from buffer.

if(column_data == 0)
{
printf("No Data available\n");
break;
}
printf("The buffer = %s\n",buff);

see src/tds/unittests/t0002.c for an example on how to read data.

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page