CVS update: php3/functions

From: Date: Wed, 07 Apr 1999 12:10:15 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4971@lists.php.net to get a copy of this message
Date: Wednesday April 7, 1999 @ 8:10 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv22472 Modified Files: oci8.c php3_oci8.h Log Message: last checking before persistent connections Index: php3/functions/oci8.c diff -c php3/functions/oci8.c:1.73 php3/functions/oci8.c:1.74 *** php3/functions/oci8.c:1.73 Tue Apr 6 08:45:51 1999 --- php3/functions/oci8.c Wed Apr 7 08:10:14 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.73 1999/04/06 12:45:51 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.74 1999/04/07 12:10:14 thies Exp $ */ /* TODO list: * *************** *** 148,154 **** 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); --- 148,154 ---- 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_debugcol(oci8_out_column * col,const char *format,...); static void oci8_close_conn(oci8_connection *connection); static void oci8_free_descr(oci8_descriptor *descr); static void oci8_free_stmt(oci8_statement *statement); *************** *** 163,172 **** 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 */ --- 163,173 ---- 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,int persistent,HashTable *list, HashTable *plist); static int oci8_close(oci8_session *session); /* bind callback functions */ *************** *** 317,337 **** } OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; ! OCI8_GLOBAL(php3_oci8_module).le_conn = 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); if (cfg_get_long("oci8.debug_mode", &OCI8_GLOBAL(php3_oci8_module).debug_mode) == FAILURE) { --- 318,348 ---- } OCI8_GLOBAL(php3_oci8_module).num_persistent = 0; ! ! /* OLD stuff */ OCI8_GLOBAL(php3_oci8_module).le_conn = 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_stmt = + register_list_destructors(oci8_free_stmt, NULL); + + + /* NEW stuff */ OCI8_GLOBAL(php3_oci8_module).le_server = ! register_list_destructors(oci8_detach, NULL); OCI8_GLOBAL(php3_oci8_module).le_pserver = ! register_list_destructors(oci8_detach, NULL); ! OCI8_GLOBAL(php3_oci8_module).le_session = ! register_list_destructors(oci8_close, NULL); ! ! OCI8_GLOBAL(php3_oci8_module).le_psession = ! register_list_destructors(oci8_close, NULL); ! if (cfg_get_long("oci8.debug_mode", &OCI8_GLOBAL(php3_oci8_module).debug_mode) == FAILURE) { *************** *** 565,595 **** } /* }}} */ - /* {{{ 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 --- 576,581 ---- *************** *** 697,702 **** --- 683,714 ---- /************************* INTERNAL FUNCTIONS *************************/ + /* {{{ oci8_debugcol() */ + + static void oci8_debugcol(oci8_out_column *column,const char *format,...) + { + OCI8_TLS_VARS; + + if (OCI8_GLOBAL(php3_oci8_module).debug_mode) { + char buffer[1024]; + char colbuffer[1024]; + va_list args; + + va_start(args, format); + vsnprintf(buffer, sizeof(buffer)-1, format, args); + va_end(args); + buffer[sizeof(buffer)-1] = '\0'; + + sprintf(colbuffer,"name=%s,type=%d,size4=%ld,size2=%d,storage_size4=%ld,indicator=%d,retcode=%d,rlen=%ld", + column->name,column->type,column->size4,column->size2,column->storage_size4,column->indicator,column->retcode,column->rlen); + + if (php3_header()) { + php3_printf("OCIDebug:%s - %s<br>\n",buffer,colbuffer); + } + } + } + + /* }}} */ /* {{{ oci8_debug() */ static void oci8_debug(const char *format,...) *************** *** 869,880 **** } else { switch (column->retcode) { case 1406: /* ORA-01406 XXX truncated value */ ! /* this seems to be a BUG in oracle */ ! oci8_debug("%s: truncated column %s indicator = %d", func,column->name,column->indicator); size = column->indicator - 1; /* when value is truncated indicator contains the lenght */ break; case 0: /* intact value */ size = column->rlen; break; --- 881,895 ---- } else { switch (column->retcode) { case 1406: /* ORA-01406 XXX truncated value */ ! /* this seems to be a BUG in oracle with 1-digit numbers */ ! /* ! oci8_debugcol(column,"truncated"); ! */ size = column->indicator - 1; /* when value is truncated indicator contains the lenght */ break; case 0: /* intact value */ + oci8_debugcol(column,"OK"); size = column->rlen; break; *************** *** 1139,1145 **** default: define_type = SQLT_STR; if ((outcol->type == SQLT_DAT) || (outcol->type == SQLT_NUM)) { ! outcol->storage_size4 = 127; /* XXX this should fit "most" NLS date-formats and Numbers */ } else { outcol->storage_size4++; /* add one for string terminator */ } --- 1154,1160 ---- default: define_type = SQLT_STR; if ((outcol->type == SQLT_DAT) || (outcol->type == SQLT_NUM)) { ! outcol->storage_size4 = 256; /* XXX this should fit "most" NLS date-formats and Numbers */ } else { outcol->storage_size4++; /* add one for string terminator */ } *************** *** 1158,1164 **** outcol->storage_size4, /* IN The size of each valuep buffer in bytes */ define_type, /* IN The data type */ (dvoid *)&outcol->indicator, /* IN pointer to an indicator variable or arr */ ! (ub2 *)&outcol->size2, /* IN/OUT Pointer to array of length of data fetched */ (ub2 *)&outcol->retcode, /* OUT Pointer to array of column-level return codes */ OCI_DYNAMIC_FETCH)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */ if (error) { --- 1173,1179 ---- outcol->storage_size4, /* IN The size of each valuep buffer in bytes */ define_type, /* IN The data type */ (dvoid *)&outcol->indicator, /* IN pointer to an indicator variable or arr */ ! (ub2 *)&outcol->size2, /* IN/OUT Pointer to array of length of data fetched */ (ub2 *)&outcol->retcode, /* OUT Pointer to array of column-level return codes */ OCI_DYNAMIC_FETCH)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */ if (error) { *************** *** 1220,1226 **** pval->value.str.len = 0; } else { if (column->retcode == 1406) { /*XXX ORA-01406 truncated value */ ! oci8_debug("OCIFetch: truncated column %s indicator = %d", func,column->name,column->indicator); pval->value.str.len = column->indicator - 1; /* when value is truncated indicator contains the lenght */ } else { pval->value.str.len = column->rlen; --- 1235,1244 ---- pval->value.str.len = 0; } else { if (column->retcode == 1406) { /*XXX ORA-01406 truncated value */ ! /* this seems to be a BUG in oracle with 1-digit numbers */ ! /* ! oci8_debugcol(column,"truncated"); ! */ pval->value.str.len = column->indicator - 1; /* when value is truncated indicator contains the lenght */ } else { pval->value.str.len = column->rlen; *************** *** 1517,1615 **** /* {{{ 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 CLEANUP; } ! 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 CLEANUP; } ! 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 CLEANUP; } ! if (OCISessionBegin(session->pServiceContext, ! session->pError, ! session->pSession, ! (ub4) OCI_CRED_RDBMS, ! (ub4) OCI_DEFAULT)) { ! oci8_error(session->pError, "OCISessionBegin", error); goto CLEANUP; } ! 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 CLEANUP; } ! session->id = php3_list_insert(session, OCI8_GLOBAL(php3_oci8_module).le_session); return session; CLEANUP: efree(session); return 0; } /* }}} */ /* {{{ oci8_attach() */ static oci8_server *oci8_attach(char *dbname,int persistent,HashTable *list, HashTable *plist) --- 1535,1672 ---- /* {{{ oci8_open() */ ! static oci8_session *oci8_open(oci8_server* server,char *username,char *password,int persistent,HashTable *list, HashTable *plist) { sword error; oci8_session *session; + OCISvcCtx *svchp = 0; OCI8_TLS_VARS; ! if (persistent) { ! session = calloc(1,sizeof(oci8_session)); ! } else { ! session = ecalloc(1,sizeof(oci8_session)); ! } if (! session) { ! goto CLEANUP; } + session->persistent = persistent; session->server = server; ! /* allocate temporary Service Context */ ! error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, ! (dvoid **)&svchp, ! OCI_HTYPE_SVCCTX, ! 0, ! NULL); ! if (error != OCI_SUCCESS) { ! oci8_error(server->pError, "oci8_open: OCIHandleAlloc OCI_HTYPE_SVCCTX", error); ! goto CLEANUP; ! } ! /* allocate private error-handle */ ! error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, ! (dvoid **)&session->pError, ! OCI_HTYPE_ERROR, ! 0, ! NULL); ! if (error != OCI_SUCCESS) { ! oci8_error(server->pError, "oci8_open: OCIHandleAlloc OCI_HTYPE_ERROR", error); ! goto CLEANUP; ! } ! /* allocate private session-handle */ ! error = OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, ! (dvoid **)&session->pSession, ! OCI_HTYPE_SESSION, ! 0, ! NULL); ! if (error != OCI_SUCCESS) { ! oci8_error(server->pError, "oci8_open: OCIHandleAlloc OCI_HTYPE_SESSION", error); goto CLEANUP; } ! /* Set the server handle in service handle */ ! error = OCIAttrSet(svchp, ! OCI_HTYPE_SVCCTX, ! server->pServer, ! 0, ! OCI_ATTR_SERVER, ! session->pError); ! if (error != OCI_SUCCESS) { ! oci8_error(session->pError, "oci8_open: OCIAttrSet OCI_ATTR_SERVER", error); goto CLEANUP; } ! /* set the username in user handle */ ! error = OCIAttrSet((dvoid *) session->pSession, ! (ub4) OCI_HTYPE_SESSION, ! (dvoid *) username, ! (ub4) strlen(username), ! (ub4) OCI_ATTR_USERNAME, ! session->pError); ! if (error != OCI_SUCCESS) { ! oci8_error(session->pError, "OCIAttrSet OCI_ATTR_USERNAME", error); goto CLEANUP; } ! /* set the password in user handle */ ! error = OCIAttrSet((dvoid *) session->pSession, ! (ub4) OCI_HTYPE_SESSION, ! (dvoid *) password, ! (ub4) strlen(password), ! (ub4) OCI_ATTR_PASSWORD, ! session->pError); ! if (error != OCI_SUCCESS) { ! oci8_error(session->pError, "OCIAttrSet OCI_ATTR_PASSWORD", error); goto CLEANUP; } ! error = OCISessionBegin(svchp, ! session->pError, ! session->pSession, ! (ub4) OCI_CRED_RDBMS, ! (ub4) OCI_DEFAULT); ! if (error != OCI_SUCCESS) { ! oci8_error(session->pError, "OCISessionBegin", error); goto CLEANUP; } ! /* Free Temporary Service Context */ ! OCIHandleFree((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX); + if (persistent) { + session->id = php3_list_insert(session, OCI8_GLOBAL(php3_oci8_module).le_psession); + } else { + session->id = php3_list_insert(session, OCI8_GLOBAL(php3_oci8_module).le_session); + } + return session; CLEANUP: + if (session) { + oci8_close(session); + } + efree(session); return 0; } /* }}} */ + /* {{{ oci8_close() + */ + + static int oci8_close(oci8_session *session) + { + oci8_debug("oci8_close"); + + return 0; + } + + /* }}} */ /* {{{ oci8_attach() */ static oci8_server *oci8_attach(char *dbname,int persistent,HashTable *list, HashTable *plist) *************** *** 1626,1631 **** --- 1683,1692 ---- server = ecalloc(1,sizeof(oci8_server)); } + if (! server) { + goto CLEANUP; + } + server->persistent = persistent; OCIHandleAlloc(OCI8_GLOBAL(php3_oci8_module).pEnv, *************** *** 1648,1654 **** if (error) { oci8_error(server->pError, "oci8_attach", error); ! return 0; } if (persistent) { --- 1709,1715 ---- if (error) { oci8_error(server->pError, "oci8_attach", error); ! goto CLEANUP; } if (persistent) { *************** *** 1660,1665 **** --- 1721,1733 ---- oci8_debug("oci8_attach"); return server; + + CLEANUP: + if (server) { + oci8_detach(server); + } + + return 0; } /* }}} */ *************** *** 1668,1673 **** --- 1736,1743 ---- static int oci8_detach(oci8_server *server) { + oci8_debug("oci8_detach"); + return 0; } *************** *** 2912,2917 **** --- 2982,2988 ---- session = oci8_open(server, userParam->value.str.val, passParam->value.str.val, + 0, list, plist); Index: php3/functions/php3_oci8.h diff -c php3/functions/php3_oci8.h:1.35 php3/functions/php3_oci8.h:1.36 *** php3/functions/php3_oci8.h:1.35 Tue Mar 30 05:20:15 1999 --- php3/functions/php3_oci8.h Wed Apr 7 08:10:15 1999 *************** *** 51,56 **** --- 51,63 ---- # include <oci.h> + typedef enum { + OCI8_SERVER=1, + OCI8_SESSION, + OCI8_SERVICE, + OCI8_STATEMENT + } php3_oci8_type; + typedef struct { int id; int persistent; *************** *** 60,73 **** typedef struct { int id; oci8_server *server; OCIError *pError; - OCISvcCtx *pServiceContext; OCISession *pSession; } oci8_session; typedef struct { int id; int persistent; OCIEnv *pEnv; OCIServer *pServer; --- 67,88 ---- typedef struct { int id; + int persistent; oci8_server *server; OCIError *pError; OCISession *pSession; } oci8_session; typedef struct { int id; + oci8_server *server; + oci8_session *session; + OCIError *pError; + OCISvcCtx *pService; + } oci8_service; + + typedef struct { + int id; int persistent; OCIEnv *pEnv; OCIServer *pServer; *************** *** 134,140 **** --- 149,168 ---- oci8_define *define; } oci8_out_column; + typedef union { + oci8_server server; + oci8_session session; + oci8_service service; + } oci8_structs; + + typedef struct { + php3_oci8_type type; + int id; + oci8_structs s; + } oci8_struct; + typedef struct { + OCIError *pError; char *default_username; char *default_password; char *default_dbname; *************** *** 155,160 **** --- 183,189 ---- int le_pserver; int le_session; + int le_psession; OCIEnv *pEnv; } oci8_module; -- 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 (#4971) next »