Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: OCIStmtExecute iters question

Re: OCIStmtExecute iters question

From: Markus M. Mueller <markus-m.mueller_at_ubs.com>
Date: Fri, 10 Sep 1999 13:45:46 +0200
Message-ID: <37D8EF6A.81818AD4@ubs.com>

  1. try with nRowCount=0 in the OCIStmtExecute for select stmt's. This will fetch only one row for each call to OCIStmtFetch.
  2. make sure you check the return value from OCIStmtFetch and stop looping if there are no more data ( and therefore stop calling OCIStmtFetch as well ).

If I got it right, when calling execute with a select stmt and having set
(1) nRowCount to a non zero value, you also need to allocate that many data
items in the define call, which I don't see in your code.

(1) nRowCount as used in your code sample to OCIStmtExecute

regards
Markus

schrodinger_cat_2_at_yahoo.com wrote:
>
> I'm trying to read a string entry from several (nRowCount) rows in a
> table and I'm getting only the first entry in OCIStmtExecute. If I use
> OCIStmtFetch I get a system exception. I should not need it since I'm
> using the iters param in OCIStmtExecute... The calls that I'm using are
> below, this is prototype code so pardon the hardcoded constants. In
> cdemo82.c they use OCIStmtFetch but with objects, this should be simple
> no? I come from ODBC land so I may have some misguided notions here.
>
> Thanks,
> Tomas
>
> pszSQLCountCmd="select count(*) from table";
> pszSQLCmd="select * from table";
>
> // Prepare the count statement
> checkerr(errhp, OCIStmtPrepare(stmthp1, errhp, (unsigned char *)
> pszSQLCountCmd, (ub4) strlen((char *) pszSQLCountCmd),(ub4)
> OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
>
> // bind the input variable
> checkerr(errhp, OCIDefineByPos(stmthp1, &defnp, errhp, 1, (dvoid *)
> &nRowCount, (sword) sizeof(sword), SQLT_INT, (dvoid *) 0, (ub2 *)0,
> (ub2 *)0, OCI_DEFAULT));
>
> // execute and fetch
> status = OCIStmtExecute(svchp, stmthp1, errhp, (ub4) 1, (ub4) 0,
> (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL,
> OCI_DEFAULT);
>
> // Prepare the statement
> checkerr(errhp, OCIStmtPrepare(stmthp, errhp, (unsigned char *)
> pszSQLCmd, (ub4) strlen((char *) pszSQLCmd), (ub4) OCI_NTV_SYNTAX,
> (ub4) OCI_DEFAULT));
>
> // bind the input variable
> checkerr(errhp, OCIDefineByPos(stmthp, &defnp, errhp, nColumn, (dvoid
> *) pszFetchData,(sword) 255, SQLT_STR, (dvoid *) 0, (ub2 *)0, (ub2 *)0,
> OCI_DEFAULT));
>
> // execute and fetch
> status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) nRowCount, (ub4) 0,
> (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
>
> for (int i=0; i<nRowCount; i++)
> {
> status = OCIStmtFetch(stmthp, errhp, (ub4) 1, (ub4)OCI_FETCH_NEXT,
> (ub4) OCI_DEFAULT);
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Received on Fri Sep 10 1999 - 06:45:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US