I am using OCIAttrGet() to obtain the type of query in my prepared statement/query handle, but it always seems to return 0 (I am doing this so I can modify how I call OCIStmtExecute(), in particular how I use the iters argument).
So, I am executing the code below (Note: the Q_ and E_ is just #define shorthand to handles/properties buried deep in memory structures). I am also doing full error checking in the real code and the statement prepare is successful.
OCIHandleAlloc(E_HENV, (dvoid **) &Q_HQRY, OCI_HTYPE_STMT, 0, 0);
OCIStmtPrepare(Q_HQRY, E_HERR, Q_SQL, strlen(Q_SQL), OCI_NTV_SYNTAX, OCI_DEFAULT);
I now call OCIAttrGet() on the query handle to obtain the SQL Function Code
OCIAttrGet(Q_HQRY, OCI_HTYPE_STMT, &pThisQuery->m_nFnCode, NULL, OCI_ATTR_SQLFNCODE, E_HERR);
However, this is always returning 0 regardless of the statement.
It occured to me that this may be because the statement has not actually been parsed yet, as this happens during the OCIStmtExecute(), however if this is the case, as I need to know the type of statement to work out how to call OCIStmtExecute() I am in a bit of a catch 22 situation.
Any ideas/suggestions welcome, and if Im doing something wrong, please tell me.
Well, it seems that until the statement is actually parsed by oracle this information is not available. I.e. until OCIStmtExecute() is called.
As I wanted the info to help decide how to call OCIStmtExecute() I am in a bit of a catch 22 situation.
I have resorted to parsing the statement myself (well, checking the first word) to determine the type of statement.
I just had the same issue. However the attribute OCI_ATTR_STMT_TYPE is available right after OCIStmtPrepare and can be used to crudely determine the type of statement. Typical problem is to figure out how many iterations to set up for the OCIStmtExecute call; it can be determined from the OCI_ATTR_STMT_TYPE attribute.