Date: 03/10/99
- Next message: nick <email protected>: "[PHP-DEV] Bug #1217: Printing a 2-D Array"
- Previous message: alex: "[PHP-DEV] please urgent: NT-PHP3 DNS function doesnt work ?"
- Next in thread: steinm: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wednesday March 10, 1999 @ 17:08
Author: thies
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv6018
Modified Files:
oci8.c php3_oci8.h
Log Message:
persistent connections (DON'T WORK YET!!!) - my family requires my attention;-)
Index: php3/functions/oci8.c
diff -c php3/functions/oci8.c:1.67 php3/functions/oci8.c:1.68
*** php3/functions/oci8.c:1.67 Tue Mar 9 11:27:15 1999
--- php3/functions/oci8.c Wed Mar 10 17:08:23 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.67 1999/03/09 16:27:15 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.68 1999/03/10 22:08:23 thies Exp $ */
/* TODO list:
*
***************
*** 75,80 ****
--- 75,82 ----
#if HAVE_OCI8
+ #define SAFE_STRING(s) ((s)?(s):"")
+
#include "php3_list.h"
#if !(WIN32|WINNT)
# include "build-defs.h"
***************
*** 146,152 ****
--- 148,156 ----
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);
***************
*** 158,163 ****
--- 162,168 ----
static int oci8_execute(oci8_statement *, char *,ub4 mode);
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);
/* bind callback functions */
static sb4 oci8_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **);
***************
*** 165,170 ****
--- 170,176 ----
/* define callback function */
static sb4 oci8_define_callback(dvoid *, OCIDefine *, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **);
+
/* }}} */
/* {{{ extension function prototypes */
***************
*** 182,187 ****
--- 188,194 ----
void php3_oci8_internaldebug(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logoff(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci8_plogon(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_error(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_freedesc(INTERNAL_FUNCTION_PARAMETERS);
void php3_oci8_savedesc(INTERNAL_FUNCTION_PARAMETERS);
***************
*** 230,235 ****
--- 237,243 ----
{"ocirowcount", php3_oci8_rowcount, NULL},
{"ocilogoff", php3_oci8_logoff, NULL},
{"ocilogon", php3_oci8_logon, NULL},
+ {"ociplogon", php3_oci8_plogon, NULL},
{"ocierror", php3_oci8_error, NULL},
{"ocifreedescriptor",php3_oci8_freedesc, NULL},
{"ocisavedesc", php3_oci8_savedesc, NULL},
***************
*** 298,303 ****
--- 306,314 ----
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_pconn, NULL);
+
OCI8_GLOBAL(php3_oci8_module).le_stmt =
register_list_destructors(oci8_free_stmt, NULL);
***************
*** 521,538 ****
/* }}} */
/* }}} */
! /* {{{ oci8_close_conn() */
static void
! oci8_close_conn(oci8_connection *connection)
{
OCI8_TLS_VARS;
! oci8_debug("oci8_close_conn: id=%d",connection->id);
_php3_hash_destroy(connection->descriptors);
- efree(connection->descriptors);
connection->open = 0;
oci8_error(connection->pError,"OCISessionEnd",
--- 532,554 ----
/* }}} */
/* }}} */
! /* {{{ 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);
_php3_hash_destroy(connection->descriptors);
+ if (persistent) {
+ free(connection->descriptors);
+ } else {
+ efree(connection->descriptors);
+ }
+
connection->open = 0;
oci8_error(connection->pError,"OCISessionEnd",
***************
*** 554,563 ****
}
OCI8_GLOBAL(php3_oci8_module).num_links--;
! efree(connection);
}
/* }}} */
/* {{{ oci8_error() */
static ub4
--- 570,602 ----
}
OCI8_GLOBAL(php3_oci8_module).num_links--;
!
! if (persistent) {
! free(connection);
! } else {
! efree(connection);
! }
}
/* }}} */
+ /* {{{ 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
***************
*** 1400,1406 ****
--- 1439,1638 ----
}
/* }}} */
+ /* {{{ 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;
+ pval *userParam, *passParam, *dbParam;
+ ub4 username_len, password_len, dbname_len;
+ oci8_connection *connection;
+ sword error;
+ char *hashed_details;
+ int hashed_details_length;
+ OCI8_TLS_VARS;
+
+ if (getParameters(ht, 3, &userParam, &passParam, &dbParam) == SUCCESS) {
+ convert_to_string(userParam);
+ convert_to_string(passParam);
+ convert_to_string(dbParam);
+ username = userParam->value.str.val;
+ password = passParam->value.str.val;
+ dbname = dbParam->value.str.val;
+ dbname_len = dbParam->value.str.len;
+ } else if (getParameters(ht, 2, &userParam, &passParam) == SUCCESS) {
+ convert_to_string(userParam);
+ convert_to_string(passParam);
+ username = userParam->value.str.val;
+ password = passParam->value.str.val;
+ dbname = (text *)NULL;
+ dbname_len = 0;
+ } else {
+ WRONG_PARAM_COUNT;
+ }
+
+ hashed_details_length = sizeof("oci8___")-1 +
+ strlen(SAFE_STRING((char *)username))+
+ strlen(SAFE_STRING((char *)password))+
+ strlen(SAFE_STRING((char *)dbname));
+
+ hashed_details = (char *) emalloc(hashed_details_length+1);
+ sprintf(hashed_details,"oci8_%s_%s_%s",
+ SAFE_STRING((char *)username),
+ SAFE_STRING((char *)password),
+ SAFE_STRING((char *)dbname));
+
+ if (!OCI8_GLOBAL(php3_oci8_module).allow_persistent) {
+ persistent=0;
+ }
+
+ if (persistent) {
+ list_entry *le;
+
+ if (_php3_hash_find(plist, hashed_details, hashed_details_length+1, (void **) &le)==SUCCESS) { /* got you!!! */
+ if (le->type != OCI8_GLOBAL(php3_oci8_module).le_pconn) {
+ efree(hashed_details);
+ RETURN_FALSE;
+ }
+
+ /* XXX we should do something like an ping here to check for dead connections!!! */
+
+ connection = (oci8_connection *) le->ptr;
+
+ oci8_debug("oci8_do_connect: persistent connection id=%d",connection->id);
+
+ RETVAL_LONG(connection->id);
+ efree(hashed_details);
+ return;
+ } else {
+ if (OCI8_GLOBAL(php3_oci8_module).max_links!=-1 && OCI8_GLOBAL(php3_oci8_module).num_links>=OCI8_GLOBAL(php3_oci8_module).max_links) {
+ php3_error(E_WARNING,"OCI8: Too many open links (%d)",OCI8_GLOBAL(php3_oci8_module).num_links);
+ efree(hashed_details);
+ RETURN_FALSE;
+ }
+ if (OCI8_GLOBAL(php3_oci8_module).max_persistent!=-1 && OCI8_GLOBAL(php3_oci8_module).num_persistent>=OCI8_GLOBAL(php3_oci8_module).max_persistent) {
+ php3_error(E_WARNING,"OCI8: Too many open persistent links (%d)",OCI8_GLOBAL(php3_oci8_module).num_persistent);
+ efree(hashed_details);
+ RETURN_FALSE;
+ }
+
+ /* fall thru an go ahead */
+ }
+ }
+
+ username_len = userParam->value.str.len;
+ password_len = passParam->value.str.len;
+
+ if (persistent) {
+ connection = (oci8_connection *) calloc(1,sizeof(oci8_connection));
+ } else {
+ connection = (oci8_connection *) ecalloc(1,sizeof(oci8_connection));
+ }
+
+ if (connection == NULL) {
+ RETURN_OUT_OF_MEMORY;
+ }
+
+ /* Set up the Oracle environment. */
+
+ /* 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);
+ 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;
+ }
+
+ connection->open = 1;
+
+ if (persistent) {
+ connection->descriptors = malloc(sizeof(HashTable));
+ } else {
+ 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 */
+ if (persistent) {
+ list_entry new_le;
+
+ new_le.type = OCI8_GLOBAL(php3_oci8_module).le_pconn;
+ new_le.ptr = connection;
+
+ if (_php3_hash_update(plist, hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(list_entry), NULL)==FAILURE) {
+ /* XXX close connection here */
+ efree(hashed_details);
+ RETURN_FALSE;
+ }
+ OCI8_GLOBAL(php3_oci8_module).num_persistent++;
+
+ connection->id = php3_list_insert(connection, OCI8_GLOBAL(php3_oci8_module).le_pconn);
+ } else {
+ connection->id = php3_list_insert(connection, OCI8_GLOBAL(php3_oci8_module).le_conn);
+ }
+
+ oci8_debug("OCILogon: new connection id=%d",connection->id);
+
+ efree(hashed_details);
+
+ OCI8_GLOBAL(php3_oci8_module).num_links++;
+
+ RETVAL_LONG(connection->id);
+ }
+
+ /* }}} */
+
/************************* EXTENSION FUNCTIONS *************************/
/* {{{ proto int OCIDefineByName(int stmt, string name, mixed &var [,int type])
***************
*** 2293,2301 ****
convert_to_long(arg);
index = arg->value.lval;
connection = (oci8_connection *)php3_list_find(index, &index_t);
! if (!connection || !OCI8_CONN_TYPE(index_t)) {
RETURN_FALSE;
}
if (php3_list_delete(index) == SUCCESS) {
RETVAL_TRUE;
} else {
--- 2525,2541 ----
convert_to_long(arg);
index = arg->value.lval;
connection = (oci8_connection *)php3_list_find(index, &index_t);
!
! if (!connection) {
! oci8_debug("OCILogoff: connection == NULL.");
RETURN_FALSE;
}
+
+ if (! OCI8_CONN_TYPE(index_t) && ! OCI8_PCONN_TYPE(index_t)) {
+ oci8_debug("OCILogoff: connection not found...");
+ RETURN_FALSE;
+ }
+
if (php3_list_delete(index) == SUCCESS) {
RETVAL_TRUE;
} else {
***************
*** 2315,2431 ****
*/
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS)
{
! text *username, *password, *dbname;
! pval *userParam, *passParam, *dbParam;
! ub4 username_len, password_len, dbname_len;
! oci8_connection *connection;
! sword error;
! OCI8_TLS_VARS;
!
! if (getParameters(ht, 3, &userParam, &passParam, &dbParam) == SUCCESS) {
! convert_to_string(userParam);
! convert_to_string(passParam);
! convert_to_string(dbParam);
! username = userParam->value.str.val;
! password = passParam->value.str.val;
! dbname = dbParam->value.str.val;
! dbname_len = dbParam->value.str.len;
! } else if (getParameters(ht, 2, &userParam, &passParam) == SUCCESS) {
! convert_to_string(userParam);
! convert_to_string(passParam);
! username = userParam->value.str.val;
! password = passParam->value.str.val;
! dbname = (text *)NULL;
! dbname_len = 0;
! } else {
! WRONG_PARAM_COUNT;
! }
! username_len = userParam->value.str.len;
! password_len = passParam->value.str.len;
!
! if (OCI8_GLOBAL(php3_oci8_module).max_links != -1 &&
! OCI8_GLOBAL(php3_oci8_module).num_links >=
! OCI8_GLOBAL(php3_oci8_module).max_links) {
! php3_error(E_WARNING, "OCILogon: Too many open links (%d)",
! OCI8_GLOBAL(php3_oci8_module).num_links);
! RETURN_FALSE;
! }
!
! connection = (oci8_connection *)ecalloc(1,sizeof(oci8_connection));
!
! if (connection == NULL) {
! RETURN_OUT_OF_MEMORY;
! }
!
! /* Set up the Oracle environment. */
!
! /* 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);
! 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;
! }
!
! connection->open = 1;
!
! /* non persistent, simply add to list */
! connection->id = php3_list_insert(connection, OCI8_GLOBAL(php3_oci8_module).le_conn);
!
!
! 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_debug("OCILogon: new connection id=%d",connection->id);
! OCI8_GLOBAL(php3_oci8_module).num_links++;
! RETVAL_LONG(connection->id);
}
/* }}} */
--- 2555,2575 ----
*/
void php3_oci8_logon(INTERNAL_FUNCTION_PARAMETERS)
{
! oci8_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0);
! }
! /* }}} */
! /* {{{ proto int OCIPLogon(string user, string pass[, string db])
! Connect to an Oracle database and log on. returns a new session.
! */
! /* Connects to an Oracle 8 database and logs on. If the
! * optional third parameter is not specified, PHP uses the environment
! * variable ORACLE_SID to determine which database to connect to.
! */
! void php3_oci8_plogon(INTERNAL_FUNCTION_PARAMETERS)
! {
! oci8_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);
}
/* }}} */
Index: php3/functions/php3_oci8.h
diff -c php3/functions/php3_oci8.h:1.32 php3/functions/php3_oci8.h:1.33
*** php3/functions/php3_oci8.h:1.32 Mon Feb 22 07:21:37 1999
--- php3/functions/php3_oci8.h Wed Mar 10 17:08:23 1999
***************
*** 135,140 ****
--- 135,141 ----
long num_persistent;
long num_links;
int le_conn;
+ int le_pconn;
int le_stmt;
} oci8_module;
***************
*** 146,151 ****
--- 147,153 ----
/* this one has to be changed to include persistent connections as well */
# 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)
# define OCI8_DESCR_TYPE(x) ((x)==OCI8_GLOBAL(php3_oci8_module).le_descr)
-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>
- Next message: nick <email protected>: "[PHP-DEV] Bug #1217: Printing a 2-D Array"
- Previous message: alex: "[PHP-DEV] please urgent: NT-PHP3 DNS function doesnt work ?"
- Next in thread: steinm: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

