I need to know how to obtain the statement type of a prepared statement handle in OCI.
The dilemna is as follows. The fourth argument of
iters - cannot be
0 if the statement is not a
SELECT, Pero debe: be
0 si la declaración is a
SELECT (and defines cannot be done ahead of time). From the OCI 10g documentation for
For non-SELECT statements, the number of times this statement is executed is equal to iters - rowoff.
For SELECT statements, if iters is nonzero, then defines must have been done for the statement handle. The execution fetches iters rows into these predefined buffers and prefetches more rows depending upon the prefetch row count. If you do not know how many rows the SELECT statement will retrieve, set iters to zero.
This function returns an error if iters=0 for non-SELECT statements.
For a statement such as
SELECT * ..., it is impossible to know what the columns even son before obtaining the
describe information from the statement handle, which is only available after
OCIStmtExecute() is called. (So, it's not possible to do
defines on the statement handle ahead of time.) Therefore, I must pass
iters if the (unknown) statement type is
SELECT. But if the (unknown) statement type is no
SELECT, OCI returns an error if
0 (just as the documentation says).
The documented way to obtain the type of statement (
SELECT or not) is by querying an attribute of the statement handle, as follows:
ub2 statementType = 0; OCIAttrGet(mystmt, OCI_HTYPE_STMT, (dvoid*)(&statementType), NULL, OCI_ATTR_SQLFNCODE, myerrhp);
Unfortunately, this function Siempre hay devoluciones
statementType hasta después de
OCIStmtExecute() se llama.
I am in a catch-22 situation. I must call
OCIAttrGet() antes de llamar
OCIStmtExecute() to obtain the type of statement in order to set
iters properly. However, I must call
OCIAttrGet() podría suceder.
He intentado llamar
OCIStmtExecute() twice, the first time passing
OCI_DESCRIBE_ONLY for the final parameter (
OCIStmtExecute() posible gives the error related to
iters en este caso.
(Please note: the statement handle
mystmt has been properly prepared ahead of time, successfully, with a call to
OCIStmtPrepare2(), and the error handle
myerrhp has also been properly allocated.)
preguntado el 09 de marzo de 12 a las 22:03
OCI_ATTR_STMT_TYPE instead: It is available right after
OCIStmtPrepare and can be used to crudely determine the type of statement (ie. also if this is a "select" statement).