When using OCIStmtPrepare() and OCIBindByName(), is there a way to do the bind by name, then get the position of that bind as an int? OCIStmtGetBindInfo() doesn’t seem to do it. Thanks!
When using OCIStmtPrepare() and OCIBindByName() , is there a way to do the bind
Share
There doesn’t appear to be an easy way to do it. I tried using the undocumented (as in I couldn’t find it in the help docs but it is in the oci.h header)
OCI_ATTR_HANDLE_POSITIONusingOCIAttrGet()on the bind handle:Unfortunately, that seems to work for bind handles that you bound positionally, but return 0 for any you bound by name.
So it seems like you would have to use the
OCIStmtGetBindInfo()call to have it fill an array of bind variable names then iterate through it to find the position(s) for each named bind, either by comparing the bind name to the values in the bind variable names array (the values of which will be uppercased):One interesting thing to note about multiple placeholders in a statement is that it behaves differently if your statement is an anonymous block or not. That is:
Will fill your
foundoutput variable with 2 (and the arrays with info for 2 binds), whereas:Will fill your
foundoutput variable with 1 (and the arrays with info for 1 bind).Nonetheless, a single call to
OCIBindByName()will bind both in either case.