CVS update: php3/functions

From: Date: Wed, 03 Feb 1999 18:21:02 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-3862@lists.php.net to get a copy of this message
Date: Wednesday February 3, 1999 @ 13:21 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv10739 Modified Files: oci8.c php3_oci8.h Log Message: internal login sequence is more flexible (still no plogon) added ocicommit, ocirollback added LOB read and write support added optional parameter to ociexecute (needed for lob-updates) i would classify this module as beta. i will continue to work on it and eventually add stuff to the ChangeLog and write the docs! Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.23 php3/functions/oci8.c:1.24 *** php3/functions/oci8.c:1.23 Wed Feb 3 10:08:08 1999 --- php3/functions/oci8.c Wed Feb 3 13:21:01 1999 *************** *** 30,36 **** +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.23 1999/02/03 15:08:08 thies Exp $ */ #include "php.h" #include "internal_functions.h" --- 30,36 ---- +----------------------------------------------------------------------+ */ ! /* $Id: oci8.c,v 1.24 1999/02/03 18:21:01 thies Exp $ */ #include "php.h" #include "internal_functions.h" *************** *** 129,135 **** static int oci8_ping(oci8_connection *conn); static void oci8_debug(const char *format,...); static void oci8_close_conn(oci8_connection *connection); ! static void oci8_free_blobs(oci8_connection *connection); static void oci8_free_stmt(oci8_statement *statement); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); --- 129,135 ---- static int oci8_ping(oci8_connection *conn); static void oci8_debug(const char *format,...); static void oci8_close_conn(oci8_connection *connection); ! static void oci8_free_lobs(oci8_connection *connection); static void oci8_free_stmt(oci8_statement *statement); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); *************** *** 137,143 **** static oci8_out_column *oci8_get_col(oci8_statement *, int, char *); static pval *oci8_make_pval(int,oci8_out_column *, char *,HashTable *); static int oci8_parse(oci8_connection *, text *, ub4, HashTable *); ! static int oci8_execute(oci8_statement *, char *); static int oci8_fetch(oci8_statement *, ub4, char *); /* bind callback functions */ --- 137,143 ---- static oci8_out_column *oci8_get_col(oci8_statement *, int, char *); static pval *oci8_make_pval(int,oci8_out_column *, char *,HashTable *); static int oci8_parse(oci8_connection *, text *, ub4, HashTable *); ! static int oci8_execute(oci8_statement *, char *,ub4 mode); static int oci8_fetch(oci8_statement *, ub4, char *); /* bind callback functions */ *************** *** 159,165 **** void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_getblob(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); --- 159,168 ---- void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS); ! void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_numcols(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_parse(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_result(INTERNAL_FUNCTION_PARAMETERS); *************** *** 189,196 **** {"ocistatementtype", php3_oci8_statementtype, NULL}, {"ocilogoff", php3_oci8_logoff, NULL}, {"ocilogon", php3_oci8_logon, NULL}, ! {"ocigetblob", php3_oci8_getblob, NULL}, ! /* {"ociplogon", php3_oci8_plogon, NULL},*/ {NULL, NULL, NULL} }; --- 192,201 ---- {"ocistatementtype", php3_oci8_statementtype, NULL}, {"ocilogoff", php3_oci8_logoff, NULL}, {"ocilogon", php3_oci8_logon, NULL}, ! {"ocisavelob", php3_oci8_savelob, NULL}, ! {"ociloadlob", php3_oci8_loadlob, NULL}, ! {"ocicommit", php3_oci8_commit, NULL}, ! {"ocirollback", php3_oci8_rollback, NULL}, {NULL, NULL, NULL} }; *************** *** 249,256 **** OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; ! OCI8_GLOBAL(php3_oci8_module).le_blob = ! register_list_destructors(oci8_free_blobs, NULL); OCI8_GLOBAL(php3_oci8_module).le_conn = register_list_destructors(oci8_close_conn, NULL); --- 254,261 ---- OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; ! OCI8_GLOBAL(php3_oci8_module).le_lob = ! register_list_destructors(oci8_free_lobs, NULL); OCI8_GLOBAL(php3_oci8_module).le_conn = register_list_destructors(oci8_close_conn, NULL); *************** *** 268,273 **** --- 273,285 ---- OCI8_GLOBAL(php3_oci8_module).debug_mode = 0; } + /* thies@digicol.de 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); + return SUCCESS; } *************** *** 360,367 **** oci8_free_column(oci8_out_column *column) { if (column->data) { ! if (column->is_blob) { ! /* XXX free blob here */ } else { efree(column->data); } --- 372,379 ---- oci8_free_column(oci8_out_column *column) { if (column->data) { ! if (column->is_lob) { ! /* XXX free lob here */ } else { efree(column->data); } *************** *** 401,410 **** } /* }}} */ ! /* {{{ oci8_free_blobs() */ static void ! oci8_free_blobs(oci8_connection *connection) { OCI8_TLS_VARS; /* XXX needs implementation */ --- 413,422 ---- } /* }}} */ ! /* {{{ oci8_free_lobs() */ static void ! oci8_free_lobs(oci8_connection *connection) { OCI8_TLS_VARS; /* XXX needs implementation */ *************** *** 561,572 **** int locator; pval *value = ecalloc(1,sizeof(pval)); ! if (column->is_blob) { object_init(value); ! locator = php3_list_insert(column->data, OCI8_GLOBAL(php3_oci8_module).le_blob); add_property_long(value, "locator", locator); add_property_long(value, "statement", stmt_ind); ! add_method(value, "get", php3_oci8_getblob); } else { switch (column->indicator) { case -1: /* NULL value, return an empty string */ --- 573,585 ---- int locator; pval *value = ecalloc(1,sizeof(pval)); ! if (column->is_lob) { object_init(value); ! locator = php3_list_insert(column->data, OCI8_GLOBAL(php3_oci8_module).le_lob); add_property_long(value, "locator", locator); add_property_long(value, "statement", stmt_ind); ! add_method(value, "save", php3_oci8_savelob); ! add_method(value, "load", php3_oci8_loadlob); } else { switch (column->indicator) { case -1: /* NULL value, return an empty string */ *************** *** 625,631 **** /* {{{ oci8_execute() */ static int ! oci8_execute(oci8_statement *statement, char *func) { oci8_out_column *outcol; OCIParam *param; --- 638,644 ---- /* {{{ oci8_execute() */ static int ! oci8_execute(oci8_statement *statement, char *func,ub4 mode) { oci8_out_column *outcol; OCIParam *param; *************** *** 633,639 **** sword error, def_error; ub2 define_type; ub2 stmttype = 0; ! ub4 iters, mode; OCI8_TLS_VARS; OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT, --- 646,652 ---- sword error, def_error; ub2 define_type; ub2 stmttype = 0; ! ub4 iters; OCI8_TLS_VARS; OCIAttrGet((dvoid *)statement->pStmt, OCI_HTYPE_STMT, *************** *** 645,651 **** } else { iters = 1; } - mode = OCI_COMMIT_ON_SUCCESS; oci8_debug("oci8_execute: stmttype=%d mode=%d", stmttype, mode); error = OCIStmtExecute(statement->conn->pServiceContext, statement->pStmt, statement->pError, --- 658,663 ---- *************** *** 721,727 **** switch (outcol->type) { case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ ! outcol->is_blob = 1; OCIDescriptorAlloc(statement->conn->pEnv,&(outcol->data), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); define_type = outcol->type; def_error = OCIDefineByPos(statement->pStmt, --- 733,740 ---- switch (outcol->type) { case SQLT_BLOB: /* binary LOB */ case SQLT_CLOB: /* character LOB */ ! case SQLT_BFILE: /* binary file LOB */ ! outcol->is_lob = 1; OCIDescriptorAlloc(statement->conn->pEnv,&(outcol->data), OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); define_type = outcol->type; def_error = OCIDefineByPos(statement->pStmt, *************** *** 738,744 **** break; case SQLT_BIN: /* RAW */ case SQLT_LBI: /* LONG RAW */ - case SQLT_BFILE: /* binary file LOB */ case SQLT_RSET: /* ref. cursor */ outcol->is_opaque = 1; define_type = outcol->type; --- 751,756 ---- *************** *** 998,1017 **** } /* }}} */ ! /* {{{ proto string ocigetblob(object blob) */ ! void php3_oci8_getblob(INTERNAL_FUNCTION_PARAMETERS) { ! pval *id, *tmp, *stmt, *col; int id_to_find; int lob_type; OCILobLocator *mylob; oci8_statement *statement; sword ociresult; char *buffer; ub4 loblen; - ub4 amtp; OCI8_TLS_VARS; --- 1010,1098 ---- } /* }}} */ ! /* {{{ proto string ocisavelob(object lob) */ ! void php3_oci8_savelob(INTERNAL_FUNCTION_PARAMETERS) { ! pval *id, *tmp, *stmt, *arg; int id_to_find; int lob_type; OCILobLocator *mylob; oci8_statement *statement; sword ociresult; + ub4 loblen; + + OCI8_TLS_VARS; + + if (getThis(&id) == SUCCESS) { + if (_php3_hash_find(id->value.ht, "statement", sizeof("statement"), (void **)&stmt) == FAILURE) { + php3_error(E_WARNING, "unable to find my statement property"); + RETURN_FALSE; + } + + statement = oci8_get_stmt(stmt->value.lval, "OCISaveLob", list); + if (statement == NULL) { + RETURN_FALSE; + } + + if (_php3_hash_find(id->value.ht, "locator", sizeof("locator"), (void **)&tmp) == FAILURE) { + php3_error(E_WARNING, "unable to find my locator property"); + RETURN_FALSE; + } + + id_to_find = tmp->value.lval; + mylob = (OCILobLocator *) php3_list_find(id_to_find, &lob_type); + + if (!mylob || lob_type != OCI8_GLOBAL(php3_oci8_module).le_lob) { + php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); + RETURN_FALSE; + } + + if (getParameters(ht, 1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + loblen = arg->value.str.len; + + ociresult = OCILobWrite(statement->conn->pServiceContext, + statement->conn->pError, + mylob, + &loblen, + (ub4) 1, + (dvoid *) arg->value.str.val, + (ub4) loblen, + OCI_ONE_PIECE, + (dvoid *)0, + (OCICallbackLobWrite) 0, + (ub2) 0, + (ub1) SQLCS_IMPLICIT); + + if (ociresult) { + oci8_error(statement->conn->pError, "OCILobWrite", ociresult); + RETURN_FALSE; + } + + RETURN_TRUE; + } + + RETURN_FALSE; + } + + /* }}} */ + /* {{{ proto string ociloadlob(object lob) + */ + + void php3_oci8_loadlob(INTERNAL_FUNCTION_PARAMETERS) + { + pval *id, *tmp, *stmt; + int id_to_find; + int lob_type; + OCILobLocator *mylob; + oci8_statement *statement; + sword ociresult; char *buffer; ub4 loblen; OCI8_TLS_VARS; *************** *** 1021,1027 **** RETURN_FALSE; } ! statement = oci8_get_stmt(stmt->value.lval, "OCIGetBlob", list); if (statement == NULL) { RETURN_FALSE; } --- 1102,1108 ---- RETURN_FALSE; } ! statement = oci8_get_stmt(stmt->value.lval, "OCILoadLob", list); if (statement == NULL) { RETURN_FALSE; } *************** *** 1034,1040 **** id_to_find = tmp->value.lval; mylob = (OCILobLocator *) php3_list_find(id_to_find, &lob_type); ! if (!mylob || lob_type != OCI8_GLOBAL(php3_oci8_module).le_blob) { php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } --- 1115,1121 ---- id_to_find = tmp->value.lval; mylob = (OCILobLocator *) php3_list_find(id_to_find, &lob_type); ! if (!mylob || lob_type != OCI8_GLOBAL(php3_oci8_module).le_lob) { php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find); RETURN_FALSE; } *************** *** 1045,1055 **** oci8_error(statement->conn->pError, "OCILobGetLength", ociresult); RETURN_FALSE; } ! buffer = emalloc(loblen); - if (! buffer) { - php3_error(E_ERROR,"OCIGetBlob: unable to convert allocate %ld bytes.",loblen); RETURN_FALSE; } --- 1126,1134 ---- oci8_error(statement->conn->pError, "OCILobGetLength", ociresult); RETURN_FALSE; } ! buffer = emalloc(loblen); if (! buffer) { RETURN_FALSE; } *************** *** 1078,1083 **** --- 1157,1226 ---- } /* }}} */ + /* {{{ proto string OCIRollback(int stmt) + rollback the current context + */ + + void php3_oci8_rollback(INTERNAL_FUNCTION_PARAMETERS) + { + pval *stmt; + oci8_statement *statement; + sword ociresult; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &stmt) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(stmt); + + statement = oci8_get_stmt(stmt->value.lval, "OCIRollback", list); + if (statement == NULL) { + RETURN_FALSE; + } + + ociresult = OCITransRollback(statement->conn->pServiceContext,statement->conn->pError, (ub4)0); + + if (ociresult) { + oci8_error(statement->conn->pError, "OCIRollback", ociresult); + RETURN_FALSE; + } + + RETURN_TRUE; + } + + /* }}} */ + /* {{{ proto string OCICommit(int stmt) + commit the current context + */ + + void php3_oci8_commit(INTERNAL_FUNCTION_PARAMETERS) + { + pval *stmt; + oci8_statement *statement; + sword ociresult; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &stmt) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(stmt); + + statement = oci8_get_stmt(stmt->value.lval, "OCICommit", list); + if (statement == NULL) { + RETURN_FALSE; + } + + ociresult = OCITransCommit(statement->conn->pServiceContext,statement->conn->pError, (ub4)0); + + if (ociresult) { + oci8_error(statement->conn->pError, "OCICommit", ociresult); + RETURN_FALSE; + } + + RETURN_TRUE; + } + + /* }}} */ /* {{{ proto string OCIColumnName(int stmt, int col) Tell the name of a column. */ *************** *** 1254,1273 **** void php3_oci8_execute(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt; oci8_statement *statement; OCI8_TLS_VARS; ! if (getParameters(ht, 1, &stmt) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(stmt); statement = oci8_get_stmt(stmt->value.lval, "OCIExecute", list); if (statement == NULL) { RETURN_FALSE; } ! ! if (oci8_execute(statement, "OCIExecute")) { RETVAL_TRUE; } else { RETVAL_FALSE; --- 1397,1423 ---- void php3_oci8_execute(INTERNAL_FUNCTION_PARAMETERS) { ! pval *stmt,*mode; oci8_statement *statement; + ub4 execmode; OCI8_TLS_VARS; ! if (getParameters(ht, 2, &stmt, &mode) == SUCCESS) { ! convert_to_long(mode); ! execmode = mode->value.lval; ! } else if (getParameters(ht, 1, &stmt) == SUCCESS) { ! execmode = OCI_COMMIT_ON_SUCCESS; ! } else { WRONG_PARAM_COUNT; } + convert_to_long(stmt); statement = oci8_get_stmt(stmt->value.lval, "OCIExecute", list); if (statement == NULL) { RETURN_FALSE; } ! ! if (oci8_execute(statement, "OCIExecute",execmode)) { RETVAL_TRUE; } else { RETVAL_FALSE; *************** *** 1461,1471 **** OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL); #endif OCIEnvInit(&connection->pEnv, OCI_DEFAULT, 0, NULL); ! OCIHandleAlloc(connection->pEnv, (dvoid **)&connection->pError, ! OCI_HTYPE_ERROR, 0, NULL); ! OCIHandleAlloc(connection->pEnv, ! (dvoid **)&connection->pServiceContext, ! OCI_HTYPE_SVCCTX, 0, NULL); error = OCILogon((OCIEnv *)connection->pEnv, (OCIError *)connection->pError, --- 1611,1659 ---- OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL); #endif OCIEnvInit(&connection->pEnv, OCI_DEFAULT, 0, NULL); ! OCIHandleAlloc(connection->pEnv, (dvoid **)&connection->pServiceContext, OCI_HTYPE_SVCCTX, 0, NULL); ! OCIHandleAlloc(connection->pEnv, (dvoid **)&connection->pError, OCI_HTYPE_ERROR, 0, NULL); ! OCIHandleAlloc(connection->pEnv, (dvoid **)&connection->pServer, OCI_HTYPE_SERVER, 0, NULL); ! OCIHandleAlloc(connection->pEnv, (dvoid **)&connection->pSession, OCI_HTYPE_SESSION, 0, NULL); ! ! error = OCIServerAttach(connection->pServer,connection->pError,dbname,dbname_len, (ub4) OCI_DEFAULT); ! if (error) { ! oci8_error(connection->pError, "OCIServerAttach", error); ! RETURN_FALSE; ! } ! ! error = OCIAttrSet((dvoid *) connection->pSession,(ub4) OCI_HTYPE_SESSION, (dvoid *) username, (ub4) username_len, (ub4) OCI_ATTR_USERNAME, connection->pError); ! if (error) { ! oci8_error(connection->pError, "OCIAttrSet OCI_ATTR_USERNAME", error); ! RETURN_FALSE; ! } ! ! error = OCIAttrSet((dvoid *) connection->pSession,(ub4) OCI_HTYPE_SESSION, (dvoid *) password, (ub4) password_len, (ub4) OCI_ATTR_PASSWORD, connection->pError); ! if (error) { ! oci8_error(connection->pError, "OCIAttrSet OCI_ATTR_PASSWORD", error); ! RETURN_FALSE; ! } ! ! error = OCIAttrSet((dvoid *)connection->pServiceContext, (ub4) OCI_HTYPE_SVCCTX,(dvoid *) connection->pServer, (ub4) 0, (ub4) OCI_ATTR_SERVER, connection->pError); ! if (error) { ! oci8_error(connection->pError, "OCIAttrSet OCI_ATTR_SERVER", error); ! RETURN_FALSE; ! } ! ! error = OCISessionBegin(connection->pServiceContext,connection->pError,connection->pSession, (ub4) OCI_CRED_RDBMS, (ub4) OCI_DEFAULT); ! if (error) { ! oci8_error(connection->pError, "OCISessionBegin", error); ! RETURN_FALSE; ! } ! ! error = OCIAttrSet((dvoid *)connection->pServiceContext,(ub4) OCI_HTYPE_SVCCTX, (dvoid *) connection->pSession, (ub4) 0, (ub4) OCI_ATTR_SESSION, connection->pError); ! if (error) { ! oci8_error(connection->pError, "OCIAttrSet OCI_ATTR_SESSION", error); ! RETURN_FALSE; ! } ! ! ! /* error = OCILogon((OCIEnv *)connection->pEnv, (OCIError *)connection->pError, *************** *** 1473,1478 **** --- 1661,1667 ---- (CONST text *)username, (ub4)username_len, (CONST text *)password, (ub4)password_len, (CONST text *)dbname, (ub4)dbname_len); + */ if (error) { oci8_error(connection->pError, "OCILogon", error); RETURN_FALSE; Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.14 php3/functions/php3_oci8.h:1.15 *** php3/functions/php3_oci8.h:1.14 Wed Feb 3 10:08:08 1999 --- php3/functions/php3_oci8.h Wed Feb 3 13:21:02 1999 *************** *** 59,66 **** typedef struct { OCIEnv *pEnv; ! OCIError *pError; OCISvcCtx *pServiceContext; int open; } oci8_connection; --- 59,68 ---- typedef struct { OCIEnv *pEnv; ! OCIServer *pServer; OCISvcCtx *pServiceContext; + OCIError *pError; + OCISession *pSession; int open; } oci8_connection; *************** *** 95,101 **** sb2 indicator; ub2 retcode; ub2 is_opaque; ! ub2 is_blob; pval *value; } oci8_out_column; --- 97,103 ---- sb2 indicator; ub2 retcode; ub2 is_opaque; ! ub2 is_lob; pval *value; } oci8_out_column; *************** *** 110,116 **** long num_persistent; long num_links; int le_conn; ! int le_blob; /* int le_pconn;*/ int le_stmt; sb4 max_bind_data_size; --- 112,118 ---- long num_persistent; long num_links; int le_conn; ! int le_lob; /* int le_pconn;*/ int le_stmt; sb4 max_bind_data_size; -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#3862) next »