CVS update: php3/functions
| From: | ssb | Date: | Wed, 09 Sep 1998 12:38:09 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-885@lists.php.net to get a copy of this message | ||
Date: Wednesday September 9, 1998 @ 8:38
Author: ssb
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv11020/functions
Modified Files:
oci8.c oracle.c php3_oci8.h
Log Message:
more OCI8 work
Index: php3/functions/oci8.c
diff -c php3/functions/oci8.c:1.2 php3/functions/oci8.c:1.3
*** php3/functions/oci8.c:1.2 Wed Sep 9 05:06:54 1998
--- php3/functions/oci8.c Wed Sep 9 08:38:08 1998
***************
*** 24,67 ****
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Stig Sæther Bakken <ssb@guardian.no> |
! | |
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.2 1998/09/09 09:06:54 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
! #if HAVE_ORACLE /* XXX should be replaced by HAVE_OCI8 */
! #include "php3_list.h"
! #include "build-defs.h"
! #include "snprintf.h"
! /* startup and shutdown function prototypes */
int php3_minit_oci8(INIT_FUNC_ARGS);
int php3_rinit_oci8(INIT_FUNC_ARGS);
int php3_mshutdown_oci8(void);
int php3_rshutdown_oci8(void);
void php3_info_oci8(void);
! /* extension function prototypes */
void php3_oci_logon(INTERNAL_FUNCTION_PARAMETERS);
! /* XXX FIXME global variables that should be moved into a
! * per-request structure once we've decided on how.
! */
! static HashTable *resource_list;
! static HashTable *resource_plist;
function_entry oci8_functions[] = {
! {"OCILogon", php3_oci_logon, NULL},
{NULL, NULL, NULL}
};
! php3_module_entry oci8_module_entry[] = {
! "Oracle 8", /* extension name */
oci8_functions, /* extension function list */
php3_minit_oci8, /* extension-wide startup function */
php3_mshutdown_oci8, /* extension-wide shutdown function */
--- 24,140 ----
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Stig Sæther Bakken <ssb@guardian.no> |
! | Mitch Golden <mgolden@interport.net> |
! | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
! | Andreas Karajannis <Andreas.Karajannis@gmd.de> |
+----------------------------------------------------------------------+
*/
! /* $Id: oci8.c,v 1.3 1998/09/09 12:38:08 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
+ #include "php3_oci8.h"
! #if HAVE_OCI8
! # include "php3_list.h"
! # include "build-defs.h"
! # include "snprintf.h"
! # include "head.h"
! /* {{{ thread safety stuff */
!
! # ifdef THREAD_SAFE
! # define OCI8_GLOBAL(a) oci8_globals->a
! # define OCI8_TLS_VARS \
! oci8_global_struct *oci8_globals = TlsGetValue(OCI8Tls);
!
! void *oci8_mutex;
! DWORD OCI8Tls;
! static int numthreads=0;
!
! typedef struct oci8_global_struct {
! oci8_module php3_oci8_module;
! } oci8_global_struct;
!
! # else /* !defined(THREAD_SAFE) */
! # define OCI8_GLOBAL(a) a
! # define OCI8_TLS_VARS
!
! oci8_module php3_oci8_module;
!
! # endif /* defined(THREAD_SAFE) */
!
! /* }}} */
! /* {{{ dynamically loadable module stuff */
!
! # if COMPILE_DL
!
! php3_module_entry *get_module() { return &oci8_module_entry; };
!
! # if (WIN32|WINNT) && defined(THREAD_SAFE)
!
! /* NOTE: You should have an oci8.def file where you export DllMain */
! BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call,
! LPVOID lpReserved)
! {
! switch (ul_reason_for_call) {
! case DLL_PROCESS_ATTACH:
! if ((OCI8Tls = TlsAlloc()) == 0xFFFFFFFF){
! return 0;
! }
! break;
! case DLL_THREAD_ATTACH:
! break;
! case DLL_THREAD_DETACH:
! break;
! case DLL_PROCESS_DETACH:
! if (!TlsFree(OCI8Tls)) {
! return 0;
! }
! break;
! }
! return 1;
! }
!
! # endif /* thread safe on Windows */
! # endif /* COMPILE_DL */
!
! /* }}} */
! /* {{{ startup and shutdown function prototypes */
!
int php3_minit_oci8(INIT_FUNC_ARGS);
int php3_rinit_oci8(INIT_FUNC_ARGS);
int php3_mshutdown_oci8(void);
int php3_rshutdown_oci8(void);
void php3_info_oci8(void);
! static ub4 php3i_oci8_error(OCIError *err_p, char *what, sword status);
! static int php3i_oci_ping(oci8_connection *conn);
! static void OCI8_DEBUG(const char *format,...);
! static void php3i_oci_close_conn(oci8_connection *connection);
! static void php3i_oci_close_pconn(oci8_connection *connection);
!
!
! /* }}} */
! /* {{{ extension function prototypes */
!
void php3_oci_logon(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci_debug(INTERNAL_FUNCTION_PARAMETERS);
! /* }}} */
! /* {{{ extension definition structures */
function_entry oci8_functions[] = {
! {"ocilogon", php3_oci_logon, NULL},
! {"ociplogon", php3_oci_plogon, NULL},
! {"ocidebug", php3_oci_debug, NULL},
{NULL, NULL, NULL}
};
! php3_module_entry oci8_module_entry = {
! "OCI8", /* extension name */
oci8_functions, /* extension function list */
php3_minit_oci8, /* extension-wide startup function */
php3_mshutdown_oci8, /* extension-wide shutdown function */
***************
*** 70,92 ****
php3_info_oci8, /* information function */
STANDARD_MODULE_PROPERTIES
};
-
! /* startup and shutdown functions */
int php3_minit_oci8(INIT_FUNC_ARGS)
{
! return SUCCESS;
}
int php3_rinit_oci8(INIT_FUNC_ARGS)
{
return SUCCESS;
}
int php3_mshutdown_oci8()
{
! return SUCCESS;
}
int php3_rshutdown_oci8()
--- 143,242 ----
php3_info_oci8, /* information function */
STANDARD_MODULE_PROPERTIES
};
! /* }}} */
! /* {{{ startup, shutdown and info functions */
int php3_minit_oci8(INIT_FUNC_ARGS)
{
! #ifdef THREAD_SAFE
! oci8_global_struct *oci8_globals;
! # if !COMPILE_DL
! # if WIN32|WINNT
! CREATE_MUTEX(oci8_mutex,"OCI8_TLS");
! # endif
! SET_MUTEX(oci8_mutex);
! numthreads++;
! if (numthreads == 1) {
! if ((OCI8Tls = TlsAlloc()) == 0xFFFFFFFF){
! FREE_MUTEX(oci8_mutex);
! return 0;
! }
! }
! FREE_MUTEX(oci8_mutex);
! # endif /* !COMPILE_DL */
! oci8_globals =
! (oci8_global_struct *) LocalAlloc(LPTR, sizeof(oci8_global_struct));
! TlsSetValue(OCI8Tls, (void *) oci8_globals);
! #endif /* THREAD_SAFE */
!
! if (cfg_get_long("oci8.allow_persistent",
! &OCI8_GLOBAL(php3_oci8_module).allow_persistent)
! == FAILURE) {
! OCI8_GLOBAL(php3_oci8_module).allow_persistent = -1;
! }
! if (cfg_get_long("oci8.max_persistent",
! &OCI8_GLOBAL(php3_oci8_module).max_persistent)
! == FAILURE) {
! OCI8_GLOBAL(php3_oci8_module).max_persistent = -1;
! }
! if (cfg_get_long("oci8.max_links",
! &OCI8_GLOBAL(php3_oci8_module).max_links)
! == FAILURE) {
! OCI8_GLOBAL(php3_oci8_module).max_links = -1;
! }
!
! OCI8_GLOBAL(php3_oci8_module).num_persistent = 0;
!
! OCI8_GLOBAL(php3_oci8_module).le_conn =
! register_list_destructors(php3i_oci_close_conn, NULL);
! OCI8_GLOBAL(php3_oci8_module).le_pconn =
! register_list_destructors(php3i_oci_close_pconn, NULL);
! /*
! OCI8_GLOBAL(php3_oci8_module).le_conn =
! register_list_destructors(php3i_oci_close_conn, NULL);
! */
!
! /*
! REGISTER_LONG_CONSTANT("OCI_BIND_INOUT", 0, CONST_CS | CONST_PERSISTENT);
! REGISTER_LONG_CONSTANT("OCI_BIND_IN", 1, CONST_CS | CONST_PERSISTENT);
! REGISTER_LONG_CONSTANT("OCI_BIND_OUT", 2, CONST_CS | CONST_PERSISTENT);
! */
!
! return SUCCESS;
}
int php3_rinit_oci8(INIT_FUNC_ARGS)
{
+ OCI8_TLS_VARS;
+
+ OCI8_GLOBAL(php3_oci8_module).num_links =
+ OCI8_GLOBAL(php3_oci8_module).num_persistent;
+
return SUCCESS;
}
int php3_mshutdown_oci8()
{
! #ifdef THREAD_SAFE
! oci8_global_struct *oci8_globals;
! oci8_globals = TlsGetValue(OCI8Tls);
! if (oci8_globals != 0) {
! LocalFree((HLOCAL) oci8_globals);
! }
! #if !COMPILE_DL
! SET_MUTEX(oci8_mutex);
! numthreads--;
! if (!numthreads) {
! if (!TlsFree(OCI8Tls)) {
! FREE_MUTEX(oci8_mutex);
! return 0;
! }
! }
! FREE_MUTEX(oci8_mutex);
! #endif
! #endif
! return SUCCESS;
}
int php3_rshutdown_oci8()
***************
*** 94,114 ****
return SUCCESS;
}
! /* info function */
! void php3_info_oci8()
{
}
! /* internal extension functions */
static ub4
php3i_oci8_error(OCIError *err_p, char *what, sword status)
{
text errbuf[512];
- ub4 buflen;
ub4 errcode;
switch (status) {
--- 244,318 ----
return SUCCESS;
}
+ void php3_info_oci8()
+ {
+ php3_printf("Oracle version: %s<br>\n"
+ "Compile-time ORACLE_HOME: %s<br>\n"
+ "Libraries used: %s",
+ PHP_ORACLE_VERSION, PHP_ORACLE_HOME, PHP_ORACLE_LIBS);
+ }
! /* }}} */
! /* {{{ extension-internal functions */
! #if 0
! static int php3i_oci_cleanup_cursors(list_entry *le)
{
+ OCI8_TLS_VARS;
+
+ if (le->type == OCI8_GLOBAL(php3_oci8_module).le_cursor) {
+ oraCursor *curs = ((oraCursor *)le->ptr);
+ oraConnection *conn = curs->conn_ptr;
+
+ if ((!(conn->open)) && (curs->open > 0)){
+ oclose(&curs->cda);
+ curs->open = 0;
+ }
+ }
+ return 0;
}
+ #endif
! static void php3i_oci_close_conn(oci8_connection *connection)
! {
! OCI8_TLS_VARS;
!
! connection->open = 0;
! #if 0
! _php3_hash_apply(OCI8_GLOBAL(php3_oci8_module).list,
! (int (*)(void *))php3i_oci_cleanup_cursors);
! #endif
! php3i_oci8_error(connection->pError, "OCILogoff",
! OCILogoff(connection->pServiceContext,
! connection->pError));
! OCI8_GLOBAL(php3_oci8_module).num_links--;
! efree(connection);
! }
!
!
! static void php3i_oci_close_pconn(oci8_connection *connection)
! {
! OCI8_TLS_VARS;
!
! connection->open = 0;
! #if 0
! _php3_hash_apply(OCI8_GLOBAL(php3_oci8_module).plist,
! (int (*)(void *))php3i_oci_cleanup_cursors);
! #endif
! php3i_oci8_error(connection->pError, "OCILogoff",
! OCILogoff(connection->pServiceContext,
! connection->pError));
! OCI8_GLOBAL(php3_oci8_module).num_links--;
! OCI8_GLOBAL(php3_oci8_module).num_persistent--;
! free(connection);
! }
+
static ub4
php3i_oci8_error(OCIError *err_p, char *what, sword status)
{
text errbuf[512];
ub4 errcode;
switch (status) {
***************
*** 124,133 ****
php3_error(E_WARNING, "%s: OCI_NO_DATA", what);
break;
case OCI_ERROR:
! OCIErrorGet(err_p, (ub4)1, NULL, &errcode,
! errbuf, (ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
php3_error(E_WARNING, "%s: %s", what, errbuf);
- exit(1);
break;
case OCI_INVALID_HANDLE:
php3_error(E_WARNING, "%s: OCI_INVALID_HANDLE", what);
--- 328,336 ----
php3_error(E_WARNING, "%s: OCI_NO_DATA", what);
break;
case OCI_ERROR:
! OCIErrorGet(err_p, (ub4)1, NULL, &errcode, errbuf,
! (ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
php3_error(E_WARNING, "%s: %s", what, errbuf);
break;
case OCI_INVALID_HANDLE:
php3_error(E_WARNING, "%s: OCI_INVALID_HANDLE", what);
***************
*** 152,160 ****
return 1;
}
! /* extension functions */
/* int OCILogon(string, string[, string])
*/
void php3_oci_logon(INTERNAL_FUNCTION_PARAMETERS)
--- 355,400 ----
return 1;
}
+
+ static void OCI8_DEBUG(const char *format,...)
+ {
+ OCI8_TLS_VARS;
! if (OCI8_GLOBAL(php3_oci8_module).debug_mode) {
! char buffer[1024];
! va_list args;
!
! va_start(args, format);
! vsnprintf(buffer, sizeof(buffer)-1, format, args);
! va_end(args);
! buffer[sizeof(buffer)-1] = '\0';
! if (php3_header()) {
! php3_printf("OCIDebug: %s<br>\n", buffer);
! }
! }
! }
+ /* }}} */
+
+ /************************* EXTENSION FUNCTIONS *************************/
+
+ /* {{{ OCIDebug() */
+
+ void php3_oci_debug(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *arg;
+
+ if (getParameters(ht, 1, &arg) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(arg);
+ OCI8_GLOBAL(php3_oci8_module).debug_mode = arg->value.lval;
+ }
+
+
+ /* }}} */
+ /* {{{ OCILogon() */
+
/* int OCILogon(string, string[, string])
*/
void php3_oci_logon(INTERNAL_FUNCTION_PARAMETERS)
***************
*** 181,245 ****
int hashed_len, len, id;
OCI8_TLS_VARS;
- OCI8_GLOBAL(php3_oci8_module).resource_list = list;
- OCI8_GLOBAL(php3_oci8_module).resource_plist = plist;
-
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 = userParam->value.str.val;
! dbname = userParam->value.str.val;
! dbname_len = userParam->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).allow_persistent) {
! persistent = 0;
}
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);
! RETURN_FALSE;
}
/* the user requested a persistent connection */
if (persistent &&
! 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);
! RETURN_FALSE;
}
len = username_len + password_len + 9;
if (dbname) {
! len += dbname_len + 1;
}
if ((hashed_details = emalloc(len)) == NULL) {
! RETURN_OUT_OF_MEMORY;
}
if (dbname) {
! hashed_len = _php3_sprintf(hashed_details, "oci8(%s,%s,%s)",
! username, password, dbname);
} else {
! hashed_len = _php3_sprintf(hashed_details, "oci8(%s,%s)",
! username, password);
}
/* try to find if we already have this link in our persistent list,
--- 421,482 ----
int hashed_len, len, id;
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).allow_persistent) {
! persistent = 0;
}
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);
! RETURN_FALSE;
}
/* the user requested a persistent connection */
if (persistent &&
! 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);
! RETURN_FALSE;
}
len = username_len + password_len + 9;
if (dbname) {
! len += dbname_len + 1;
}
if ((hashed_details = emalloc(len)) == NULL) {
! RETURN_OUT_OF_MEMORY;
}
if (dbname) {
! hashed_len = _php3_sprintf(hashed_details, "oci8(%s,%s,%s)",
! username, password, dbname);
} else {
! hashed_len = _php3_sprintf(hashed_details, "oci8(%s,%s)",
! username, password);
}
/* try to find if we already have this link in our persistent list,
***************
*** 247,365 ****
*/
if (_php3_hash_find(plist, hashed_details, hashed_len + 1,
! (void **) &index_ptr) == FAILURE) {
! /* the link is not in the persistent list */
! list_entry new_index_ptr;
!
! OCI8_DEBUG("Connection \"%s\" not found in plist.", hashed_details);
!
! if (persistent) {
! connection = (oci8_connection *)malloc(sizeof(oci8_connection));
! } else {
! connection = (oci8_connection *)emalloc(sizeof(oci8_connection));
! }
! if (connection == NULL) {
! efree(hashed_details);
! RETURN_OUT_OF_MEMORY;
! }
!
! /* Set up the Oracle environment. We can specify our own
! * malloc/realloc/free functions to OCIInitialize, but
! * we don't do that yet.
! */
! OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL);
! 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(connection->pEnv, connection->pError,
! &connection->pServiceContext,
! username, username_len,
! password, password_len,
! dbname, dbname_len);
! if (error) {
! efree(hashed_details);
! persistent ? free(connection) : efree(connection);
! OCI8_FAIL(connection, "OCILogon", error);
! }
!
! connection->open = 1;
! OCI8_DEBUG("\"%s\" created and connected.",
! hashed_details);
!
! if (persistent) {
! new_index_ptr.ptr = (void *) return_value->value.lval;
! new_index_ptr.type = le_index_ptr;
!
! if (_php3_hash_update(plist, hashed_details, hashed_len + 1,
! (void *) &new_index_ptr,
! sizeof(list_entry),NULL) == FAILURE) {
! php3i_oci8_error(connection->pError, "OCILogoff",
! OCILogoff(connection->pServiceContext,
! connection->pError));
! free(connection);
! efree(hashed_details);
! php3_error(E_WARNING, "OCILogon: can't update plist");
! RETURN_FALSE;
! }
! OCI8_GLOBAL(php3_oci8_module).num_persistent++;
!
! /* add the connection to the non-persistent list */
! return_value->value.lval =
! php3_list_insert(connection,
! OCI8_GLOBAL(php3_oci8_module).le_pconn);
! OCI8_DEBUG("\"%s\" inserted as le_pconn in list with id %s.",
! return_value->value.lval);
! } else {
! /* non persistent, simply add to list */
! return_value->value.lval =
! php3_list_insert(db_conn, OCI8_GLOBAL(php3_oci8_module).le_conn);
! OCI8_DEBUG("\"%s\" inserted as le_conn in list with id %s.",
! return_value->value.lval);
! }
!
! OCI8_GLOBAL(php3_oci8_module).num_links++;
!
! } else {
! /* the link is already in the persistent list */
! int type;
!
! if (index_ptr->type != le_index_ptr) {
! efree(hashed_details);
! php3_error(E_WARNING, "Oops, something went completly wrong");
! RETURN_FALSE;
! }
! id = (int) index_ptr->ptr;
! connection = (oci8_connection *)php3_plist_find(id, &type);
!
! if (connection && (type == OCI8_GLOBAL(php3_oci8_module).le_conn ||
! type == OCI8_GLOBAL(php3_oci8_module).le_pconn)) {
! if (!php3i_oci_ping(connection)) {
! /* if the connection was lost, try reconnecting */
error = OCILogon(connection->pEnv, connection->pError,
! &connection->pServiceContext,
! username, username_len,
! password, password_len,
! dbname, dbname_len);
if (error) {
! /* delete list entry for this connection */
! php3_list_delete(id);
! /* delete hashed plist entry for this dead connection */
! _php3_hash_del(plist, hashed_details, hashed_len);
! efree(hashed_details);
! OCI8_FAIL(connection, "OCILogon", error);
}
! }
! return_value->value.lval = id;
! }
}
efree(hashed_details);
return_value->type = IS_LONG;
}
#endif
--- 484,604 ----
*/
if (_php3_hash_find(plist, hashed_details, hashed_len + 1,
! (void **) &index_ptr) == FAILURE) {
! /* the link is not in the persistent list */
! list_entry new_index_ptr;
!
! OCI8_DEBUG("Connection \"%s\" not found in plist.", hashed_details);
!
! if (persistent) {
! connection = (oci8_connection *)malloc(sizeof(oci8_connection));
! } else {
! connection = (oci8_connection *)emalloc(sizeof(oci8_connection));
! }
! if (connection == NULL) {
! efree(hashed_details);
! RETURN_OUT_OF_MEMORY;
! }
!
! /* Set up the Oracle environment. We can specify our own
! * malloc/realloc/free functions to OCIInitialize, but
! * we don't do that yet.
! */
! OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL);
! 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(connection->pEnv, connection->pError,
! &connection->pServiceContext,
! username, username_len,
! password, password_len,
! dbname, dbname_len);
if (error) {
! efree(hashed_details);
! persistent ? free(connection) : efree(connection);
! OCI8_FAIL(connection, "OCILogon", error);
}
!
! connection->open = 1;
! OCI8_DEBUG("\"%s\" created and connected.",
! hashed_details);
!
! if (persistent) {
! new_index_ptr.ptr = (void *) return_value->value.lval;
! new_index_ptr.type = le_index_ptr;
!
! if (_php3_hash_update(plist, hashed_details, hashed_len + 1,
! (void *) &new_index_ptr,
! sizeof(list_entry),NULL) == FAILURE) {
! php3i_oci8_error(connection->pError, "OCILogoff",
! OCILogoff(connection->pServiceContext,
! connection->pError));
! free(connection);
! efree(hashed_details);
! php3_error(E_WARNING, "OCILogon: can't update plist");
! RETURN_FALSE;
! }
! OCI8_GLOBAL(php3_oci8_module).num_persistent++;
!
! /* add the connection to the non-persistent list */
! return_value->value.lval =
! php3_list_insert(connection,
! OCI8_GLOBAL(php3_oci8_module).le_pconn);
! OCI8_DEBUG("\"%s\" inserted as le_pconn in list with id %d.",
! hashed_details, return_value->value.lval);
! } else {
! /* non persistent, simply add to list */
! return_value->value.lval =
! php3_list_insert(connection,
! OCI8_GLOBAL(php3_oci8_module).le_conn);
! OCI8_DEBUG("\"%s\" inserted as le_conn in list with id %s.",
! return_value->value.lval);
! }
!
! OCI8_GLOBAL(php3_oci8_module).num_links++;
!
! } else {
! /* the link is already in the persistent list */
! int type;
!
! if (index_ptr->type != le_index_ptr) {
! efree(hashed_details);
! php3_error(E_WARNING, "Oops, something went completly wrong");
! RETURN_FALSE;
! }
! id = (int) index_ptr->ptr;
! connection = (oci8_connection *)php3_plist_find(id, &type);
!
! if (connection && (type == OCI8_GLOBAL(php3_oci8_module).le_conn ||
! type == OCI8_GLOBAL(php3_oci8_module).le_pconn)) {
! if (!php3i_oci_ping(connection)) {
! /* if the connection was lost, try reconnecting */
! error = OCILogon(connection->pEnv, connection->pError,
! &connection->pServiceContext,
! username, username_len,
! password, password_len,
! dbname, dbname_len);
! if (error) {
! /* delete list entry for this connection */
! php3_list_delete(id);
! /* delete hashed plist entry for this dead connection */
! _php3_hash_del(plist, hashed_details, hashed_len);
! efree(hashed_details);
! OCI8_FAIL(connection, "OCILogon", error);
! }
! }
! return_value->value.lval = id;
! }
}
efree(hashed_details);
return_value->type = IS_LONG;
}
+ /* }}} */
#endif
Index: php3/functions/oracle.c
diff -c php3/functions/oracle.c:1.78 php3/functions/oracle.c:1.79
*** php3/functions/oracle.c:1.78 Thu Aug 6 11:04:32 1998
--- php3/functions/oracle.c Wed Sep 9 08:38:08 1998
***************
*** 111,118 ****
};
php3_module_entry oracle_module_entry = {
! "Oracle", oracle_functions, php3_minit_oracle, php3_mshutdown_oracle,
! php3_rinit_oracle, NULL, php3_info_oracle, 0, 0, 0, NULL
};
static const text *ora_func_tab[] =
--- 111,124 ----
};
php3_module_entry oracle_module_entry = {
! "Oracle",
! oracle_functions,
! php3_minit_oracle,
! php3_mshutdown_oracle,
! php3_rinit_oracle,
! NULL,
! php3_info_oracle,
! STANDARD_MODULE_PROPERTIES
};
static const text *ora_func_tab[] =
Index: php3/functions/php3_oci8.h
diff -c php3/functions/php3_oci8.h:1.1 php3/functions/php3_oci8.h:1.2
*** php3/functions/php3_oci8.h:1.1 Wed Sep 9 05:06:54 1998
--- php3/functions/php3_oci8.h Wed Sep 9 08:38:09 1998
***************
*** 33,44 ****
#if HAVE_OCI8
# ifndef _PHP_OCI8_H
# define _PHP_OCI8_H
! #if 0
typedef struct {
OCIEnv *pEnv;
} oci8_request;
! #endif
typedef struct {
OCIEnv *pEnv;
--- 33,59 ----
#if HAVE_OCI8
# ifndef _PHP_OCI8_H
# define _PHP_OCI8_H
+ # endif
! # if (defined(__osf__) && defined(__alpha))
! # ifndef A_OSF
! # define A_OSF
! # endif
! # ifndef OSF1
! # define OSF1
! # endif
! # ifndef _INTRINSICS
! # define _INTRINSICS
! # endif
! # endif /* osf alpha */
!
! # include <oci.h>
!
! # if 0
typedef struct {
OCIEnv *pEnv;
} oci8_request;
! # endif
typedef struct {
OCIEnv *pEnv;
***************
*** 52,70 ****
OCIStmt *pStatement;
} oci8_statement;
extern php3_module_entry oci8_module_entry;
! # define oci8_module_ptr &oci8_module_entry
! # define ORACLE_TLS_VARS (void)
! # define ORACLE_GLOBAL(x) (x)
! # define RETURN_OUT_OF_MEMORY \
php3_error(E_WARNING, "Out of memory");\
RETURN_FALSE
! # define OCI8_FAIL(c,f,r) \
php3i_oci8_error((c)->pError,(f),(r));\
RETURN_FALSE
- # endif /* _PHP_OCI8_H */
#endif /* HAVE_OCI8 */
/*
--- 67,107 ----
OCIStmt *pStatement;
} oci8_statement;
+ typedef struct {
+ 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_cursor;
+ HashTable *list;
+ HashTable *plist;
+ } oci8_module;
+
extern php3_module_entry oci8_module_entry;
! # define oci8_module_ptr &oci8_module_entry
! # define RETURN_OUT_OF_MEMORY \
php3_error(E_WARNING, "Out of memory");\
RETURN_FALSE
! # define OCI8_FAIL(c,f,r) \
php3i_oci8_error((c)->pError,(f),(r));\
RETURN_FALSE
+
+ void php3_oci_logon(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci_plogon(INTERNAL_FUNCTION_PARAMETERS);
+ void php3_oci_do_logon(INTERNAL_FUNCTION_PARAMETERS, int persistent);
+
+ #else /* !HAVE_OCI8 */
+
+ # define oci8_module_ptr NULL
#endif /* HAVE_OCI8 */
/*
--
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