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

"Knygh, Øyvind" oyvind.knygh at brreg.no
Fri Oct 3 14:21:29 EDT 2003


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


More information about the FreeTDS mailing list