📄 oracle8connection.c
字号:
OCI_ATTR_PREFETCH_ROWS, (OCIError *)oracle8conn->err)!=OCI_SUCCESS) { return false; } // should be able to alloc these here, but it fails /*for (ub4 i=0; i<oracle8conn->maxselectlistsize; i++) { if (OCIHandleAlloc((dvoid *)stmt,(dvoid **)&def[i], OCI_HTYPE_DEFINE,0,NULL)!=OCI_SUCCESS) { return false; } }*/ return sqlrcursor_svr::openCursor(id);}bool oracle8cursor::closeCursor() { // should be able to free these here, but the alloc fails /*for (ub4 i=0; i<oracle8conn->maxselectlistsize; i++) { OCIHandleFree(def[i],OCI_HTYPE_DEFINE); }*/ return (OCIHandleFree(stmt,OCI_HTYPE_STMT)==OCI_SUCCESS);}bool oracle8cursor::prepareQuery(const char *query, uint32_t length) { // keep a pointer to the query and length in case it needs to be // reprepared later this->query=(char *)query; this->length=length; // reset the statement type stmttype=0; // prepare the query return (OCIStmtPrepare(stmt,oracle8conn->err, (text *)query,(ub4)length, (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT)==OCI_SUCCESS);}void oracle8cursor::checkRePrepare() { // Oracle8 appears to have a bug. // You can prepare, bind, execute, rebind, re-execute, etc. with // selects, but not with DML, it has to be re-prepared. // What a drag. if (!prepared && stmttype && stmttype!=OCI_STMT_SELECT) { cleanUpData(true,true); prepareQuery(query,length); prepared=true; }}bool oracle8cursor::inputBindString(const char *variable, uint16_t variablesize, const char *value, uint16_t valuesize, int16_t *isnull) { checkRePrepare(); // the size of the value must include the terminating NULL if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&inbindpp[inbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)value,(sb4)valuesize+1, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&inbindpp[inbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)value,(sb4)valuesize+1, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } inbindcount++; return true;}bool oracle8cursor::inputBindInteger(const char *variable, uint16_t variablesize, int64_t *value) { checkRePrepare(); inintbindstring[inbindcount]=charstring::parseNumber(*value); if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&inbindpp[inbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)inintbindstring[inbindcount], (sb4)charstring::length( inintbindstring[inbindcount])+1, SQLT_STR, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&inbindpp[inbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)inintbindstring[inbindcount], (sb4)charstring::length( inintbindstring[inbindcount])+1, SQLT_STR, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } inbindcount++; return true;}bool oracle8cursor::inputBindDouble(const char *variable, uint16_t variablesize, double *value, uint32_t precision, uint32_t scale) { checkRePrepare(); if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&inbindpp[inbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)value,(sb4)sizeof(double), SQLT_FLT, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&inbindpp[inbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)value,(sb4)sizeof(double), SQLT_FLT, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } inbindcount++; return true;}bool oracle8cursor::outputBindString(const char *variable, uint16_t variablesize, char *value, uint16_t valuesize, int16_t *isnull) { checkRePrepare(); outintbindstring[outbindcount]=NULL; if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&outbindpp[outbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)value, (sb4)valuesize, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&outbindpp[outbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)value, (sb4)valuesize, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } outbindcount++; return true;}bool oracle8cursor::outputBindInteger(const char *variable, uint16_t variablesize, int64_t *value, int16_t *isnull) { checkRePrepare(); outintbindstring[outbindcount]=new char[21]; rawbuffer::zero(outintbindstring[outbindcount],21); outintbind[outbindcount]=value; if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&outbindpp[outbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)outintbindstring[outbindcount], (sb4)21, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&outbindpp[outbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)outintbindstring[outbindcount], (sb4)21, SQLT_STR, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } outbindcount++; return true;}bool oracle8cursor::outputBindDouble(const char *variable, uint16_t variablesize, double *value, uint32_t *precision, uint32_t *scale, int16_t *isnull) { checkRePrepare(); outintbindstring[outbindcount]=NULL; if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&outbindpp[outbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)value,(sb4)sizeof(double), SQLT_FLT, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&outbindpp[outbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)value,(sb4)sizeof(double), SQLT_FLT, (dvoid *)isnull,(ub2 *)0, (ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } outbindcount++; return true;}#ifdef HAVE_ORACLE_8ibool oracle8cursor::inputBindBlob(const char *variable, uint16_t variablesize, const char *value, uint32_t valuesize, int16_t *isnull) { return inputBindGenericLob(variable,variablesize, value,valuesize,isnull, OCI_TEMP_BLOB,SQLT_BLOB);}bool oracle8cursor::inputBindClob(const char *variable, uint16_t variablesize, const char *value, uint32_t valuesize, int16_t *isnull) { return inputBindGenericLob(variable,variablesize, value,valuesize,isnull, OCI_TEMP_CLOB,SQLT_CLOB);}bool oracle8cursor::inputBindGenericLob(const char *variable, uint16_t variablesize, const char *value, uint32_t valuesize, int16_t *isnull, ub1 temptype, ub2 type) { checkRePrepare(); // create a temporary lob, write the value to it if (OCIDescriptorAlloc((dvoid *)oracle8conn->env, (dvoid **)&inbind_lob[inbindlobcount], (ub4)OCI_DTYPE_LOB, (size_t)0,(dvoid **)0)!=OCI_SUCCESS) { return false; } if (OCILobCreateTemporary(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount], //(ub2)0,SQLCS_IMPLICIT, (ub2)OCI_DEFAULT,OCI_DEFAULT, temptype,OCI_ATTR_NOCACHE, OCI_DURATION_SESSION)!=OCI_SUCCESS) { OCIDescriptorFree(inbind_lob[inbindlobcount],OCI_DTYPE_LOB); return false; } if (OCILobOpen(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount], OCI_LOB_READWRITE)!=OCI_SUCCESS) { OCILobFreeTemporary(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount]); OCIDescriptorFree(inbind_lob[inbindlobcount],OCI_DTYPE_LOB); return false; } ub4 size=valuesize; if (OCILobWrite(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount],&size,1, (void *)value,valuesize, OCI_ONE_PIECE,(dvoid *)0, (sb4 (*)(dvoid*,dvoid*,ub4*,ub1 *))0, 0,SQLCS_IMPLICIT)!=OCI_SUCCESS) { OCILobClose(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount]); OCILobFreeTemporary(oracle8conn->svc,oracle8conn->err, inbind_lob[inbindlobcount]); OCIDescriptorFree(inbind_lob[inbindlobcount],OCI_DTYPE_LOB); return false; } // bind the temporary lob if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&inbindpp[inbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)&inbind_lob[inbindlobcount],(sb4)0, type, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&inbindpp[inbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)&inbind_lob[inbindlobcount],(sb4)0, type, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } inbindlobcount++; inbindcount++; return true;}bool oracle8cursor::outputBindBlob(const char *variable, uint16_t variablesize, uint16_t index, int16_t *isnull) { return outputBindGenericLob(variable,variablesize,index, isnull,SQLT_BLOB);}bool oracle8cursor::outputBindClob(const char *variable, uint16_t variablesize, uint16_t index, int16_t *isnull) { return outputBindGenericLob(variable,variablesize,index, isnull,SQLT_CLOB);}bool oracle8cursor::outputBindGenericLob(const char *variable, uint16_t variablesize, uint16_t index, int16_t *isnull, ub2 type) { checkRePrepare(); // allocate a lob descriptor if (OCIDescriptorAlloc((dvoid *)oracle8conn->env, (dvoid **)&outbind_lob[index],(ub4)OCI_DTYPE_LOB, (size_t)0,(dvoid **)0)!=OCI_SUCCESS) { return false; } outbindlobcount=index+1; // bind the lob descriptor if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&outbindpp[outbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)&outbind_lob[index], (sb4)sizeof(OCILobLocator *), type, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&outbindpp[outbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)&outbind_lob[index], (sb4)sizeof(OCILobLocator *), type, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } outbindcount++; return true;}bool oracle8cursor::outputBindCursor(const char *variable, uint16_t variablesize, sqlrcursor_svr *cursor) { checkRePrepare(); if (charstring::isInteger(variable+1,variablesize-1)) { if (!charstring::toInteger(variable+1)) { return false; } if (OCIBindByPos(stmt,&curbindpp[curbindcount], oracle8conn->err, (ub4)charstring::toInteger(variable+1), (dvoid *)&(((oracle8cursor *)cursor)->stmt), (sb4)0, SQLT_RSET, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } else { if (OCIBindByName(stmt,&curbindpp[curbindcount], oracle8conn->err, (text *)variable,(sb4)variablesize, (dvoid *)&(((oracle8cursor *)cursor)->stmt), (sb4)0, SQLT_RSET, (dvoid *)0,(ub2 *)0,(ub2 *)0,0,(ub4 *)0, OCI_DEFAULT)!=OCI_SUCCESS) { return false; } } curbindcount++; return true;}void oracle8cursor::returnOutputBindBlob(uint16_t index) { // FIXME: call OCILobGetChunkSize to determine the size of this buffer // rather than maxitembuffersize, it will improve performance ub1 buf[oracle8conn->maxitembuffersize+1]; sendLob(outbind_lob[index],buf);}void oracle8cursor::returnOutputBindClob(uint16_t index) { // FIXME: call OCILobGetChunkSize to determine the size of this buffer // rather than maxitembuffersize, it will improve performance ub1 buf[oracle8conn->maxitembuffersize+1]; sendLob(outbind_lob[index],buf);}void oracle8cursor::checkForTempTable(const char *query, uint32_t length) { char *ptr=(char *)query; char *endptr=(char *)query+length; // skip any leading comments if (!skipWhitespace(&ptr,endptr) || !skipComment(&ptr,endptr) || !skipWhitespace(&ptr,endptr)) { return; } // look for "create global temporary table " if (createtemp.match(ptr)) { ptr=createtemp.getSubstringEnd(0); } else { return; } // get the table name stringbuffer tablename; while (ptr && *ptr && *ptr!=' ' && *ptr!='\n' && *ptr!=' ' && ptr<endptr) { tablename.append(*ptr); ptr++; } // append to list of temp tables // check for "on commit preserve rows" otherwise assume // "on commit delete rows" if (preserverows.match(ptr)) { conn->addSessionTempTableForTrunc(tablename.getString()); }}#endifvoid oracle8cursor::sendLob(OCILobLocator *lob, ub1 *buf) { // When reading from a clob, you have to tell it how // many characters to read, and the offset must be // specified in characters too. But the OCILobRead // returns the number of bytes read, not characters // and there's no good way to convert the number of // bytes read into the number of characters. So, we'll // have to try to read the same number of characters // each time and make sure that we don't try to read // more than will fit in our buffer. That way, we can // be sure that we were able to read them all and will // be able to reliably calculate the next offset. ub4 charstoread=oracle8conn->maxitembuffersize/MAX_BYTES_PER_CHAR; // handle lob datatypes // handle lob datatypes ub4 retlen=charstoread; ub4 offset=1; bool start=true; // Get the length of the lob. If we fail to read the // length, send a NULL field. Unfortunately OCILobGetLength // has no way to express that a LOB is NULL, the result is // "undefined" in that case. ub4 loblength=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -