SqlOpenLob::~SqlOpenLob() { bool done = false; while(!done) { sword res = OCICALL(OCILobClose( _lob._conn._svc_ctx, _lob._conn._env._errh, _lob._loc )); if( res != OCI_SUCCESS ) { sb4 errorcode; sword res2 = OCICALL(OCIErrorGet(_lob._conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR)); assert(res2 == OCI_SUCCESS); if(errorcode == 3127) // ORA-03127: no new operations allowed until the active operation ends { std::cerr << "ORA-03127: no new operations allowed until the active operation ends" << std::endl; MSLEEP(100); } else { oci_check_error(__TROTL_HERE__, _lob._conn._env._errh, res); } } else { done = true; } } };
void Blob::getData(tntdb::Blob& blob) const { log_debug("OCILobGetLength"); ub4 len; sword ret = OCILobGetLength(conn->getSvcCtxHandle(), conn->getErrorHandle(), lob, &len); conn->checkError(ret, "OCILobGetLength"); log_debug("len=" << len); log_debug("OCILobOpen"); ret = OCILobOpen(conn->getSvcCtxHandle(), conn->getErrorHandle(), lob, OCI_LOB_READONLY); conn->checkError(ret, "OCILobOpen"); char* buffer = blob.reserve(len, true); memset(buffer, '\0', len); ub4 amt = len; log_debug("OCILobRead"); ret = OCILobRead(conn->getSvcCtxHandle(), conn->getErrorHandle(), lob, &amt, 1, buffer, len, 0, 0, 0, SQLCS_IMPLICIT); conn->checkError(ret, "OCILobRead"); log_debug("OCILobClose"); ret = OCILobClose(conn->getSvcCtxHandle(), conn->getErrorHandle(), lob); conn->checkError(ret, "OCILobClose"); }
void BfileLobClose_proc(OCILobLocator *Bfile_loc, OCIEnv *envhp, OCIError *errhp, OCISvcCtx *svchp, OCIStmt *stmthp) { printf ("----------- OCILobOpen Demo --------------\n"); checkerr(errhp, OCILobOpen(svchp, errhp, Bfile_loc, (ub1) OCI_LOB_READONLY)); checkerr(errhp, OCILobClose(svchp, errhp, Bfile_loc)); }
static int oci_blob_close(php_stream *stream, int close_handle) { struct oci_lob_self *self = (struct oci_lob_self*)stream->abstract; pdo_stmt_t *stmt = self->stmt; if (close_handle) { OCILobClose(self->S->H->svc, self->S->err, self->lob); efree(self); } php_pdo_stmt_delref(stmt); return 0; }
void LOBBuffering_proc(OCILobLocator *Lob_loc, OCIEnv *envhp, OCIError *errhp, OCISvcCtx *svchp, OCIStmt *stmthp) { ub4 amt; ub4 offset; sword retval; ub1 bufp[MAXBUFLEN]; ub4 buflen; printf ("----------- OCI LOB Buffering Demo --------------\n"); /* Open the CLOB: */ checkerr (errhp, (OCILobOpen(svchp, errhp, Lob_loc, OCI_LOB_READWRITE))); /* Enable LOB Buffering: */ printf (" enable LOB buffering\n"); checkerr (errhp, OCILobEnableBuffering(svchp, errhp, Lob_loc)); printf (" write data to LOB\n"); /* Write data into the LOB: */ amt = sizeof(bufp); buflen = sizeof(bufp); offset = 1; checkerr (errhp, OCILobWrite (svchp, errhp, Lob_loc, &amt, offset, (void *)bufp, buflen, OCI_ONE_PIECE, (void *)0, (sb4 (*)(void*,void*,ub4*,ub1 *))0, 0, SQLCS_IMPLICIT)); /* Flush the buffer: */ printf(" flush the LOB buffers\n"); checkerr (errhp, OCILobFlushBuffer(svchp, errhp, Lob_loc, (ub4)OCI_LOB_BUFFER_FREE)); /* Disable Buffering: */ printf (" disable LOB buffering\n"); checkerr (errhp, OCILobDisableBuffering(svchp, errhp, Lob_loc)); /* Subsequent LOB WRITEs will not use the LOB Buffering Subsystem: */ /* Closing the CLOB is mandatory if you have opened it: */ checkerr (errhp, OCILobClose(svchp, errhp, Lob_loc)); return; }
static int oci_blob_close(php_stream *stream, int close_handle) { struct oci_lob_self *self = (struct oci_lob_self *)stream->abstract; pdo_stmt_t *stmt = self->stmt; if (close_handle) { zend_object *obj = &stmt->std; OCILobClose(self->E->svc, self->E->err, self->lob); zval_ptr_dtor(&self->dbh); GC_DELREF(obj); efree(self->E); efree(self); } /* php_pdo_free_statement(stmt); */ return 0; }
void trimLOB_proc(OCILobLocator *Lob_loc, OCIEnv *envhp, OCIError *errhp, OCISvcCtx *svchp, OCIStmt *stmthp) { oraub8 trimLength; printf ("----------- OCILobTrim Demo --------------\n"); /* Open the CLOB */ checkerr (errhp, (OCILobOpen(svchp, errhp, Lob_loc, OCI_LOB_READWRITE))); /* Trim the LOB to its new length */ trimLength = 200; /* <New truncated length of the LOB>*/ printf (" trim the lob to %d bytes\n", (ub4)trimLength); checkerr (errhp, OCILobTrim2(svchp, errhp, Lob_loc, trimLength )); /* Closing the CLOB is mandatory if you have opened it */ checkerr (errhp, OCILobClose(svchp, errhp, Lob_loc)); }
static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type) /* {{{ */ { pdo_oci_stmt *S = (pdo_oci_stmt*)stmt->driver_data; /* we're only interested in parameters for prepared SQL right now */ if (param->is_param) { pdo_oci_bound_param *P; sb4 value_sz = -1; P = (pdo_oci_bound_param*)param->driver_data; switch (event_type) { case PDO_PARAM_EVT_FETCH_PRE: case PDO_PARAM_EVT_FETCH_POST: case PDO_PARAM_EVT_NORMALIZE: /* Do nothing */ break; case PDO_PARAM_EVT_FREE: P = param->driver_data; if (P) { efree(P); } break; case PDO_PARAM_EVT_ALLOC: P = (pdo_oci_bound_param*)ecalloc(1, sizeof(pdo_oci_bound_param)); param->driver_data = P; /* figure out what we're doing */ switch (PDO_PARAM_TYPE(param->param_type)) { case PDO_PARAM_STMT: return 0; case PDO_PARAM_LOB: /* P->thing is now an OCILobLocator * */ P->oci_type = SQLT_BLOB; value_sz = sizeof(OCILobLocator*); break; case PDO_PARAM_STR: default: P->oci_type = SQLT_CHR; value_sz = param->max_value_len; if (param->max_value_len == 0) { value_sz = 1332; /* maximum size before value is interpreted as a LONG value */ } } if (param->name) { STMT_CALL(OCIBindByName, (S->stmt, &P->bind, S->err, (text*)param->name, param->namelen, 0, value_sz, P->oci_type, &P->indicator, 0, &P->retcode, 0, 0, OCI_DATA_AT_EXEC)); } else { STMT_CALL(OCIBindByPos, (S->stmt, &P->bind, S->err, param->paramno+1, 0, value_sz, P->oci_type, &P->indicator, 0, &P->retcode, 0, 0, OCI_DATA_AT_EXEC)); } STMT_CALL(OCIBindDynamic, (P->bind, S->err, param, oci_bind_input_cb, param, oci_bind_output_cb)); return 1; case PDO_PARAM_EVT_EXEC_PRE: P->indicator = 0; P->used_for_output = 0; if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) { ub4 empty = 0; STMT_CALL(OCIDescriptorAlloc, (S->H->env, &P->thing, OCI_DTYPE_LOB, 0, NULL)); STMT_CALL(OCIAttrSet, (P->thing, OCI_DTYPE_LOB, &empty, 0, OCI_ATTR_LOBEMPTY, S->err)); S->have_blobs = 1; } return 1; case PDO_PARAM_EVT_EXEC_POST: /* fixup stuff set in motion in oci_bind_output_cb */ if (P->used_for_output) { if (P->indicator == -1) { /* set up a NULL value */ if (Z_TYPE_P(param->parameter) == IS_STRING #if ZEND_EXTENSION_API_NO < 220040718 && Z_STRVAL_P(param->parameter) != empty_string #endif ) { /* OCI likes to stick non-terminated strings in things */ *Z_STRVAL_P(param->parameter) = '\0'; } zval_dtor(param->parameter); ZVAL_NULL(param->parameter); } else if (Z_TYPE_P(param->parameter) == IS_STRING #if ZEND_EXTENSION_API_NO < 220040718 && Z_STRVAL_P(param->parameter) != empty_string #endif ) { Z_STRLEN_P(param->parameter) = P->actual_len; Z_STRVAL_P(param->parameter) = erealloc(Z_STRVAL_P(param->parameter), P->actual_len+1); Z_STRVAL_P(param->parameter)[P->actual_len] = '\0'; } } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->thing) { php_stream *stm; if (Z_TYPE_P(param->parameter) == IS_NULL) { /* if the param is NULL, then we assume that they * wanted to bind a lob locator into it from the query * */ stm = oci_create_lob_stream(stmt, (OCILobLocator*)P->thing); if (stm) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); php_stream_to_zval(stm, param->parameter); P->thing = NULL; } } else { /* we're a LOB being used for insert; transfer the data now */ size_t n; ub4 amt, offset = 1; char *consume; php_stream_from_zval_no_verify(stm, ¶m->parameter); if (stm) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); do { char buf[8192]; n = php_stream_read(stm, buf, sizeof(buf)); if ((int)n <= 0) { break; } consume = buf; do { amt = n; OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing, &amt, offset, consume, n, OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT); offset += amt; n -= amt; consume += amt; } while (n); } while (1); OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing); OCILobFlushBuffer(S->H->svc, S->err, (OCILobLocator*)P->thing, 0); } else if (Z_TYPE_P(param->parameter) == IS_STRING) { /* stick the string into the LOB */ consume = Z_STRVAL_P(param->parameter); n = Z_STRLEN_P(param->parameter); if (n) { OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE); while (n) { amt = n; OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing, &amt, offset, consume, n, OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT); consume += amt; n -= amt; } OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing); } } OCIDescriptorFree(P->thing, OCI_DTYPE_LOB); P->thing = NULL; } } return 1; } } return 1; } /* }}} */