📄 oci8.c
字号:
php_oci_init_globals(&oci_globals TSRMLS_CC);#endif le_stmt = zend_register_list_destructors_ex(_oci_stmt_list_dtor, NULL, "oci8 statement", module_number); le_conn = zend_register_list_destructors_ex(php_oci_free_conn_list, NULL, "oci8 connection", module_number); le_desc = zend_register_list_destructors_ex(_oci_descriptor_list_dtor, NULL, "oci8 descriptor", module_number);#ifdef WITH_COLLECTIONS le_coll = zend_register_list_destructors_ex(_oci_coll_list_dtor, NULL, "oci8 collection", module_number);#endif le_server = zend_register_list_destructors_ex(_oci_server_list_dtor, NULL, "oci8 server", module_number); le_session = zend_register_list_destructors_ex(_oci_session_list_dtor, NULL, "oci8 session", module_number); INIT_CLASS_ENTRY(oci_lob_class_entry, "OCI-Lob", php_oci_lob_class_functions);#ifdef WITH_COLLECTIONS INIT_CLASS_ENTRY(oci_coll_class_entry, "OCI-Collection", php_oci_coll_class_functions);#endif oci_lob_class_entry_ptr = zend_register_internal_class(&oci_lob_class_entry TSRMLS_CC);#ifdef WITH_COLLECTIONS oci_coll_class_entry_ptr = zend_register_internal_class(&oci_coll_class_entry TSRMLS_CC);#endif/* thies@thieso.net 990203 i do not think that we will need all of them - just in here for completeness for now! */ REGISTER_LONG_CONSTANT("OCI_DEFAULT",OCI_DEFAULT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_DESCRIBE_ONLY",OCI_DESCRIBE_ONLY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_COMMIT_ON_SUCCESS",OCI_COMMIT_ON_SUCCESS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_EXACT_FETCH",OCI_EXACT_FETCH, CONST_CS | CONST_PERSISTENT);/* for OCIBindByName (real "oci" names + short "php" names*/ REGISTER_LONG_CONSTANT("SQLT_BFILEE",SQLT_BFILEE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_CFILEE",SQLT_CFILEE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SQLT_RDD",SQLT_RDD, CONST_CS | CONST_PERSISTENT);#ifdef WITH_COLLECTIONS REGISTER_LONG_CONSTANT("OCI_B_SQLT_NTY",SQLT_NTY, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("OCI_SYSDATE","SYSDATE",CONST_PERSISTENT);#endif REGISTER_LONG_CONSTANT("OCI_B_BFILE",SQLT_BFILEE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_CFILEE",SQLT_CFILEE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_ROWID",SQLT_RDD, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_CURSOR",SQLT_RSET, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_B_BIN",SQLT_BIN, CONST_CS | CONST_PERSISTENT);/* for OCIFetchStatement */ REGISTER_LONG_CONSTANT("OCI_FETCHSTATEMENT_BY_COLUMN", OCI_FETCHSTATEMENT_BY_COLUMN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_FETCHSTATEMENT_BY_ROW", OCI_FETCHSTATEMENT_BY_ROW, CONST_CS | CONST_PERSISTENT);/* for OCIFetchInto & OCIResult */ REGISTER_LONG_CONSTANT("OCI_ASSOC",OCI_ASSOC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_NUM",OCI_NUM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_BOTH",OCI_BOTH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_RETURN_NULLS",OCI_RETURN_NULLS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_RETURN_LOBS",OCI_RETURN_LOBS, CONST_CS | CONST_PERSISTENT);/* for OCINewDescriptor (real "oci" names + short "php" names*/ REGISTER_LONG_CONSTANT("OCI_DTYPE_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_DTYPE_LOB",OCI_DTYPE_LOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_DTYPE_ROWID",OCI_DTYPE_ROWID, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_D_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_D_LOB",OCI_DTYPE_LOB, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("OCI_D_ROWID",OCI_DTYPE_ROWID, CONST_CS | CONST_PERSISTENT); return SUCCESS;}/* ----------------------------------------------------------------- */PHP_RINIT_FUNCTION(oci){ /* XXX NYI OCI(num_links) = OCI(num_persistent); */ OCI(debug_mode) = 0; /* start "fresh" *//* OCI(in_call) = 0; i don't think we want this! */ oci_debug("php_rinit_oci"); return SUCCESS;}static int _session_pcleanup(oci_session *session TSRMLS_DC){ _oci_close_session(session); return 1;}static int _server_pcleanup(oci_server *server TSRMLS_DC){ _oci_close_server(server); return 1;}PHP_MSHUTDOWN_FUNCTION(oci){ OCI(shutdown) = 1; oci_debug("START php_mshutdown_oci"); zend_hash_apply(OCI(user), (apply_func_t)_session_pcleanup TSRMLS_CC); zend_hash_apply(OCI(server), (apply_func_t)_server_pcleanup TSRMLS_CC); zend_hash_destroy(OCI(user)); zend_hash_destroy(OCI(server)); free(OCI(user)); free(OCI(server)); CALL_OCI(OCIHandleFree( (dvoid *)OCI(pEnv), OCI_HTYPE_ENV)); oci_debug("END php_mshutdown_oci"); return SUCCESS;}PHP_RSHUTDOWN_FUNCTION(oci){ oci_debug("START php_rshutdown_oci");#if 0 /* XXX free all statements, rollback all outstanding transactions */ zend_hash_apply(OCI(user), (apply_func_t) _session_cleanup TSRMLS_CC); zend_hash_apply(OCI(server), (apply_func_t) _server_cleanup TSRMLS_CC);#endif oci_debug("END php_rshutdown_oci"); return SUCCESS;}PHP_MINFO_FUNCTION(oci){ php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); php_info_print_table_row(2, "Revision", "$Revision: 1.183.2.18.2.4 $");#ifndef PHP_WIN32 php_info_print_table_row(2, "Oracle Version", PHP_OCI8_VERSION ); php_info_print_table_row(2, "Compile-time ORACLE_HOME", PHP_OCI8_DIR ); php_info_print_table_row(2, "Libraries Used", PHP_OCI8_SHARED_LIBADD );#endif php_info_print_table_end();}/* }}} *//* {{{ _oci_define_hash_dtor() */static void_oci_define_hash_dtor(void *data){ oci_define *define = (oci_define *) data; oci_debug("_oci_define_hash_dtor: %s",define->name); zval_ptr_dtor(&define->zval); if (define->name) { efree(define->name); define->name = 0; }}/* }}} *//* {{{ _oci_bind_hash_dtor() */static void_oci_bind_hash_dtor(void *data){ oci_bind *bind = (oci_bind *) data; oci_debug("_oci_bind_hash_dtor:"); zval_ptr_dtor(&(bind->zval));}/* }}} *//* {{{ _oci_bind_pre_exec() */static int_oci_bind_pre_exec(void *data TSRMLS_DC){ oci_bind *bind = (oci_bind *) data; /* reset all bind stuff to a normal state..-. */ bind->indicator = 0; return 0;}/* }}} *//* {{{ _oci_bind_post_exec() */static int_oci_bind_post_exec(void *data TSRMLS_DC){ oci_bind *bind = (oci_bind *) data; if (bind->indicator == -1) { /* NULL */ zval *val = bind->zval; if (Z_TYPE_P(val) == IS_STRING && (Z_STRVAL_P(val) != empty_string)) { *Z_STRVAL_P(val) = '\0'; /* XXX avoid warning in debug mode */ } zval_dtor(val); ZVAL_NULL(val); } else if (Z_TYPE_P(bind->zval) == IS_STRING && (Z_STRVAL_P(bind->zval) != empty_string)) { Z_STRVAL_P(bind->zval) = erealloc(Z_STRVAL_P(bind->zval), Z_STRLEN_P(bind->zval)+1); Z_STRVAL_P(bind->zval)[ Z_STRLEN_P(bind->zval) ] = '\0'; } return 0;}/* }}} *//* {{{ _oci_column_hash_dtor() */static void_oci_column_hash_dtor(void *data){ oci_out_column *column = (oci_out_column *) data; TSRMLS_FETCH(); oci_debug("START _oci_column_hash_dtor: %s",column->name); if (column->stmtid) { zend_list_delete(column->stmtid); } if (column->is_descr) { zend_list_delete(column->descid); } else { if (column->data) { efree(column->data); } } oci_debug("END _oci_column_hash_dtor: %s",column->name); if (column->name) { efree(column->name); }}/* }}} *//* {{{ _oci_stmt_list_dtor() */ static void_oci_stmt_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_statement *statement = (oci_statement *)rsrc->ptr; oci_debug("START _oci_stmt_list_dtor: id=%d last_query=\"%s\"",statement->id,SAFE_STRING(statement->last_query)); if (statement->pStmt) { CALL_OCI(OCIHandleFree( statement->pStmt, OCI_HTYPE_STMT)); statement->pStmt = 0; } if (statement->pError) { CALL_OCI(OCIHandleFree( statement->pError, OCI_HTYPE_ERROR)); statement->pError = 0; } if (statement->last_query) { efree(statement->last_query); } if (statement->columns) { zend_hash_destroy(statement->columns); efree(statement->columns); } if (statement->binds) { zend_hash_destroy(statement->binds); efree(statement->binds); } if (statement->defines) { zend_hash_destroy(statement->defines); efree(statement->defines); } zend_list_delete(statement->conn->id); oci_debug("END _oci_stmt_list_dtor: id=%d",statement->id); efree(statement);}/* }}} *//* {{{ _oci_conn_list_dtor() */static void_oci_conn_list_dtor(oci_connection *connection TSRMLS_DC){ /* as the connection is "only" a in memory service context we do not disconnect from oracle. */ oci_debug("START _oci_conn_list_dtor: id=%d",connection->id); if (connection->pServiceContext) { if (connection->needs_commit) { oci_debug("OCITransRollback"); CALL_OCI_RETURN(connection->error,OCITransRollback( connection->pServiceContext, connection->pError, (ub4)0)); if (connection->error) { oci_error(connection->pError, "failed to rollback outstanding transactions!", connection->error); } connection->needs_commit = 0; } else { oci_debug("nothing to do.."); } CALL_OCI(OCIHandleFree( (dvoid *) connection->pServiceContext, (ub4) OCI_HTYPE_SVCCTX)); } if (connection->pError) { CALL_OCI(OCIHandleFree( (dvoid *) connection->pError, (ub4) OCI_HTYPE_ERROR)); } if (connection->session && connection->session->exclusive) { /* exclusive connection created via OCINLogon() close their associated session when destructed */ zend_list_delete(connection->session->num); } oci_debug("END _oci_conn_list_dtor: id=%d",connection->id); efree(connection);}/* }}} *//* {{{ php_oci_free_conn_list */static void php_oci_free_conn_list(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_connection *conn = (oci_connection *)rsrc->ptr; _oci_conn_list_dtor(conn TSRMLS_CC);}/* }}} */#ifdef WITH_COLLECTIONS/* {{{ _oci_coll_list_dtor() */static void _oci_coll_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_collection *coll = (oci_collection *)rsrc->ptr; oci_debug("START _oci_coll_list_dtor: %d",coll->id); zend_list_delete(coll->conn->id); /* Note sure if we need to free the object. Have an oracle TAR out on this one. OCIDescriptorFree(descr->ocidescr, Z_TYPE_P(descr)); */ oci_debug("END _oci_coll_list_dtor: %d",coll->id); efree(coll);}/* }}} */#endif/* {{{ _oci_descriptor_list_dtor() */static void _oci_descriptor_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_descriptor *descr = (oci_descriptor *)rsrc->ptr; oci_debug("START _oci_descriptor_list_dtor: %d",descr->id); zend_list_delete(descr->conn->id); CALL_OCI(OCIDescriptorFree( descr->ocidescr, Z_TYPE_P(descr))); oci_debug("END _oci_descriptor_list_dtor: %d",descr->id); efree(descr);}/* }}} *//* {{{ _oci_server_list_dtor() */static void _oci_server_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_server *server = (oci_server *)rsrc->ptr; if (server->persistent) return; _oci_close_server(server);}/* }}} *//* {{{ _oci_session_list_dtor() */static void _oci_session_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC){ oci_session *session = (oci_session *)rsrc->ptr; if (session->persistent) return; _oci_close_session(session);}/* }}} *//* {{{ oci_handle_error */static ub4oci_handle_error(oci_connection *connection, ub4 errcode){ switch (errcode) { case 1013: /* user requested cancel of current operation */ zend_bailout(); break; case 22: /* ORA-00022 Invalid session id */ case 1012: /* ORA-01012: */ case 3113: /* ORA-03113: end-of-file on communication channel */ case 604: case 1041: connection->is_open = 0; connection->session->is_open = 0; connection->session->server->is_open = 0; return 1; /* fatal error */ } return 0; /* no fatal error */}/* }}} *//* {{{ oci_error() */static ub4oci_error(OCIError *err_p, char *what, sword status){ text errbuf[512]; sb4 errcode = 0; TSRMLS_FETCH(); switch (status) { case OCI_SUCCESS: break; case OCI_SUCCESS_WITH_INFO: CALL_OCI(OCIErrorGet( err_p, (ub4)1, NULL, &errcode, errbuf, (ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s: OCI_SUCCESS_WITH_INFO: %s", what, errbuf); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -