[freetds] how to CALL Sql stored procedure with C?
Thompson, Bill D (London)
bill_d_thompson at ml.com
Fri Oct 3 14:05:52 EDT 2003
Hi,
the db-library manual page is slightly ambiguous and confusing on this
point,
and I'm not sure that freeTDS behaves exactly like Sybase or SQl server
db-lib in this respec.t
Using Freetds though, it is not valid to call dbhasretstat until you have
processed all the results using dbresults()
In other words, you should move those calls after the "while...dbresults"
loop
BIll
> -----Original Message-----
> From: "Knygh, Øyvind" [SMTP:oyvind.knygh at brreg.no]
> Sent: 03 October 2003 12:21
> To: 'freetds at lists.ibiblio.org'
> Subject: [freetds] how to CALL Sql stored procedure with C?
>
> 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?
> When I'm using result set from the stored procedure all is ok.
>
> 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
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
More information about the FreeTDS
mailing list