CVS update: php3/functions

From: Date: Mon, 15 Mar 1999 19:04:36 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4634@lists.php.net to get a copy of this message
Date: Monday March 15, 1999 @ 14:04 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv17426 Modified Files: oci8.c php3_oci8.h Log Message: working on (hopefully blazing fast) persintent connections & fine grained session control.. Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.68 php3/functions/oci8.c:1.69 *** php3/functions/oci8.c:1.68 Wed Mar 10 17:08:23 1999 --- php3/functions/oci8.c Mon Mar 15 14:04:36 1999 *************** *** 33,39 **** #define OCI8_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */ ! /* $Id: oci8.c,v 1.68 1999/03/10 22:08:23 thies Exp $ */ /* TODO list: * --- 33,39 ---- #define OCI8_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */ ! /* $Id: oci8.c,v 1.69 1999/03/15 19:04:36 thies Exp $ */ /* TODO list: * *************** *** 148,159 **** static ub4 oci8_error(OCIError *err_p, char *what, sword status); /* static int oci8_ping(oci8_connection *conn); XXX NYI */ static void oci8_debug(const char *format,...); ! static void oci8_close(oci8_connection *connection,int persistent); static void oci8_close_conn(oci8_connection *connection); - static void oci8_close_pconn(oci8_connection *connection); static void oci8_free_descr(oci8_descriptor *descr); static void oci8_free_stmt(oci8_statement *statement); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); static oci8_statement *oci8_get_stmt(int, const char *, HashTable *); static oci8_out_column *oci8_get_col(oci8_statement *, int, pval *, char *); --- 148,159 ---- static ub4 oci8_error(OCIError *err_p, char *what, sword status); /* static int oci8_ping(oci8_connection *conn); XXX NYI */ static void oci8_debug(const char *format,...); ! static void oci8_close_server(oci8_server *server); static void oci8_close_conn(oci8_connection *connection); static void oci8_free_descr(oci8_descriptor *descr); static void oci8_free_stmt(oci8_statement *statement); + static oci8_server *oci8_get_server(int server_ind, const char *func, HashTable *list, HashTable *plist); static oci8_connection *oci8_get_conn(int, const char *, HashTable *, HashTable *); static oci8_statement *oci8_get_stmt(int, const char *, HashTable *); static oci8_out_column *oci8_get_col(oci8_statement *, int, pval *, char *); *************** *** 163,169 **** --- 163,174 ---- static int oci8_fetch(oci8_statement *, ub4, char *); static ub4 oci8_loaddesc(oci8_connection *, oci8_descriptor *, char **); static void oci8_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent); + static oci8_server *oci8_attach(char *dbname,int persistent,HashTable *list, HashTable *plist); + static int oci8_detach(oci8_server *server); + static oci8_session *oci8_open(oci8_server* server,char *username,char *password,HashTable *list, HashTable *plist); + static int oci8_close(oci8_session *session); + /* bind callback functions */ static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **); static sb4 oci8_bind_out_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **); *************** *** 188,193 **** --- 193,203 ---- void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_detach(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_attach(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_pattach(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_open(INTERNAL_FUNCTION_PARAMETERS); + void php3_oci8_close(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_plogon(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_error(INTERNAL_FUNCTION_PARAMETERS); void php3_oci8_freedesc(INTERNAL_FUNCTION_PARAMETERS); *************** *** 237,242 **** --- 247,257 ---- {"ocirowcount", php3_oci8_rowcount, NULL}, {"ocilogoff", php3_oci8_logoff, NULL}, {"ocilogon", php3_oci8_logon, NULL}, + {"ocidetach", php3_oci8_detach, NULL}, + {"ociattach", php3_oci8_attach, NULL}, + {"ocipattach", php3_oci8_pattach, NULL}, + {"ociopen", php3_oci8_open, NULL}, + {"ociclose", php3_oci8_close, NULL}, {"ociplogon", php3_oci8_plogon, NULL}, {"ocierror", php3_oci8_error, NULL}, {"ocifreedescriptor",php3_oci8_freedesc, NULL}, *************** *** 307,314 **** register_list_destructors(oci8_close_conn, NULL); OCI8_GLOBAL(php3_oci8_module).le_pconn = ! register_list_destructors(oci8_close_pconn, NULL); OCI8_GLOBAL(php3_oci8_module).le_stmt = register_list_destructors(oci8_free_stmt, NULL); --- 322,335 ---- register_list_destructors(oci8_close_conn, NULL); OCI8_GLOBAL(php3_oci8_module).le_pconn = ! register_list_destructors(oci8_close_conn, NULL); ! ! OCI8_GLOBAL(php3_oci8_module).le_server = ! register_list_destructors(oci8_close_server, NULL); + OCI8_GLOBAL(php3_oci8_module).le_pserver = + register_list_destructors(oci8_close_server, NULL); + OCI8_GLOBAL(php3_oci8_module).le_stmt = register_list_destructors(oci8_free_stmt, NULL); *************** *** 352,357 **** --- 373,386 ---- 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); + #if OCI8_USE_EMALLOC + OCIInitialize(OCI_DEFAULT, (dvoid *)connection, ocimalloc, ocirealloc, ocifree); + #else + OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL); + #endif + + OCIEnvInit(&OCI8_GLOBAL(php3_oci8_module).pEnv, OCI_DEFAULT, 0, NULL); + return SUCCESS; } *************** *** 531,542 **** } /* }}} */ /* }}} */ ! /* {{{ oci8_close() */ static void ! oci8_close(oci8_connection *connection,int persistent) { OCI8_TLS_VARS; oci8_debug("oci8_close_conn: id=%d persistent=%d",connection->id,persistent); --- 560,597 ---- } /* }}} */ + /* {{{ oci8_close_server() */ + + static void + oci8_close_server(oci8_server *server) + { + oci8_debug("oci8_close_server"); + + oci8_error(server->pError,"oci8_close_server", + OCIServerDetach(server->pServer, server->pError, (ub4) OCI_DEFAULT)); + + /* + if (OCIHandleFree((dvoid *)server->pEnv, OCI_HTYPE_ENV) != OCI_SUCCESS) { + oci8_debug("oci8_close_server: OCIHandleFree returned error"); + } + */ + + if (server->persistent) { + free(server); + } else { + efree(server); + } + + } + /* }}} */ ! /* {{{ oci8_close_conn() */ static void ! oci8_close_conn(oci8_connection *connection) { + int persistent = 0; + OCI8_TLS_VARS; oci8_debug("oci8_close_conn: id=%d persistent=%d",connection->id,persistent); *************** *** 554,560 **** oci8_error(connection->pError,"OCISessionEnd", OCISessionEnd(connection->pServiceContext, connection->pError, connection->pSession, (ub4) 0)); ! oci8_error(connection->pError,"OCIServerDetach", OCIServerDetach(connection->pServer, connection->pError, (ub4) OCI_DEFAULT)); /* from Oracle Doc: All handles may be explicitly deallocated. --- 609,615 ---- oci8_error(connection->pError,"OCISessionEnd", OCISessionEnd(connection->pServiceContext, connection->pError, connection->pSession, (ub4) 0)); ! oci8_error(connection->pError,"OCIServerDetach", OCIServerDetach(connection->pServer, connection->pError, (ub4) OCI_DEFAULT)); /* from Oracle Doc: All handles may be explicitly deallocated. *************** *** 579,602 **** } /* }}} */ - /* {{{ oci8_close_conn() */ - - static void - oci8_close_conn(oci8_connection *connection) - { - oci8_close(connection,0); - } - - /* }}} */ - /* {{{ oci8_close_pconn() */ - - static void - oci8_close_pconn(oci8_connection *connection) - { - oci8_close(connection,1); - } - - /* }}} */ /* {{{ oci8_error() */ static ub4 --- 634,639 ---- *************** *** 674,679 **** --- 711,734 ---- } /* }}} */ + /* {{{ oci8_get_server() */ + + static oci8_server * + oci8_get_server(int server_ind, const char *func, HashTable *list, HashTable *plist) + { + int type; + oci8_server *server; + OCI8_TLS_VARS; + + server = (oci8_server *) php3_list_find(server_ind, &type); + if (!server || !OCI8_SERVER_TYPE(type)) { + php3_error(E_WARNING, "%s: invalid server %d", func, server_ind); + return (oci8_server *)NULL; + } + return server; + } + + /* }}} */ /* {{{ oci8_get_conn() */ static oci8_connection * *************** *** 1439,1448 **** --- 1494,1659 ---- } /* }}} */ + /* {{{ oci8_open() + */ + + static oci8_session *oci8_open(oci8_server* server,char *username,char *password,HashTable *list, HashTable *plist) + { + sword error; + oci8_session *session; + OCI8_TLS_VARS; + + + session = ecalloc(1,sizeof(oci8_session)); + + if (! session) { + return 0; + } + + session->server = server; + + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&session->pServiceContext, + OCI_HTYPE_SVCCTX, + 0, + NULL); + + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&session->pError, + OCI_HTYPE_ERROR, + 0, + NULL); + + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&session->pSession, + OCI_HTYPE_SESSION, + 0, + NULL); + + if (OCIAttrSet((dvoid *) session->pSession, + (ub4) OCI_HTYPE_SESSION, + (dvoid *) username, + (ub4) strlen(username), + (ub4) OCI_ATTR_USERNAME, + session->pError)) { + oci8_error(session->pError, "OCIAttrSet OCI_ATTR_USERNAME", error); + goto ERROR; + } + + if (OCIAttrSet((dvoid *) session->pSession, + (ub4) OCI_HTYPE_SESSION, + (dvoid *) password, + (ub4) strlen(password), + (ub4) OCI_ATTR_PASSWORD, + session->pError)) { + oci8_error(session->pError, "OCIAttrSet OCI_ATTR_PASSWORD", error); + goto ERROR; + } + + if (OCIAttrSet((dvoid *) session->pServiceContext, + (ub4) OCI_HTYPE_SVCCTX, + (dvoid *) server->pServer, + (ub4) 0, + (ub4) OCI_ATTR_SERVER, + session->pError)) { + oci8_error(session->pError, "OCIAttrSet OCI_ATTR_SERVER", error); + goto ERROR; + } + + if (OCISessionBegin(session->pServiceContext, + session->pError, + session->pSession, + (ub4) OCI_CRED_RDBMS, + (ub4) OCI_DEFAULT)) { + oci8_error(session->pError, "OCISessionBegin", error); + goto ERROR; + } + + if (OCIAttrSet((dvoid *) session->pServiceContext, + (ub4) OCI_HTYPE_SVCCTX, + (dvoid *) session->pSession, + (ub4) 0, + (ub4) OCI_ATTR_SESSION, + session->pError)) { + oci8_error(session->pError, "OCIAttrSet OCI_ATTR_SESSION", error); + goto ERROR; + } + + session->id = php3_list_insert(session, OCI8_GLOBAL(php3_oci8_module).le_session); + + return session; + + ERROR: + efree(session); + return 0; + } + + /* }}} */ + /* {{{ oci8_attach() + */ + static oci8_server *oci8_attach(char *dbname,int persistent,HashTable *list, HashTable *plist) + { + oci8_server *server; + sword error; + OCI8_TLS_VARS; + + /* XXX check if we already have this server open */ + + if (persistent) { + server = calloc(1,sizeof(oci8_server)); + } else { + server = ecalloc(1,sizeof(oci8_server)); + } + + server->persistent = persistent; + + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&server->pError, + OCI_HTYPE_ERROR, + 0, + NULL); + + OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, + (dvoid **)&server->pServer, + OCI_HTYPE_SERVER, + 0, + NULL); + + error = OCIServerAttach(server->pServer, + server->pError, + dbname, + strlen(dbname), + (ub4) OCI_DEFAULT); + + if (error) { + oci8_error(server->pError, "oci8_attach", error); + return 0; + } + + if (persistent) { + server->id = php3_list_insert(server, OCI8_GLOBAL(php3_oci8_module).le_pserver); + } else { + server->id = php3_list_insert(server, OCI8_GLOBAL(php3_oci8_module).le_server); + } + + oci8_debug("oci8_attach"); + + return server; + } + + /* }}} */ /* {{{ oci8_do_connect() Connect to an Oracle database and log on. returns a new session. */ + static int oci8_detach(oci8_server *server) + { + } + + /* }}} */ + /* {{{ oci8_do_connect() + Connect to an Oracle database and log on. returns a new session. + */ static void oci8_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent) { text *username, *password, *dbname; *************** *** 1539,1550 **** /* OCI_OBJECT is not supported as of now, but it should not harm!! */ - #if OCI8_USE_EMALLOC - OCIInitialize(OCI_DEFAULT, (dvoid *)connection, ocimalloc, ocirealloc, ocifree); - #else - 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); --- 1750,1757 ---- /* OCI_OBJECT is not supported as of now, but it should not harm!! */ 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); *************** *** 1555,1561 **** 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); --- 1762,1768 ---- 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); *************** *** 1594,1606 **** connection->descriptors = emalloc(sizeof(HashTable)); } ! if (!connection->descriptors || _php3_hash_init(connection->descriptors, 13, NULL,(void (*)(void *))oci8_free_descr, 0) == FAILURE) { /* out of memory */ RETURN_FALSE; } - OCI8_GLOBAL(php3_oci8_module).num_links++; /* non persistent, simply add to list */ --- 1801,1812 ---- connection->descriptors = emalloc(sizeof(HashTable)); } ! if (!connection->descriptors || _php3_hash_init(connection->descriptors, 13, NULL,(void (*)(void *))oci8_free_descr, 0) == FAILURE) { /* out of memory */ RETURN_FALSE; } OCI8_GLOBAL(php3_oci8_module).num_links++; /* non persistent, simply add to list */ *************** *** 2542,2547 **** --- 2748,2855 ---- oci8_debug("OCILogoff: php3_list_delete failed."); RETVAL_FALSE; } + } + + /* }}} */ + /* {{{ proto int OCIAttach(string $dbname) + */ + void php3_oci8_attach(INTERNAL_FUNCTION_PARAMETERS) + { + pval *dbname; + oci8_server *server; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &dbname) == SUCCESS) { + convert_to_string(dbname); + server = oci8_attach(dbname->value.str.val,0,list,plist); + } else { + server = oci8_attach("",0,list,plist); + } + + if (server) { + RETURN_LONG(server->id); + } else { + RETURN_FALSE; + } + } + + /* }}} */ + /* {{{ proto int OCIDetach(int server) + */ + + void php3_oci8_detach(INTERNAL_FUNCTION_PARAMETERS) + { + } + + /* }}} */ + /* {{{ proto int OCIPAttach(string $dbname) + */ + void php3_oci8_pattach(INTERNAL_FUNCTION_PARAMETERS) + { + pval *dbname; + oci8_server *server; + OCI8_TLS_VARS; + + if (getParameters(ht, 1, &dbname) == SUCCESS) { + convert_to_string(dbname); + server = oci8_attach(dbname->value.str.val,1,list,plist); + } else { + server = oci8_attach("",1,list,plist); + } + + if (server) { + RETURN_LONG(server->id); + } else { + RETURN_FALSE; + } + } + + /* }}} */ + /* {{{ proto int OCIOpen(string user, string pass) + */ + + void php3_oci8_open(INTERNAL_FUNCTION_PARAMETERS) + { + pval *serverParam, *userParam, *passParam; + oci8_session *session; + oci8_server *server; + OCI8_TLS_VARS; + + + if (getParameters(ht, 3, &serverParam, &userParam, &passParam) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(serverParam); + convert_to_string(userParam); + convert_to_string(passParam); + + server = oci8_get_server(serverParam->value.lval,"php3_oci8_open",list,plist); + if (! server) { + RETURN_FALSE; + } + + + session = oci8_open(server, + userParam->value.str.val, + passParam->value.str.val, + list, + plist); + + + if (session) { + RETVAL_LONG(session->id); + } else { + RETVAL_FALSE; + } + } + + /* }}} */ + /* {{{ proto int OCIClose(int $session) + */ + + void php3_oci8_close(INTERNAL_FUNCTION_PARAMETERS) + { } /* }}} */ Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.33 php3/functions/php3_oci8.h:1.34 *** php3/functions/php3_oci8.h:1.33 Wed Mar 10 17:08:23 1999 --- php3/functions/php3_oci8.h Mon Mar 15 14:04:36 1999 *************** *** 8,14 **** | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | ! | Foundation; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | --- 8,14 ---- | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | ! | Foundatbion; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | *************** *** 51,61 **** # include <oci.h> - # if 0 typedef struct { ! OCIEnv *pEnv; ! } oci8_request; ! # endif typedef struct { int id; --- 51,70 ---- # include <oci.h> typedef struct { ! int id; ! int persistent; ! OCIError *pError; ! OCIServer *pServer; ! } oci8_server; ! ! typedef struct { ! int id; ! oci8_server *server; ! OCIError *pError; ! OCISvcCtx *pServiceContext; ! OCISession *pSession; ! } oci8_session; typedef struct { int id; *************** *** 128,142 **** --- 137,161 ---- char *default_username; char *default_password; char *default_dbname; + long debug_mode; + long allow_persistent; long max_persistent; long max_links; long num_persistent; long num_links; + int le_conn; int le_pconn; int le_stmt; + + int le_server; + int le_pserver; + + int le_session; + + OCIEnv *pEnv; } oci8_module; extern php3_module_entry oci8_module_entry; *************** *** 146,151 **** --- 165,171 ---- # define OCI8_MAX_DATA_SIZE 2097152 /* two megs */ /* this one has to be changed to include persistent connections as well */ + # define OCI8_SERVER_TYPE(x) (((x)==OCI8_GLOBAL(php3_oci8_module).le_server) || ((x)==OCI8_GLOBAL(php3_oci8_module).le_pserver)) # define OCI8_CONN_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_conn) # define OCI8_PCONN_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_pconn) # define OCI8_STMT_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_stmt) -- 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 (#4634) next »