Skip to Content.
Sympa Menu

freetds - Re: [freetds] how to CALL Sql stored procedure with C?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT schemamania.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] how to CALL Sql stored procedure with C?
  • Date: Fri, 3 Oct 2003 23:55:38 -0400

On Fri, 3 Oct 2003, "Knygh, Øyvind" <oyvind.knygh AT brreg.no> wrote:
> I have problems using function dbhasretstat() and dbretstatus().
> Here is the db-lib code in C using FreeTDS. What's wrong with
> this?? I get
> no info from dbretstatus(). I call this stored procedure
> several times. The
> first time it looks like dbhasretstat(dbproc) = FALSE why?

Bill's advice is good. I think Microsoft's documentation is clear,
though:

"call dbhasretstat after dbresults returns NO_MORE_RPC_RESULTS ... or
NO_MORE_RESULTS...."

>From what I've seen, the server always returns data in following order:

1. Regular rows.
2. Compute rows.
3. Output parameters, in order.
4. Return status.

Obviously, 1 & 2 may be repeated.

Although it's possible for db-lib to "peek ahead" a little bit, FreeTDS
doesn't. The return status isn't fetched from the wire until the
application attempts to read the past the end of the returned data (parts
1-3).

HTH.

--jkl

> dbfcmd (dbproc, " exec oko_chk_apar_id @apar_id=%ld,",apar_id); /*
> Kundenr */
> dbcmd (dbproc, " @apar_type='R',"); /*
> Reskontrotype */
> dbfcmd (dbproc, "
> @client='%s'",client); /* Firma
> */
> if (dbsqlexec (dbproc) == FAIL)
> {
> printf ("Feil i SQL-query. - exec oko_chk_apar_id
> @apar_id=%ld,\n",apar_id);
> printf ("
> @apar_type='R',\n");
> printf ("
> @client='%s'\n",client);
> return(-1);
> }
> while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS)
> {
> if (result_code == SUCCEED)
> {
> dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &status2);
> while (dbnextrow(dbproc) != NO_MORE_ROWS)
> {
>
> printf("\nStep 2 Sjekk_Acuheader Inne i dbresults
> status2=%ld\n",status2);
> }
>
> if ( dbhasretstat(dbproc) )
> {
> status=dbretstatus(dbproc);
> if (status==1)
> {
> return 1; /* Kunde finnes ikke i AGRESSO */
> }
> else if (status == 0 )
> {
> return 0; /* Kunde finnes i AGRESSO */
> }
> else if (status < 0) /* Noe feilet */
> {
> printf ("Feil, dbhasretstat: status=%ld\n",status);
> return (-1);
> }
> }
> if (status2==1)
> {
> return 1; /* Kunde finnes ikke i AGRESSO */
> }
> else if (status2 == 0 )
> {
> return 0; /* Kunde finnes i AGRESSO */
> }
> }
> else
> {
> printf ("Results Failed\n");
> break;
> }
> }
>
>
> Øyvind




Archive powered by MHonArc 2.6.24.

Top of Page