Skip to Content.
Sympa Menu

freetds - Re: CTLib Question

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Michael Peppler <mpeppler AT peppler.org>
  • To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
  • Subject: Re: CTLib Question
  • Date: Fri, 10 Aug 2001 09:31:31 -0700


Patrick Muldoon writes:
> I am reading the sybase docs, and trying to figure out how to figure out
> how
> many rows are returned in a query (so I can allocate memory to hold them)
>
> Here is what I am using which is bombing. Any ideas on what I should do, or
> where else I can look for information ..
>
> ret = ct_command(sqlcmd, CS_LANG_CMD, cmd->argv[1], CS_NULLTERM,
> CS_UNUSED);
> /* send the damn thing */
> ret = ct_send(sqlcmd);
> if(ret == CS_SUCCEED){
> /* First we need to determine the number of rows & cols in the
> resultset
> */
> ret = ct_res_info(sqlcmd, CS_NUMDATA, &fcount, CS_UNUSED,NULL);
> ret = ct_res_info(sqlcmd, CS_ROW_COUNT, &rcount, CS_UNUSED,NULL);
>

Read the docs again - you can't get the number of rows for a SELECT
query until all the rows have been processed. This is not a limitation
of the API, but rather an issue with the server that doesn't "know"
how many rows are in a result set without actually going and fetching
each of the rows - which would make it painfully slow.

You need to use another scheme to allocate memory for your rows. You
can use a linked list, or malloc() to pre-allocate a certain amount of
space, and then realloc() to extend (or shrink) as necessary.

Michael
--
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler AT peppler.org - mpeppler AT mbay.net
International Sybase User Group - http://www.isug.com



  • CTLib Question, Patrick Muldoon, 08/10/2001
    • <Possible follow-up(s)>
    • Re: CTLib Question, Michael Peppler, 08/10/2001

Archive powered by MHonArc 2.6.24.

Top of Page