[freetds] Accessing Ms SQL Server queries through FREETDS C Apis
ZIGLIO, Frediano, VF-IT
Frediano.Ziglio at vodafone.com
Mon Apr 19 07:21:46 EDT 2004
>
> 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
More information about the FreeTDS
mailing list