php-src/ext/oci8/oci8.c

3730 lines
89 KiB
C
Raw Normal View History

1999-04-22 06:49:16 +08:00
/*
+----------------------------------------------------------------------+
1999-07-16 21:13:16 +08:00
| PHP version 4.0 |
1999-04-22 06:49:16 +08:00
+----------------------------------------------------------------------+
1999-07-16 21:13:16 +08:00
| Copyright (c) 1997, 1998, 1999 The PHP Group |
1999-04-22 06:49:16 +08:00
+----------------------------------------------------------------------+
1999-07-16 21:13:16 +08:00
| This source file is subject to version 2.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
1999-04-22 06:49:16 +08:00
+----------------------------------------------------------------------+
| Authors: Stig S<EFBFBD>ther Bakken <ssb@fast.no> |
1999-04-22 06:49:16 +08:00
| Thies C. Arntzen <thies@digicol.de> |
| |
| Initial work sponsored by |
| Digital Collections, http://www.digicol.de/ |
+----------------------------------------------------------------------+
*/
1999-08-17 21:54:25 +08:00
#define OCI_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */
1999-04-22 06:49:16 +08:00
/* $Id$ */
/* TODO list:
*
* - php.ini flags
1999-12-01 15:34:06 +08:00
* - Change return-value for OCIFetch*() (1-row read, 0-Normal end, false-error)
1999-04-22 06:49:16 +08:00
* - Error mode (print or shut up?)
* - OCIPasswordChange()
* - binding of arrays
* - Truncate input values to the bind size
* - Character sets for NCLOBS
* - split the module into an upper (php-callable) and lower (c-callable) layer!
* - make_pval needs some cleanup....
* - NULLS (retcode/indicator) needs some more work for describing & binding
* - remove all XXXs
* - clean up and documentation
* - make OCIInternalDebug accept a mask of flags....
* - better NULL handling
* - add some flags to OCIFetchStatement (maxrows etc...)
*/
/* {{{ includes & stuff */
#if defined(COMPILE_DL)
# include "dl/phpdl.h"
#endif
#include "php.h"
1999-09-13 19:13:53 +08:00
#include "ext/standard/head.h"
1999-08-10 22:33:59 +08:00
#if HAVE_OCI8
1999-07-08 22:12:07 +08:00
1999-04-22 06:49:16 +08:00
#include "php3_oci8.h"
1999-08-17 21:54:25 +08:00
/* True globals, no need for thread safety */
static int le_conn; /* active connections */
static int le_stmt; /* active statements */
static zend_class_entry *oci_lob_class_entry_ptr;
#ifndef SQLT_BFILEE
#define SQLT_BFILEE 114
#endif
#ifndef SQLT_CFILEE
#define SQLT_CFILEE 115
#endif
1999-04-22 06:49:16 +08:00
#define SAFE_STRING(s) ((s)?(s):"")
#if !(WIN32|WINNT)
1999-08-17 21:54:25 +08:00
#include "build-defs.h"
1999-04-22 06:49:16 +08:00
#endif
1999-08-17 21:54:25 +08:00
#include <fcntl.h>
1999-04-22 06:49:16 +08:00
#include "snprintf.h"
/* }}} */
/* {{{ thread safety stuff */
1999-08-17 21:54:25 +08:00
#ifdef ZTS
int oci_globals_id;
#else
PHP_OCI_API php_oci_globals oci_globals;
#endif
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ dynamically loadable module stuff */
#if COMPILE_DL
1999-08-17 21:54:25 +08:00
DLEXPORT php3_module_entry *get_module() { return &oci_module_entry; };
1999-04-22 06:49:16 +08:00
#endif /* COMPILE_DL */
/* }}} */
/* {{{ startup/shutdown/info/internal function prototypes */
1999-08-17 21:54:25 +08:00
PHP_MINIT_FUNCTION(oci);
PHP_RINIT_FUNCTION(oci);
PHP_MSHUTDOWN_FUNCTION(oci);
PHP_RSHUTDOWN_FUNCTION(oci);
PHP_MINFO_FUNCTION(oci);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static ub4 oci_error(OCIError *err_p, char *what, sword status);
static int oci_ping(oci_connection *conn);
1999-08-17 21:54:25 +08:00
static void oci_debug(const char *format,...);
1999-04-22 06:49:16 +08:00
1999-09-29 21:35:12 +08:00
static void _oci_connection_dtor(oci_connection *connection);
static void _oci_statement_dtor(oci_statement *statement);
1999-09-13 19:13:53 +08:00
static int _oci_column_dtor(void *data);
static int _oci_descr_dtor(void *data);
static int _oci_define_dtor(void *data);
1999-04-22 06:49:16 +08:00
static oci_connection *oci_get_conn(zval **);
static oci_statement *oci_get_stmt(zval **);
static oci_out_column *oci_get_col(oci_statement *, int, zval **);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static int oci_make_pval(pval *,oci_statement *,oci_out_column *, char *, int mode);
static oci_statement *oci_parse(oci_connection *, char *, int);
1999-08-17 21:54:25 +08:00
static int oci_execute(oci_statement *, char *,ub4 mode,HashTable *);
static int oci_fetch(oci_statement *, ub4, char *);
static ub4 oci_loadlob(oci_connection *, oci_descriptor *, char **);
1999-08-17 21:54:25 +08:00
static int oci_setprefetch(oci_statement *statement,int size);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static void oci_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent,int exclusive);
1999-04-22 06:49:16 +08:00
/* ServerAttach/Detach */
1999-08-17 21:54:25 +08:00
static oci_server *oci_open_server(char *dbname,int persistent);
static void _oci_close_server(oci_server *server);
/* SessionBegin/End */
1999-08-17 21:54:25 +08:00
static oci_session *oci_open_user(oci_server* server,char *username,char *password,int persistent,int exclusive);
static void _oci_close_user(oci_session *session);
1999-04-22 06:49:16 +08:00
/* bind callback functions */
1999-08-17 21:54:25 +08:00
static sb4 oci_bind_in_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 *, ub1 *, dvoid **);
static sb4 oci_bind_out_callback(dvoid *, OCIBind *, ub4, ub4, dvoid **, ub4 **, ub1 *, dvoid **, ub2 **);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
#if 0
/* failover callback function */
1999-08-17 21:54:25 +08:00
static sb4 oci_failover_callback(dvoid *svchp,dvoid* envhp,dvoid *fo_ctx,ub4 fo_type, ub4 fo_event);
1999-05-12 22:28:01 +08:00
#endif
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ extension function prototypes */
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocibindbyname);
PHP_FUNCTION(ocidefinebyname);
PHP_FUNCTION(ocicolumnisnull);
PHP_FUNCTION(ocicolumnname);
PHP_FUNCTION(ocicolumnsize);
PHP_FUNCTION(ocicolumntype);
PHP_FUNCTION(ociexecute);
PHP_FUNCTION(ocifetch);
PHP_FUNCTION(ocicancel);
PHP_FUNCTION(ocifetchinto);
PHP_FUNCTION(ocifetchstatement);
PHP_FUNCTION(ocifreestatement);
PHP_FUNCTION(ociinternaldebug);
PHP_FUNCTION(ocilogoff);
PHP_FUNCTION(ocilogon);
PHP_FUNCTION(ocinlogon);
PHP_FUNCTION(ociplogon);
PHP_FUNCTION(ocierror);
PHP_FUNCTION(ocifreedesc);
PHP_FUNCTION(ocisavelob);
PHP_FUNCTION(ocisavelobfile);
PHP_FUNCTION(ociloadlob);
PHP_FUNCTION(ociwritelobtofile);
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicommit);
PHP_FUNCTION(ocirollback);
PHP_FUNCTION(ocinewdescriptor);
PHP_FUNCTION(ocinumcols);
PHP_FUNCTION(ociparse);
PHP_FUNCTION(ocinewcursor);
PHP_FUNCTION(ociresult);
PHP_FUNCTION(ociserverversion);
PHP_FUNCTION(ocistatementtype);
PHP_FUNCTION(ocirowcount);
PHP_FUNCTION(ocisetprefetch);
1999-04-22 06:49:16 +08:00
#define OCI_GET_STMT(statement,pval) \
statement = oci_get_stmt(pval); \
if (statement == NULL) { \
RETURN_FALSE; \
}
#define OCI_GET_CONN(connection,pval) \
connection = oci_get_conn(pval); \
if (connection == NULL) { \
RETURN_FALSE; \
}
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ extension definition structures */
#define OCI_ASSOC 1<<0
#define OCI_NUM 1<<1
#define OCI_BOTH (OCI_ASSOC|OCI_NUM)
#define OCI_RETURN_NULLS 1<<2
#define OCI_RETURN_LOBS 1<<3
static unsigned char a3_arg_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
static unsigned char a2_arg_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
1999-08-10 22:33:59 +08:00
static zend_function_entry php_oci_functions[] = {
PHP_FE(ocidefinebyname, a3_arg_force_ref)
PHP_FE(ocibindbyname, a3_arg_force_ref)
PHP_FE(ocicolumnisnull, NULL)
PHP_FE(ocicolumnname, NULL)
PHP_FE(ocicolumnsize, NULL)
PHP_FE(ocicolumntype, NULL)
PHP_FE(ociexecute, NULL)
PHP_FE(ocicancel, NULL)
PHP_FE(ocifetch, NULL)
PHP_FE(ocifetchinto, a2_arg_force_ref)
PHP_FE(ocifetchstatement,a2_arg_force_ref)
PHP_FE(ocifreestatement, NULL)
PHP_FE(ociinternaldebug, NULL)
PHP_FE(ocinumcols, NULL)
PHP_FE(ociparse, NULL)
PHP_FE(ocinewcursor, NULL)
PHP_FE(ociresult, NULL)
PHP_FE(ociserverversion, NULL)
PHP_FE(ocistatementtype, NULL)
PHP_FE(ocirowcount, NULL)
PHP_FE(ocilogoff, NULL)
PHP_FE(ocilogon, NULL)
PHP_FE(ocinlogon, NULL)
PHP_FE(ociplogon, NULL)
PHP_FE(ocierror, NULL)
PHP_FE(ocifreedesc, NULL)
PHP_FE(ocisavelob, NULL)
PHP_FE(ocisavelobfile, NULL)
PHP_FE(ociloadlob, NULL)
PHP_FE(ociwritelobtofile,NULL)
1999-08-10 22:33:59 +08:00
PHP_FE(ocicommit, NULL)
PHP_FE(ocirollback, NULL)
PHP_FE(ocinewdescriptor, NULL)
PHP_FE(ocisetprefetch, NULL)
1999-11-13 01:05:57 +08:00
PHP_FALIAS(ocifreecursor,ocifreestatement,NULL)
1999-08-10 22:33:59 +08:00
{NULL,NULL,NULL}
1999-04-22 06:49:16 +08:00
};
static zend_function_entry php_oci_lob_class_functions[] = {
PHP_FALIAS(load, ociloadlob, NULL)
PHP_FALIAS(writetofile, ociwritelobtofile,NULL)
PHP_FALIAS(save, ocisavelob, NULL)
PHP_FALIAS(savefile, ocisavelobfile, NULL)
PHP_FALIAS(free, ocifreedesc, NULL)
{NULL,NULL,NULL}
};
1999-04-22 06:49:16 +08:00
php3_module_entry oci8_module_entry = {
1999-08-17 21:54:25 +08:00
"Oracle-OCI8", /* extension name */
php_oci_functions, /* extension function list */
PHP_MINIT(oci), /* extension-wide startup function */
PHP_MSHUTDOWN(oci), /* extension-wide shutdown function */
PHP_RINIT(oci), /* per-request startup function */
PHP_RSHUTDOWN(oci), /* per-request shutdown function */
PHP_MINFO(oci), /* information function */
1999-04-22 06:49:16 +08:00
STANDARD_MODULE_PROPERTIES
};
/* }}} */
/* {{{ debug malloc/realloc/free */
1999-08-17 21:54:25 +08:00
#if OCI_USE_EMALLOC
CONST dvoid *ocimalloc(dvoid *ctx, size_t size)
{
dvoid *ret;
ret = (dvoid *)malloc(size);
1999-08-17 21:54:25 +08:00
oci_debug("ocimalloc(%d) = %08x", size,ret);
return ret;
}
CONST dvoid *ocirealloc(dvoid *ctx, dvoid *ptr, size_t size)
{
dvoid *ret;
1999-08-17 21:54:25 +08:00
oci_debug("ocirealloc(%08x, %d)", ptr, size);
ret = (dvoid *)realloc(ptr, size);
return ptr;
}
CONST void ocifree(dvoid *ctx, dvoid *ptr)
{
1999-08-17 21:54:25 +08:00
oci_debug("ocifree(%08x)", ptr);
free(ptr);
}
#endif
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ startup, shutdown and info functions */
1999-08-17 21:54:25 +08:00
#ifdef ZTS
static void php_oci_init_globals(php_oci_globals *oci_globals)
{
OCI(user_num) = 1000;
OCI(server_num) = 2000;
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(user) = malloc(sizeof(HashTable));
zend_hash_init(OCI(user), 13, NULL, NULL, 1);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(server) = malloc(sizeof(HashTable));
zend_hash_init(OCI(server), 13, NULL, NULL, 1);
1999-08-19 00:48:59 +08:00
OCIEnvInit(&OCI(pEnv), OCI_DEFAULT, 0, NULL);
OCIHandleAlloc(OCI(pEnv),
(dvoid **)&OCI(pError),
OCI_HTYPE_ERROR,
0,
NULL);
1999-08-17 21:54:25 +08:00
}
#endif
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
PHP_MINIT_FUNCTION(oci)
{
zend_class_entry oci_lob_class_entry;
1999-08-17 21:54:25 +08:00
ELS_FETCH();
1999-08-17 21:54:25 +08:00
#ifdef ZTS
oci_globals_id = ts_allocate_id(sizeof(php_oci_globals), php_oci_init_globals, NULL);
#else
OCI(user_num) = 1000;
OCI(server_num) = 2000;
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(user) = malloc(sizeof(HashTable));
zend_hash_init(OCI(user), 13, NULL, NULL, 1);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(server) = malloc(sizeof(HashTable));
zend_hash_init(OCI(server), 13, NULL, NULL, 1);
1999-08-19 00:48:59 +08:00
OCIEnvInit(&OCI(pEnv), OCI_DEFAULT, 0, NULL);
OCIHandleAlloc(OCI(pEnv),
(dvoid **)&OCI(pError),
OCI_HTYPE_ERROR,
0,
NULL);
1999-08-17 21:54:25 +08:00
#endif
1999-09-29 21:35:12 +08:00
le_stmt = register_list_destructors(_oci_statement_dtor, NULL);
1999-09-29 22:20:27 +08:00
le_conn = register_list_destructors(_oci_connection_dtor, NULL);
1999-08-17 21:54:25 +08:00
INIT_CLASS_ENTRY(oci_lob_class_entry, "OCI-Lob", php_oci_lob_class_functions);
oci_lob_class_entry_ptr = register_internal_class(&oci_lob_class_entry);
1999-04-22 06:49:16 +08:00
/* 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);
/* for OCIBindByName (real "oci" names + short "php" names*/
REGISTER_LONG_CONSTANT("SQLT_BFILEE",SQLT_BFILEE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLT_CFILEE",SQLT_CFILEE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLT_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLT_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SQLT_RDD",SQLT_RDD, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_B_BFILE",SQLT_BFILEE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_B_CFILEE",SQLT_CFILEE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_B_CLOB",SQLT_CLOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_B_BLOB",SQLT_BLOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_B_ROWID",SQLT_RDD, CONST_CS | CONST_PERSISTENT);
1999-05-12 22:28:01 +08:00
REGISTER_LONG_CONSTANT("OCI_B_CURSOR",SQLT_RSET, CONST_CS | CONST_PERSISTENT);
1999-06-09 18:40:08 +08:00
REGISTER_LONG_CONSTANT("OCI_B_BIN",SQLT_BIN, CONST_CS | CONST_PERSISTENT);
1999-04-22 06:49:16 +08:00
/* for OCIFetchInto & OCIResult */
REGISTER_LONG_CONSTANT("OCI_ASSOC",OCI_ASSOC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_NUM",OCI_NUM, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_BOTH",OCI_BOTH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_RETURN_NULLS",OCI_RETURN_NULLS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_RETURN_LOBS",OCI_RETURN_LOBS, CONST_CS | CONST_PERSISTENT);
/* for OCINewDescriptor (real "oci" names + short "php" names*/
REGISTER_LONG_CONSTANT("OCI_DTYPE_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_DTYPE_LOB",OCI_DTYPE_LOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_DTYPE_ROWID",OCI_DTYPE_ROWID, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("OCI_D_FILE",OCI_DTYPE_FILE, CONST_CS | CONST_PERSISTENT);
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);
#ifdef ZTS
#define PHP_OCI_INIT_MODE OCI_THREADED
#else
#define PHP_OCI_INIT_MODE OCI_DEFAULT
#endif
1999-08-17 21:54:25 +08:00
#if OCI_USE_EMALLOC
OCIInitialize(PHP_OCI_INIT_MODE, NULL, ocimalloc, ocirealloc, ocifree);
1999-04-22 06:49:16 +08:00
#else
OCIInitialize(PHP_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
1999-04-22 06:49:16 +08:00
#endif
return SUCCESS;
}
/* ----------------------------------------------------------------- */
1999-08-17 21:54:25 +08:00
PHP_RINIT_FUNCTION(oci)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
/* XXX NYI
1999-08-17 21:54:25 +08:00
OCI(num_links) =
OCI(num_persistent);
*/
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(debug_mode) = 0; /* start "fresh" */
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
oci_debug("php3_rinit_oci8");
1999-04-22 06:49:16 +08:00
return SUCCESS;
}
1999-08-17 21:54:25 +08:00
static int _user_pcleanup(oci_session *session)
{
1999-08-17 21:54:25 +08:00
_oci_close_user(session);
1999-05-12 22:28:01 +08:00
return 1;
}
1999-08-17 21:54:25 +08:00
static int _server_pcleanup(oci_server *server)
{
1999-08-17 21:54:25 +08:00
_oci_close_server(server);
1999-05-12 22:28:01 +08:00
return 1;
}
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
PHP_MSHUTDOWN_FUNCTION(oci)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-08-17 21:54:25 +08:00
oci_debug("php3_mshutdown_oci8");
1999-08-17 21:54:25 +08:00
zend_hash_apply(OCI(user),(int (*)(void *))_user_pcleanup);
zend_hash_apply(OCI(server),(int (*)(void *))_server_pcleanup);
1999-08-17 21:54:25 +08:00
zend_hash_destroy(OCI(user));
zend_hash_destroy(OCI(server));
1999-08-17 21:54:25 +08:00
free(OCI(user));
free(OCI(server));
1999-08-17 21:54:25 +08:00
OCIHandleFree((dvoid *)OCI(pEnv), OCI_HTYPE_ENV);
1999-04-22 06:49:16 +08:00
return SUCCESS;
}
1999-06-09 18:40:08 +08:00
static int _stmt_cleanup(list_entry *le)
{
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-06-09 18:40:08 +08:00
1999-08-17 21:54:25 +08:00
if (le->type == le_stmt) {
statement = (oci_statement *) le->ptr;
1999-06-09 18:40:08 +08:00
if (!statement->conn->open) {
return 1;
}
}
return 0;
}
1999-08-17 21:54:25 +08:00
static int _user_cleanup(oci_session *session)
{
if (session->persistent)
return 0;
1999-08-17 21:54:25 +08:00
_oci_close_user(session);
1999-05-12 22:28:01 +08:00
return 1;
}
1999-08-17 21:54:25 +08:00
static int _server_cleanup(oci_server *server)
{
if (server->persistent)
return 0;
1999-08-17 21:54:25 +08:00
_oci_close_server(server);
1999-05-12 22:28:01 +08:00
return 1;
}
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
PHP_RSHUTDOWN_FUNCTION(oci)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-08-17 21:54:25 +08:00
oci_debug("php3_rshutdown_oci8");
1999-08-17 21:54:25 +08:00
zend_hash_apply(OCI(user),(int (*)(void *))_user_cleanup);
zend_hash_apply(OCI(server),(int (*)(void *))_server_cleanup);
1999-04-22 06:49:16 +08:00
/* XXX free all statements, rollback all outstanding transactions */
1999-04-22 06:49:16 +08:00
return SUCCESS;
}
1999-08-17 21:54:25 +08:00
PHP_MINFO_FUNCTION(oci)
1999-04-22 06:49:16 +08:00
{
#if !(WIN32|WINNT)
php_printf("Oracle version: %s<br>\n"
1999-04-22 06:49:16 +08:00
"Compile-time ORACLE_HOME: %s<br>\n"
"Libraries used: %s",
PHP_ORACLE_VERSION, PHP_ORACLE_HOME, PHP_ORACLE_LIBS);
#endif
}
/* }}} */
1999-09-13 19:13:53 +08:00
/* {{{ _oci_define_dtor() */
1999-04-22 06:49:16 +08:00
static int
1999-09-13 19:13:53 +08:00
_oci_define_dtor(void *data)
1999-04-22 06:49:16 +08:00
{
1999-09-13 19:13:53 +08:00
oci_define *define = (oci_define *) data;
oci_debug("_oci_define_dtor: %s",define->name);
1999-04-22 06:49:16 +08:00
if (define->name) {
efree(define->name);
define->name = 0;
}
1999-09-29 22:20:27 +08:00
1999-07-12 18:36:19 +08:00
return 1;
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-09-13 19:13:53 +08:00
/* {{{ _oci_column_dtor() */
1999-04-22 06:49:16 +08:00
1999-09-13 19:13:53 +08:00
static int
_oci_column_dtor(void *data)
{
oci_out_column *column = (oci_out_column *) data;
1999-04-22 06:49:16 +08:00
1999-09-29 22:20:27 +08:00
oci_debug("START _oci_column_dtor: %s",column->name);
1999-04-22 06:49:16 +08:00
if (column->data) {
if (column->is_descr) {
zend_hash_index_del(column->statement->conn->descriptors,(int) column->data);
1999-04-22 06:49:16 +08:00
} else {
1999-06-09 18:40:08 +08:00
if (column->data) {
1999-04-22 06:49:16 +08:00
efree(column->data);
}
}
}
1999-09-29 22:20:27 +08:00
oci_debug("END _oci_column_dtor: %s",column->name);
1999-04-22 06:49:16 +08:00
if (column->name) {
efree(column->name);
}
1999-09-13 19:13:53 +08:00
return 1;
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-09-29 21:35:12 +08:00
/* {{{ _oci_statement_dtor() */
1999-04-22 06:49:16 +08:00
static void
1999-09-29 21:35:12 +08:00
_oci_statement_dtor(oci_statement *statement)
1999-04-22 06:49:16 +08:00
{
oci_debug("START _oci_statement_dtor: id=%d last_query=\"%s\"",statement->id,SAFE_STRING(statement->last_query));
1999-04-22 06:49:16 +08:00
if (statement->pStmt) {
OCIHandleFree(statement->pStmt, OCI_HTYPE_STMT);
statement->pStmt = 0;
}
if (statement->pError) {
OCIHandleFree(statement->pError, OCI_HTYPE_ERROR);
statement->pError = 0;
}
if (statement->last_query) {
efree(statement->last_query);
}
if (statement->columns) {
zend_hash_destroy(statement->columns);
1999-04-22 06:49:16 +08:00
efree(statement->columns);
}
if (statement->binds) {
zend_hash_destroy(statement->binds);
1999-04-22 06:49:16 +08:00
efree(statement->binds);
}
if (statement->defines) {
zend_hash_destroy(statement->defines);
1999-04-22 06:49:16 +08:00
efree(statement->defines);
}
zend_list_delete(statement->conn->id); /* delete one ref from the connection */
oci_debug("END _oci_statement_dtor: id=%d",statement->id);
1999-04-22 06:49:16 +08:00
efree(statement);
}
/* }}} */
1999-09-29 21:35:12 +08:00
/* {{{ _oci_connection_dtor() */
1999-04-22 06:49:16 +08:00
static void
1999-09-29 21:35:12 +08:00
_oci_connection_dtor(oci_connection *connection)
1999-04-22 06:49:16 +08:00
{
/*
as the connection is "only" a in memory service context we do not disconnect from oracle.
*/
1999-09-29 22:20:27 +08:00
oci_debug("START _oci_connection_dtor: id=%d",connection->id);
1999-04-22 06:49:16 +08:00
if (connection->descriptors) {
1999-09-29 22:20:27 +08:00
zend_hash_destroy(connection->descriptors);
1999-04-22 06:49:16 +08:00
efree(connection->descriptors);
}
if (connection->pServiceContext) {
OCIHandleFree((dvoid *) connection->pServiceContext, (ub4) OCI_HTYPE_SVCCTX);
}
if (connection->pError) {
OCIHandleFree((dvoid *) connection->pError, (ub4) OCI_HTYPE_ERROR);
}
1999-09-29 22:20:27 +08:00
oci_debug("END _oci_connection_dtor: id=%d",connection->id);
1999-04-22 06:49:16 +08:00
efree(connection);
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_error() */
1999-04-22 06:49:16 +08:00
static ub4
1999-08-17 21:54:25 +08:00
oci_error(OCIError *err_p, char *what, sword status)
1999-04-22 06:49:16 +08:00
{
text errbuf[512];
1999-06-09 18:40:08 +08:00
sb4 errcode = 0;
1999-04-22 06:49:16 +08:00
switch (status) {
case OCI_SUCCESS:
break;
case OCI_SUCCESS_WITH_INFO:
php_error(E_WARNING, "%s: OCI_SUCCESS_WITH_INFO", what);
1999-04-22 06:49:16 +08:00
break;
case OCI_NEED_DATA:
php_error(E_WARNING, "%s: OCI_NEED_DATA", what);
1999-04-22 06:49:16 +08:00
break;
case OCI_NO_DATA:
php_error(E_WARNING, "%s: OCI_NO_DATA", what);
1999-04-22 06:49:16 +08:00
break;
case OCI_ERROR:
OCIErrorGet(err_p, (ub4)1, NULL, &errcode, errbuf,
(ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
php_error(E_WARNING, "%s: %s", what, errbuf);
1999-04-22 06:49:16 +08:00
break;
case OCI_INVALID_HANDLE:
php_error(E_WARNING, "%s: OCI_INVALID_HANDLE", what);
1999-04-22 06:49:16 +08:00
break;
case OCI_STILL_EXECUTING:
php_error(E_WARNING, "%s: OCI_STILL_EXECUTING", what);
1999-04-22 06:49:16 +08:00
break;
case OCI_CONTINUE:
php_error(E_WARNING, "%s: OCI_CONTINUE", what);
1999-04-22 06:49:16 +08:00
break;
default:
break;
}
return errcode;
}
/* }}} */
/* {{{ oci_ping() */
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static int oci_ping(oci_connection *conn)
1999-04-22 06:49:16 +08:00
{
char version[256];
conn->error =
OCIServerVersion(conn->pServiceContext,
conn->pError,
(text*)version,
sizeof(version),
OCI_HTYPE_SVCCTX);
if (conn->error != OCI_SUCCESS) {
return 0;
}
1999-04-22 06:49:16 +08:00
return 1;
}
/* }}} */
/************************* INTERNAL FUNCTIONS *************************/
1999-08-17 21:54:25 +08:00
/* {{{ oci_debug() */
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static void oci_debug(const char *format,...)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
if (OCI(debug_mode)) {
1999-04-22 06:49:16 +08:00
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()) {
php_printf("OCIDebug: %s<br>\n", buffer);
1999-04-22 06:49:16 +08:00
}
}
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_get_conn() */
1999-04-22 06:49:16 +08:00
static oci_connection *oci_get_conn(zval **conn)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_connection *connection;
1999-04-22 06:49:16 +08:00
connection = (oci_connection *) zend_fetch_resource(conn, -1, "OCI8-Connection", NULL, 1, le_conn);
if (connection && connection->open) {
return connection;
} else {
return (oci_connection *) NULL;
}
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_get_stmt() */
1999-04-22 06:49:16 +08:00
static oci_statement *oci_get_stmt(zval **stmt)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
statement = (oci_statement *) zend_fetch_resource(stmt, -1, "OCI8-Connection", NULL, 1, le_stmt);
if (statement && statement->conn->open) {
return statement;
} else {
return (oci_statement *) NULL;
}
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_get_col() */
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
static oci_out_column *
oci_get_col(oci_statement *statement, int col, pval **pval)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_out_column *outcol = NULL;
1999-04-22 06:49:16 +08:00
int i;
1999-06-09 18:40:08 +08:00
if (statement->columns == 0) { /* we release the columns at the end of a fetch */
return NULL;
}
1999-04-22 06:49:16 +08:00
if (pval) {
if ((*pval)->type == IS_STRING) {
1999-04-22 06:49:16 +08:00
for (i = 0; i < statement->ncolumns; i++) {
outcol = oci_get_col(statement, i + 1, 0);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
continue;
} else if (((int) outcol->name_len == (*pval)->value.str.len)
&& (! strncmp(outcol->name,(*pval)->value.str.val,(*pval)->value.str.len))) {
1999-04-22 06:49:16 +08:00
return outcol;
}
}
} else {
convert_to_long_ex(pval);
return oci_get_col(statement,(*pval)->value.lval,0);
1999-04-22 06:49:16 +08:00
}
} else if (col != -1) {
if (zend_hash_index_find(statement->columns, col, (void **)&outcol) == FAILURE) {
php_error(E_WARNING, "Invalid column %d", col);
1999-04-22 06:49:16 +08:00
return NULL;
}
return outcol;
}
return NULL;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_make_pval() */
1999-04-22 06:49:16 +08:00
static int
1999-08-17 21:54:25 +08:00
oci_make_pval(pval *value,oci_statement *statement,oci_out_column *column, char *func, int mode)
1999-04-22 06:49:16 +08:00
{
size_t size;
1999-08-17 21:54:25 +08:00
oci_descriptor *descr;
1999-04-22 06:49:16 +08:00
ub4 loblen;
char *buffer;
1999-06-09 18:40:08 +08:00
if (column->indicator || column->retcode)
1999-07-08 22:12:07 +08:00
if ((column->indicator != -1) && (column->retcode != 1405))
oci_debug("oci_make_pval: %16s,retlen = %4d,retlen4 = %d,storage_size4 = %4d,indicator %4d, retcode = %4d",
column->name,column->retlen,column->retlen4,column->storage_size4,column->indicator,column->retcode);
1999-04-22 06:49:16 +08:00
if (column->indicator == -1) { /* column is NULL */
var_reset(value); /* XXX we NEED to make sure that there's no data attached to this yet!!! */
return 0;
}
1999-05-12 22:28:01 +08:00
if (column->is_cursor) { /* REFCURSOR -> simply return the statement id */
value->type = IS_RESOURCE;
1999-05-12 22:28:01 +08:00
value->value.lval = column->stmtid;
zend_list_addref(column->stmtid);
1999-05-12 22:28:01 +08:00
} else if (column->is_descr) {
1999-07-08 22:12:07 +08:00
if ((column->data_type != SQLT_RDD) && (mode & OCI_RETURN_LOBS)) {
1999-04-22 06:49:16 +08:00
/* OCI_RETURN_LOBS means that we want the content of the LOB back instead of the locator */
if (zend_hash_index_find(statement->conn->descriptors,(int) column->data, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor %d",column->data);
1999-04-22 06:49:16 +08:00
return -1;
}
loblen = oci_loadlob(statement->conn,descr,&buffer);
1999-04-22 06:49:16 +08:00
if (loblen >= 0) {
1999-04-22 06:49:16 +08:00
value->type = IS_STRING;
value->value.str.len = loblen;
value->value.str.val = buffer;
} else {
var_reset(value);
}
} else { /* return the locator */
object_init_ex(value, oci_lob_class_entry_ptr);
add_property_resource(value, "descriptor", (long) column->data);
add_property_resource(value, "connection", statement->conn->id);
zend_list_addref(statement->conn->id);
1999-04-22 06:49:16 +08:00
}
} else {
switch (column->retcode) {
case 0: /* intact value */
/*
1999-08-17 21:54:25 +08:00
oci_debugcol(column,"OK");
1999-04-22 06:49:16 +08:00
*/
1999-06-09 18:40:08 +08:00
if (column->piecewise) {
size = column->retlen4;
1999-06-09 18:40:08 +08:00
} else {
1999-07-08 22:12:07 +08:00
size = column->retlen;
1999-06-09 18:40:08 +08:00
}
1999-04-22 06:49:16 +08:00
break;
default: /* XXX we SHOULD maybe have a different behaviour for unknown results! */
var_reset(value);
return 0;
}
value->type = IS_STRING;
value->value.str.len = size;
value->value.str.val = estrndup(column->data,size);
}
return 0;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_setprefetch() */
1999-04-22 06:49:16 +08:00
1999-07-08 22:12:07 +08:00
static int
1999-08-17 21:54:25 +08:00
oci_setprefetch(oci_statement *statement,int size)
1999-07-08 22:12:07 +08:00
{
ub4 prefetch;
prefetch = size * 1024;
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-07-08 22:12:07 +08:00
"OCIAttrSet OCI_ATTR_PREFETCH_MEMORY",
OCIAttrSet(statement->pStmt,
OCI_HTYPE_STMT,
&prefetch,
0,
OCI_ATTR_PREFETCH_MEMORY,
statement->pError));
prefetch = size;
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-07-08 22:12:07 +08:00
"OCIAttrSet OCI_ATTR_PREFETCH_MEMORY",
OCIAttrSet(statement->pStmt,
OCI_HTYPE_STMT,
&prefetch,
0,
OCI_ATTR_PREFETCH_ROWS,
statement->pError));
return 1;
}
1999-08-10 22:33:59 +08:00
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_parse() */
1999-08-10 22:33:59 +08:00
static oci_statement *oci_parse(oci_connection *connection, char *query, int len)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_statement *statement;
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
statement = ecalloc(1,sizeof(oci_statement));
1999-08-17 21:54:25 +08:00
OCIHandleAlloc(OCI(pEnv),
1999-04-22 06:49:16 +08:00
(dvoid **)&statement->pStmt,
OCI_HTYPE_STMT,
0,
NULL);
1999-08-17 21:54:25 +08:00
OCIHandleAlloc(OCI(pEnv),
1999-04-22 06:49:16 +08:00
(dvoid **)&statement->pError,
OCI_HTYPE_ERROR,
0,
NULL);
1999-05-12 22:28:01 +08:00
if (len > 0) {
connection->error =
1999-08-17 21:54:25 +08:00
oci_error(connection->pError,
1999-05-12 22:28:01 +08:00
"OCIParse",
OCIStmtPrepare(statement->pStmt,
connection->pError,
1999-06-09 18:40:08 +08:00
(text*)query,
1999-05-12 22:28:01 +08:00
len,
OCI_NTV_SYNTAX,
OCI_DEFAULT));
if (connection->error) {
/* XXX loose memory */
return 0;
}
1999-04-22 06:49:16 +08:00
}
1999-05-12 22:28:01 +08:00
if (query) {
statement->last_query = estrdup(query);
}
1999-04-22 06:49:16 +08:00
statement->conn = connection;
statement->id = zend_list_insert(statement,le_stmt);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
oci_debug("oci_parse \"%s\" id=%d conn=%d",
1999-05-12 22:28:01 +08:00
SAFE_STRING(query),
1999-04-22 06:49:16 +08:00
statement->id,
statement->conn->id);
zend_list_addref(statement->conn->id);
return statement;
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_execute() */
1999-04-22 06:49:16 +08:00
static int
1999-08-17 21:54:25 +08:00
oci_execute(oci_statement *statement, char *func,ub4 mode, HashTable *list)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_out_column *outcol;
oci_out_column column;
1999-04-22 06:49:16 +08:00
OCIParam *param = 0;
text *colname;
ub4 counter;
ub2 define_type;
ub2 stmttype;
ub4 iters;
ub4 colcount;
1999-07-08 22:12:07 +08:00
ub2 dynamic;
dvoid *buf;
1999-08-17 21:54:25 +08:00
oci_descriptor *pdescr, descr;
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_STMT_TYPE",
OCIAttrGet((dvoid *)statement->pStmt,
OCI_HTYPE_STMT,
(ub2 *)&stmttype,
(ub4 *)0,
OCI_ATTR_STMT_TYPE,
statement->pError));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0;
}
if (stmttype == OCI_STMT_SELECT) {
iters = 0;
} else {
iters = 1;
}
1999-05-12 22:28:01 +08:00
if (statement->last_query) { /* if we execute refcursors we don't have a query and we don't want to execute!!! */
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIStmtExecute",
OCIStmtExecute(statement->conn->pServiceContext,
statement->pStmt,
statement->pError,
iters,
0,
NULL,
NULL,
mode));
switch (statement->error) {
case 0:
break;
case 3113: /* ORA-03113: end-of-file on communication channel */
statement->conn->open = 0;
statement->conn->session->open = 0;
statement->conn->session->server->open = 0;
return 0;
break;
default:
return 0;
break;
1999-05-12 22:28:01 +08:00
}
1999-04-22 06:49:16 +08:00
}
if (stmttype == OCI_STMT_SELECT && (statement->executed == 0)) {
/* we only need to do the define step is this very statement is executed the first time! */
statement->executed++;
statement->columns = emalloc(sizeof(HashTable));
if (!statement->columns ||
1999-09-13 19:13:53 +08:00
zend_hash_init(statement->columns, 13, NULL,_oci_column_dtor, 0) == FAILURE) {
1999-04-22 06:49:16 +08:00
/* out of memory */
return 0;
}
OCIHandleAlloc(
1999-08-17 21:54:25 +08:00
OCI(pEnv),
1999-04-22 06:49:16 +08:00
(dvoid **)&param,
OCI_DTYPE_PARAM,
0,
NULL);
counter = 1;
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_PARAM_COUNT",
OCIAttrGet((dvoid *)statement->pStmt,
OCI_HTYPE_STMT,
(dvoid *)&colcount,
(ub4 *)0,
OCI_ATTR_PARAM_COUNT,
statement->pError));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
statement->ncolumns = colcount;
for (counter = 1; counter <= colcount; counter++) {
1999-08-17 21:54:25 +08:00
memset(&column,0,sizeof(oci_out_column));
1999-04-22 06:49:16 +08:00
if (zend_hash_index_update(statement->columns, counter, &column,
1999-08-17 21:54:25 +08:00
sizeof(oci_out_column), (void**) &outcol) == FAILURE) {
1999-04-22 06:49:16 +08:00
efree(statement->columns);
/* out of memory */
return 0;
}
outcol->statement = statement;
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIParamGet OCI_HTYPE_STMT",
OCIParamGet(
(dvoid *)statement->pStmt,
OCI_HTYPE_STMT,
statement->pError,
(dvoid*)&param,
counter));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_TYPE",
OCIAttrGet((dvoid *)param,
OCI_DTYPE_PARAM,
1999-07-08 22:12:07 +08:00
(dvoid *)&outcol->data_type,
1999-05-12 22:28:01 +08:00
(ub4 *)0,
OCI_ATTR_DATA_TYPE,
statement->pError));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
1999-06-09 18:40:08 +08:00
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_SIZE",
OCIAttrGet((dvoid *)param,
OCI_DTYPE_PARAM,
1999-07-08 22:12:07 +08:00
(dvoid *)&outcol->data_size,
1999-05-12 22:28:01 +08:00
(dvoid *)0,
OCI_ATTR_DATA_SIZE,
statement->pError));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
1999-07-08 22:12:07 +08:00
outcol->storage_size4 = outcol->data_size;
outcol->retlen = outcol->data_size;
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-05-12 22:28:01 +08:00
"OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_NAME",
OCIAttrGet((dvoid *)param,
OCI_DTYPE_PARAM,
(dvoid **)&colname, /* XXX this string is NOT zero terminated!!!! */
(ub4 *)&outcol->name_len,
(ub4)OCI_ATTR_NAME,
statement->pError));
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
1999-06-09 18:40:08 +08:00
outcol->name = estrndup((char*) colname,outcol->name_len);
1999-04-22 06:49:16 +08:00
/* find a user-setted define */
if (statement->defines) {
zend_hash_find(statement->defines,outcol->name,outcol->name_len,(void **) &outcol->define);
1999-04-22 06:49:16 +08:00
}
1999-07-08 22:12:07 +08:00
buf = 0;
switch (outcol->data_type) {
case SQLT_RSET:
outcol->pstmt = oci_parse(statement->conn,0,0);
outcol->stmtid = outcol->pstmt->id;
1999-05-12 22:28:01 +08:00
1999-07-08 22:12:07 +08:00
define_type = outcol->data_type;
outcol->is_cursor = 1;
outcol->storage_size4 = -1;
outcol->retlen = -1;
dynamic = OCI_DEFAULT;
buf = &(outcol->pstmt->pStmt);
1999-04-22 06:49:16 +08:00
break;
case SQLT_RDD: /* ROWID */
case SQLT_BLOB: /* binary LOB */
case SQLT_CLOB: /* character LOB */
case SQLT_BFILE: /* binary file LOB */
1999-07-08 22:12:07 +08:00
define_type = outcol->data_type;
1999-04-22 06:49:16 +08:00
outcol->is_descr = 1;
outcol->storage_size4 = -1;
1999-07-08 22:12:07 +08:00
dynamic = OCI_DEFAULT;
if (outcol->data_type == SQLT_BFILE) {
descr.type = OCI_DTYPE_FILE;
} else if (outcol->data_type == SQLT_RDD ) {
descr.type = OCI_DTYPE_ROWID;
} else {
descr.type = OCI_DTYPE_LOB;
}
1999-08-17 21:54:25 +08:00
OCIDescriptorAlloc(OCI(pEnv),
1999-07-08 22:12:07 +08:00
(dvoid *)&(descr.ocidescr),
descr.type,
(size_t) 0,
(dvoid **) 0);
zend_hash_index_update(statement->conn->descriptors,
1999-07-08 22:12:07 +08:00
statement->conn->descriptors_count,
&descr,
1999-08-17 21:54:25 +08:00
sizeof(oci_descriptor),
1999-07-08 22:12:07 +08:00
(void **)&pdescr);
outcol->data = (void *) outcol->statement->conn->descriptors_count++;
buf = outcol->pdescr = pdescr;
1999-08-17 21:54:25 +08:00
oci_debug("OCIExecute: new descriptor for %s",outcol->name);
1999-04-22 06:49:16 +08:00
break;
1999-06-09 18:40:08 +08:00
case SQLT_LNG:
1999-07-08 22:12:07 +08:00
case SQLT_LBI:
if (outcol->data_type == SQLT_LBI) {
define_type = SQLT_BIN;
} else {
define_type = SQLT_STR;
}
1999-08-17 21:54:25 +08:00
outcol->storage_size4 = OCI_MAX_DATA_SIZE;
1999-06-09 18:40:08 +08:00
outcol->piecewise = 1;
1999-07-08 22:12:07 +08:00
dynamic = OCI_DYNAMIC_FETCH;
1999-04-22 06:49:16 +08:00
break;
1999-07-08 22:12:07 +08:00
case SQLT_BIN:
1999-04-22 06:49:16 +08:00
default:
define_type = SQLT_STR;
1999-07-08 22:12:07 +08:00
if ((outcol->data_type == SQLT_DAT) || (outcol->data_type == SQLT_NUM)) {
outcol->storage_size4 = 512; /* XXX this should fit "most" NLS date-formats and Numbers */
1999-04-22 06:49:16 +08:00
} else {
outcol->storage_size4++; /* add one for string terminator */
}
1999-07-08 22:12:07 +08:00
if (outcol->data_type == SQLT_BIN) {
outcol->storage_size4 *= 3;
}
dynamic = OCI_DEFAULT;
buf = outcol->data = (text *) emalloc(outcol->storage_size4);
1999-04-22 06:49:16 +08:00
break;
}
1999-07-08 22:12:07 +08:00
if (dynamic == OCI_DYNAMIC_FETCH) {
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-07-08 22:12:07 +08:00
"OCIDefineByPos",
OCIDefineByPos(statement->pStmt, /* IN/OUT handle to the requested SQL query */
(OCIDefine **)&outcol->pDefine,/* IN/OUT pointer to a pointer to a define handle */
statement->pError, /* IN/OUT An error handle */
counter, /* IN position in the select list */
(dvoid *)NULL, /* IN/OUT pointer to a buffer */
1999-07-08 22:12:07 +08:00
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 *)NULL, /* IN/OUT Pointer to array of length of data fetched */
(ub2 *)NULL, /* OUT Pointer to array of column-level return codes */
OCI_DYNAMIC_FETCH)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */
1999-07-08 22:12:07 +08:00
} else {
statement->error =
1999-08-17 21:54:25 +08:00
oci_error(statement->pError,
1999-07-08 22:12:07 +08:00
"OCIDefineByPos",
OCIDefineByPos(statement->pStmt, /* IN/OUT handle to the requested SQL query */
(OCIDefine **)&outcol->pDefine,/* IN/OUT pointer to a pointer to a define handle */
statement->pError, /* IN/OUT An error handle */
counter, /* IN position in the select list */
(dvoid *)buf, /* IN/OUT pointer to a buffer */
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->retlen, /* IN/OUT Pointer to array of length of data fetched */
(ub2 *)&outcol->retcode, /* OUT Pointer to array of column-level return codes */
OCI_DEFAULT)); /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */
1999-07-08 22:12:07 +08:00
}
1999-05-12 22:28:01 +08:00
if (statement->error) {
1999-04-22 06:49:16 +08:00
return 0; /* XXX we loose memory!!! */
}
}
}
1999-07-08 22:12:07 +08:00
1999-04-22 06:49:16 +08:00
return 1;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_fetch() */
1999-04-22 06:49:16 +08:00
static int
1999-08-17 21:54:25 +08:00
oci_fetch(oci_statement *statement, ub4 nrows, char *func)
1999-04-22 06:49:16 +08:00
{
int i;
1999-08-17 21:54:25 +08:00
oci_out_column *column;
1999-04-22 06:49:16 +08:00
1999-06-09 18:40:08 +08:00
/* first we need to reset our piecewise fetch-infos */
for (i = 0; i < statement->ncolumns; i++) {
column = oci_get_col(statement, i + 1, 0);
1999-06-09 18:40:08 +08:00
if (column == NULL) { /* should not happen... */
continue;
}
if (column->piecewise) {
column->retlen4 = 0;
1999-06-09 18:40:08 +08:00
}
}
1999-05-12 22:28:01 +08:00
statement->error =
OCIStmtFetch(statement->pStmt,
statement->pError, nrows,
OCI_FETCH_NEXT,
OCI_DEFAULT);
if ((statement->error == OCI_NO_DATA) || (nrows == 0)) {
/* XXX this is needed for REFCURSORS! */
if (statement->columns) {
zend_hash_destroy(statement->columns);
1999-05-12 22:28:01 +08:00
efree(statement->columns);
statement->columns = 0;
}
statement->executed = 0;
statement->error = 0; /* OCI_NO_DATA is NO error for us!!! */
1999-04-22 06:49:16 +08:00
return 0;
}
while (statement->error == OCI_NEED_DATA) {
for (i = 0; i < statement->ncolumns; i++) {
column = oci_get_col(statement, i + 1, 0);
if (column->piecewise) {
if (! column->data) {
column->data = (text *) emalloc(OCI_PIECE_SIZE);
} else {
column->data = erealloc(column->data,column->retlen4 + OCI_PIECE_SIZE);
}
column->cb_retlen = OCI_PIECE_SIZE;
OCIStmtSetPieceInfo((void *) column->pDefine,
OCI_HTYPE_DEFINE,
statement->pError,
((char*)column->data) + column->retlen4,
&(column->cb_retlen),
OCI_NEXT_PIECE,
NULL,
NULL);
}
}
statement->error =
OCIStmtFetch(statement->pStmt,
statement->pError, nrows,
OCI_FETCH_NEXT,
OCI_DEFAULT);
for (i = 0; i < statement->ncolumns; i++) {
column = oci_get_col(statement, i + 1, 0);
if (column->piecewise) {
column->retlen4 += column->cb_retlen;
}
}
}
1999-05-12 22:28:01 +08:00
if (statement->error == OCI_SUCCESS_WITH_INFO || statement->error == OCI_SUCCESS) {
1999-04-22 06:49:16 +08:00
/* do the stuff needed for OCIDefineByName */
for (i = 0; i < statement->ncolumns; i++) {
column = oci_get_col(statement, i + 1, 0);
1999-04-22 06:49:16 +08:00
if (column == NULL) { /* should not happen... */
continue;
}
1999-06-09 18:40:08 +08:00
if (! column->define) {
continue;
}
1999-07-12 18:36:19 +08:00
1999-09-13 19:13:53 +08:00
pval_destructor(column->define->pval);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
oci_make_pval(column->define->pval,statement,column,"OCIFetch",0);
1999-04-22 06:49:16 +08:00
}
return 1;
}
1999-08-17 21:54:25 +08:00
oci_error(statement->pError, func, statement->error);
1999-04-22 06:49:16 +08:00
return 0;
}
/* }}} */
/* {{{ oci_loadlob() */
1999-04-22 06:49:16 +08:00
static ub4
oci_loadlob(oci_connection *connection, oci_descriptor *mydescr, char **buffer)
1999-04-22 06:49:16 +08:00
{
ub4 loblen;
1999-05-12 22:28:01 +08:00
connection->error =
OCILobGetLength(connection->pServiceContext,
connection->pError,
mydescr->ocidescr,
&loblen);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCILobGetLength", connection->error);
return -1;
1999-04-22 06:49:16 +08:00
}
*buffer = emalloc(loblen + 1);
if (! buffer) {
return -1;
}
if (loblen == 0) {
(*buffer)[ 0 ] = 0;
1999-04-22 06:49:16 +08:00
return 0;
}
if (mydescr->type == OCI_DTYPE_FILE) {
1999-05-12 22:28:01 +08:00
connection->error =
OCILobFileOpen(connection->pServiceContext,
connection->pError,
mydescr->ocidescr,
OCI_FILE_READONLY);
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCILobFileOpen",connection->error);
1999-04-22 06:49:16 +08:00
efree(buffer);
return -1;
1999-04-22 06:49:16 +08:00
}
}
1999-05-12 22:28:01 +08:00
connection->error =
OCILobRead(connection->pServiceContext,
connection->pError,
mydescr->ocidescr,
&loblen, /* IN/OUT bytes toread/read */
1, /* offset (starts with 1) */
(dvoid *) *buffer,
loblen, /* size of buffer */
(dvoid *)0,
(OCICallbackLobRead) 0, /* callback... */
(ub2) 0, /* The character set ID of the buffer data. */
(ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCILobRead", connection->error);
1999-04-22 06:49:16 +08:00
efree(buffer);
return -1;
1999-04-22 06:49:16 +08:00
}
if (mydescr->type == OCI_DTYPE_FILE) {
1999-05-12 22:28:01 +08:00
connection->error =
OCILobFileClose(connection->pServiceContext,
connection->pError,
mydescr->ocidescr);
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCILobFileClose", connection->error);
1999-04-22 06:49:16 +08:00
efree(buffer);
return -1;
1999-04-22 06:49:16 +08:00
}
}
(*buffer)[ loblen ] = 0;
oci_debug("OCIloadlob: size=%d",loblen);
1999-04-22 06:49:16 +08:00
return loblen;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_failover_callback() */
1999-05-12 22:28:01 +08:00
#if 0 /* not needed yet ! */
static sb4
1999-08-17 21:54:25 +08:00
oci_failover_callback(dvoid *svchp,
dvoid* envhp,
dvoid *fo_ctx,
ub4 fo_type,
ub4 fo_event)
{
/*
this stuff is from an oci sample - it will get cleaned up as soon as i understand it!!! (thies@digicol.de 990420)
right now i cant get oracle to even call it;-(((((((((((
*/
switch (fo_event)
{
case OCI_FO_BEGIN:
{
printf(" Failing Over ... Please stand by \n");
printf(" Failover type was found to be %s \n",
((fo_type==OCI_FO_NONE) ? "NONE"
:(fo_type==OCI_FO_SESSION) ? "SESSION"
:(fo_type==OCI_FO_SELECT) ? "SELECT"
: "UNKNOWN!"));
printf(" Failover Context is :%s\n",
(fo_ctx?(char *)fo_ctx:"NULL POINTER!"));
break;
}
case OCI_FO_ABORT:
{
printf(" Failover aborted. Failover will not take place.\n");
break;
}
case OCI_FO_END:
{
printf(" Failover ended ...resuming services\n");
break;
}
case OCI_FO_REAUTH:
{
printf(" Failed over user. Resuming services\n");
/* Application can check the OCI_ATTR_SESSION attribute of
the service handle to find out the user being
re-authenticated.
After this, the application can replay any ALTER SESSION
commands associated with this session. These must have
been saved by the application in the fo_ctx
*/
break;
}
case OCI_FO_ERROR:
{
printf(" Failover error gotten. Sleeping...\n");
sleep(3);
/* cannot find this blody define !!! return OCI_FO_RETRY; */
break;
}
default:
{
printf("Bad Failover Event: %ld.\n", fo_event);
break;
}
}
return 0;
}
1999-05-12 22:28:01 +08:00
#endif
1999-04-22 06:49:16 +08:00
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_bind_in_callback() */
1999-04-22 06:49:16 +08:00
static sb4
1999-08-17 21:54:25 +08:00
oci_bind_in_callback(dvoid *ictxp, /* context pointer */
1999-04-22 06:49:16 +08:00
OCIBind *bindp, /* bind handle */
ub4 iter, /* 0-based execute iteration value */
ub4 index, /* index of current array for PL/SQL or
row index for SQL */
dvoid **bufpp, /* pointer to data */
ub4 *alenp, /* size after value/piece has been read */
ub1 *piecep, /* which piece */
dvoid **indpp) /* indicator value */
{
1999-08-17 21:54:25 +08:00
oci_bind *phpbind;
1999-04-22 06:49:16 +08:00
pval *val;
1999-08-17 21:54:25 +08:00
phpbind = (oci_bind *)ictxp;
1999-04-22 06:49:16 +08:00
if (!phpbind || !(val = phpbind->value)) {
php_error(E_WARNING, "!phpbind || !phpbind->val");
1999-04-22 06:49:16 +08:00
return OCI_ERROR;
}
1999-05-12 22:28:01 +08:00
if ((phpbind->descr == 0) && (phpbind->pStmt == 0)) { /* "normal string bind */
1999-04-22 06:49:16 +08:00
convert_to_string(val);
*bufpp = val->value.str.val;
*alenp = phpbind->maxsize;
*indpp = (dvoid *)&phpbind->indicator;
1999-05-12 22:28:01 +08:00
} else if (phpbind->pStmt != 0) {
*bufpp = phpbind->pStmt;
*alenp = -1; /* seems to be allright */
*indpp = (dvoid *)&phpbind->indicator;
} else { /* descriptor bind */
1999-04-22 06:49:16 +08:00
*bufpp = phpbind->descr;
*alenp = -1; /* seems to be allright */
*indpp = (dvoid *)&phpbind->indicator;
}
*piecep = OCI_ONE_PIECE; /* pass all data in one go */
return OCI_CONTINUE;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_bind_out_callback() */
1999-04-22 06:49:16 +08:00
static sb4
1999-08-17 21:54:25 +08:00
oci_bind_out_callback(dvoid *ctxp, /* context pointer */
1999-04-22 06:49:16 +08:00
OCIBind *bindp, /* bind handle */
ub4 iter, /* 0-based execute iteration value */
ub4 index, /* index of current array for PL/SQL or
row index for SQL */
dvoid **bufpp, /* pointer to data */
ub4 **alenpp, /* size after value/piece has been read */
ub1 *piecep, /* which piece */
dvoid **indpp, /* indicator value */
ub2 **rcodepp) /* return code */
{
1999-08-17 21:54:25 +08:00
oci_bind *phpbind;
1999-04-22 06:49:16 +08:00
pval *val;
1999-08-17 21:54:25 +08:00
phpbind = (oci_bind *)ctxp;
1999-04-22 06:49:16 +08:00
if (!phpbind) {
1999-08-17 21:54:25 +08:00
oci_debug("oci_bind_out_callback: phpbind = NULL");
1999-04-22 06:49:16 +08:00
return OCI_ERROR;
}
val = phpbind->value;
if (val == NULL) {
1999-08-17 21:54:25 +08:00
oci_debug("oci_bind_out_callback: phpbind->value = NULL");
1999-04-22 06:49:16 +08:00
return OCI_ERROR;
}
/* XXX risky, if the variable has been freed, nasty things
* could happen here.
*/
if (val->type == IS_OBJECT) {
} else if (val->type == IS_STRING) {
STR_FREE(val->value.str.val);
phpbind->value->value.str.len = phpbind->maxsize;
phpbind->value->value.str.val = emalloc(phpbind->maxsize);
1999-08-17 21:54:25 +08:00
oci_debug("oci_bind_out_callback: maxlen=%d",phpbind->maxsize);
1999-04-22 06:49:16 +08:00
*alenpp = (ub4*) &phpbind->value->value.str.len; /* XXX we assume that php-pval len has 4 bytes */
*bufpp = phpbind->value->value.str.val;
*piecep = OCI_ONE_PIECE;
*rcodepp = &phpbind->retcode;
*indpp = &phpbind->indicator;
}
return OCI_CONTINUE;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_open_user()
1999-04-22 06:49:16 +08:00
*/
1999-08-17 21:54:25 +08:00
static oci_session *oci_open_user(oci_server* server,char *username,char *password,int persistent,int exclusive)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_session *session = 0;
1999-04-22 06:49:16 +08:00
OCISvcCtx *svchp = 0;
1999-05-12 22:28:01 +08:00
char *hashed_details;
1999-04-22 06:49:16 +08:00
int hashed_details_length;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
/*
check if we already have this user authenticated
we will reuse authenticated users within a request no matter if the user requested a persistent
connections or not!
but only as pesistent requested connections will be kept between requests!
*/
hashed_details_length = strlen(SAFE_STRING(username))+
1999-04-22 06:49:16 +08:00
strlen(SAFE_STRING(password))+
strlen(SAFE_STRING(server->dbname));
1999-05-12 22:28:01 +08:00
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"%s%s%s",
1999-04-22 06:49:16 +08:00
SAFE_STRING(username),
SAFE_STRING(password),
SAFE_STRING(server->dbname));
1999-05-12 22:28:01 +08:00
if (! exclusive) {
1999-08-17 21:54:25 +08:00
zend_hash_find(OCI(user), hashed_details, hashed_details_length+1, (void **) &session);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (session) {
if (session->open) {
if (persistent) {
session->persistent = 1;
}
efree(hashed_details);
return session;
} else {
1999-08-17 21:54:25 +08:00
_oci_close_user(session);
1999-05-12 22:28:01 +08:00
/* breakthru to open */
}
}
1999-04-22 06:49:16 +08:00
}
1999-08-17 21:54:25 +08:00
session = calloc(1,sizeof(oci_session));
1999-04-22 06:49:16 +08:00
if (! session) {
goto CLEANUP;
}
session->persistent = persistent;
session->server = server;
/* allocate temporary Service Context */
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIHandleAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid **)&svchp,
OCI_HTYPE_SVCCTX,
0,
NULL);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "oci_open_user: OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* allocate private session-handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIHandleAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid **)&session->pSession,
OCI_HTYPE_SESSION,
0,
NULL);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "oci_open_user: OCIHandleAlloc OCI_HTYPE_SESSION", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* Set the server handle in service handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIAttrSet(svchp,
OCI_HTYPE_SVCCTX,
server->pServer,
0,
OCI_ATTR_SERVER,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "oci_open_user: OCIAttrSet OCI_ATTR_SERVER", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* set the username in user handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIAttrSet((dvoid *) session->pSession,
(ub4) OCI_HTYPE_SESSION,
(dvoid *) username,
(ub4) strlen(username),
(ub4) OCI_ATTR_USERNAME,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "OCIAttrSet OCI_ATTR_USERNAME", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* set the password in user handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIAttrSet((dvoid *) session->pSession,
(ub4) OCI_HTYPE_SESSION,
(dvoid *) password,
(ub4) strlen(password),
(ub4) OCI_ATTR_PASSWORD,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "OCIAttrSet OCI_ATTR_PASSWORD", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCISessionBegin(svchp,
1999-08-17 21:54:25 +08:00
OCI(pError),
1999-05-12 22:28:01 +08:00
session->pSession,
(ub4) OCI_CRED_RDBMS,
(ub4) OCI_DEFAULT);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "OCISessionBegin", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* Free Temporary Service Context */
OCIHandleFree((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX);
1999-08-17 21:54:25 +08:00
session->num = OCI(user_num)++;
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
session->open = 1;
1999-08-17 21:54:25 +08:00
oci_debug("oci_open_user new sess=%d user=%s",session->num,username);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (exclusive) {
1999-08-17 21:54:25 +08:00
zend_hash_next_index_pointer_insert(OCI(user),
1999-05-12 22:28:01 +08:00
(void *) session);
} else {
1999-08-17 21:54:25 +08:00
zend_hash_pointer_update(OCI(user),
1999-05-12 22:28:01 +08:00
hashed_details,
hashed_details_length+1,
(void *) session);
}
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
efree(hashed_details);
1999-04-22 06:49:16 +08:00
return session;
CLEANUP:
1999-08-17 21:54:25 +08:00
oci_debug("oci_open_user: FAILURE -> CLEANUP called");
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (hashed_details) {
efree(hashed_details);
}
1999-08-17 21:54:25 +08:00
_oci_close_user(session);
1999-04-22 06:49:16 +08:00
return 0;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ _oci_close_user()
1999-04-22 06:49:16 +08:00
*/
static void
1999-08-17 21:54:25 +08:00
_oci_close_user(oci_session *session)
1999-04-22 06:49:16 +08:00
{
OCISvcCtx *svchp;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
if (! session) {
return;
}
1999-08-17 21:54:25 +08:00
oci_debug("_oci_close_user: logging-off sess=%d",session->num);
if (session->open) {
/* Temporary Service Context */
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIHandleAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid **) &svchp,
(ub4) OCI_HTYPE_SVCCTX,
(size_t) 0,
(dvoid **) 0);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "_oci_close_user OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI(error));
}
/* Set the server handle in service handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIAttrSet(svchp,
OCI_HTYPE_SVCCTX,
session->server->pServer,
0,
OCI_ATTR_SERVER,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "_oci_close_user: OCIAttrSet OCI_ATTR_SERVER", OCI(error));
}
/* Set the Authentication handle in the service handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIAttrSet(svchp,
OCI_HTYPE_SVCCTX,
session->pSession,
0,
OCI_ATTR_SESSION,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "_oci_close_user: OCIAttrSet OCI_ATTR_SESSION", OCI(error));
}
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCISessionEnd(svchp,
1999-08-17 21:54:25 +08:00
OCI(pError),
1999-05-12 22:28:01 +08:00
session->pSession,
(ub4) 0);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "_oci_close_user: OCISessionEnd", OCI(error));
}
} else {
1999-08-17 21:54:25 +08:00
oci_debug("_oci_close_user: logging-off DEAD session");
}
OCIHandleFree((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX);
1999-05-12 22:28:01 +08:00
if (session->pSession) {
OCIHandleFree((dvoid *) session->pSession, (ub4) OCI_HTYPE_SESSION);
}
1999-05-12 22:28:01 +08:00
free(session);
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-09-13 19:13:53 +08:00
/* {{{ _oci_descr_dtor()
1999-04-22 06:49:16 +08:00
*/
1999-07-12 18:36:19 +08:00
static int
1999-09-13 19:13:53 +08:00
_oci_descr_dtor(void *data)
1999-04-22 06:49:16 +08:00
{
1999-09-13 19:13:53 +08:00
oci_descriptor *descr = (oci_descriptor *) data;
1999-09-29 21:35:12 +08:00
oci_debug("_oci_descr_dtor: %x",descr->ocidescr);
1999-04-22 06:49:16 +08:00
OCIDescriptorFree(descr->ocidescr, descr->type);
1999-07-12 18:36:19 +08:00
return 1;
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_open_server()
1999-04-22 06:49:16 +08:00
*/
1999-08-17 21:54:25 +08:00
static oci_server *oci_open_server(char *dbname,int persistent)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_server *server = 0;
1999-05-12 22:28:01 +08:00
char *hashed_details;
1999-04-22 06:49:16 +08:00
int hashed_details_length;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
/*
check if we already have this server open
we will reuse servers within a request no matter if the usere requested persistent
connections or not!
but only as pesistent requested connections will be kept between requests!
*/
hashed_details_length = strlen(SAFE_STRING((char *)dbname));
1999-05-12 22:28:01 +08:00
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"%s",SAFE_STRING((char *)dbname));
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
zend_hash_find(OCI(server), hashed_details, hashed_details_length+1, (void **) &server);
1999-04-22 06:49:16 +08:00
if (server) {
if (server->open) {
/* if our new users uses this connection persistent, we're keeping it! */
if (persistent) {
server->persistent = persistent;
}
1999-05-12 22:28:01 +08:00
efree(hashed_details);
return server;
} else { /* server "died" in the meantime - try to reconnect! */
1999-08-17 21:54:25 +08:00
_oci_close_server(server);
/* breakthru to open */
}
1999-04-22 06:49:16 +08:00
}
1999-08-17 21:54:25 +08:00
server = calloc(1,sizeof(oci_server));
1999-04-22 06:49:16 +08:00
if (! server) {
goto CLEANUP;
}
server->persistent = persistent;
1999-05-12 22:28:01 +08:00
server->dbname = strdup(SAFE_STRING(dbname));
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCIHandleAlloc(OCI(pEnv),
1999-04-22 06:49:16 +08:00
(dvoid **)&server->pServer,
OCI_HTYPE_SERVER,
0,
NULL);
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIServerAttach(server->pServer,
1999-08-17 21:54:25 +08:00
OCI(pError),
1999-06-09 18:40:08 +08:00
(text*)dbname,
1999-05-12 22:28:01 +08:00
strlen(dbname),
(ub4) OCI_DEFAULT);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
if (OCI(error)) {
oci_error(OCI(pError), "oci_open_server", OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
1999-08-17 21:54:25 +08:00
server->num = OCI(server_num)++;
1999-05-12 22:28:01 +08:00
server->open = 1;
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
#if 0
server->failover.fo_ctx = (dvoid *) server;
1999-08-17 21:54:25 +08:00
server->failover.callback_function = oci_failover_callback;
1999-04-22 06:49:16 +08:00
error = OCIAttrSet((dvoid *)server->pServer,
(ub4) OCI_HTYPE_SERVER,
(dvoid *) &server->failover,
(ub4) 0,
(ub4) OCI_ATTR_FOCBK,
1999-08-17 21:54:25 +08:00
OCI(pError));
if (error) {
1999-08-17 21:54:25 +08:00
oci_error(OCI(pError), "oci_open_server OCIAttrSet OCI_ATTR_FOCBK", error);
goto CLEANUP;
1999-04-22 06:49:16 +08:00
}
1999-05-12 22:28:01 +08:00
#endif
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
oci_debug("oci_open_server new conn=%d dname=%s",server->num,server->dbname);
1999-08-17 21:54:25 +08:00
zend_hash_pointer_update(OCI(server),
1999-05-12 22:28:01 +08:00
hashed_details,
hashed_details_length+1,
(void *) server);
efree(hashed_details);
1999-04-22 06:49:16 +08:00
return server;
CLEANUP:
1999-08-17 21:54:25 +08:00
oci_debug("oci_open_server: FAILURE -> CLEANUP called");
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (hashed_details) {
efree(hashed_details);
}
1999-08-17 21:54:25 +08:00
_oci_close_server(server);
1999-04-22 06:49:16 +08:00
return 0;
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ _oci_close_server()
1999-04-22 06:49:16 +08:00
*/
static void
1999-08-17 21:54:25 +08:00
_oci_close_server(oci_server *server)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
if (! server) {
return;
}
1999-08-17 21:54:25 +08:00
oci_debug("_oci_close_server: detaching conn=%d dbname=%s",server->num,server->dbname);
/* XXX close server here */
if (server->open) {
1999-08-17 21:54:25 +08:00
if (server->pServer && OCI(pError)) {
1999-11-12 22:34:50 +08:00
#if 0 && APACHE
void (*handler) (int);
handler = signal(SIGCHLD, SIG_DFL);
#endif
1999-08-17 21:54:25 +08:00
OCI(error) =
1999-05-12 22:28:01 +08:00
OCIServerDetach(server->pServer,
1999-08-17 21:54:25 +08:00
OCI(pError),
1999-05-12 22:28:01 +08:00
OCI_DEFAULT);
1999-11-12 22:34:50 +08:00
#if 0 && APACHE
signal(SIGCHLD,handler);
#endif
1999-08-17 21:54:25 +08:00
if (OCI(error)) {
oci_error(OCI(pError), "oci_close_server OCIServerDetach", OCI(error));
}
}
} else {
1999-08-19 12:13:56 +08:00
oci_debug("_oci_close_server: closing DEAD server");
}
1999-05-12 22:28:01 +08:00
if (server->pServer) {
OCIHandleFree((dvoid *) server->pServer, (ub4) OCI_HTYPE_SERVER);
1999-05-12 22:28:01 +08:00
}
1999-05-12 22:28:01 +08:00
if (server->dbname) {
free(server->dbname);
}
free(server);
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-08-17 21:54:25 +08:00
/* {{{ oci_do_connect()
1999-04-22 06:49:16 +08:00
Connect to an Oracle database and log on. returns a new session.
*/
1999-08-17 21:54:25 +08:00
static void oci_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent,int exclusive)
1999-04-22 06:49:16 +08:00
{
1999-06-09 18:40:08 +08:00
char *username, *password, *dbname;
pval **userParam, **passParam, **dbParam;
1999-08-17 21:54:25 +08:00
oci_server *server = 0;
oci_session *session = 0;
oci_connection *connection = 0;
OCILS_FETCH();
if (getParametersEx(3, &userParam, &passParam, &dbParam) == SUCCESS) {
convert_to_string_ex(userParam);
convert_to_string_ex(passParam);
convert_to_string_ex(dbParam);
username = (*userParam)->value.str.val;
password = (*passParam)->value.str.val;
dbname = (*dbParam)->value.str.val;
} else if (getParametersEx(2, &userParam, &passParam) == SUCCESS) {
convert_to_string_ex(userParam);
convert_to_string_ex(passParam);
username = (*userParam)->value.str.val;
password = (*passParam)->value.str.val;
1999-06-09 18:40:08 +08:00
dbname = "";
1999-04-22 06:49:16 +08:00
} else {
WRONG_PARAM_COUNT;
}
1999-08-17 21:54:25 +08:00
connection = (oci_connection *) ecalloc(1,sizeof(oci_connection));
1999-04-22 06:49:16 +08:00
if (! connection) {
goto CLEANUP;
}
1999-08-17 21:54:25 +08:00
server = oci_open_server(dbname,persistent);
1999-04-22 06:49:16 +08:00
if (! server) {
goto CLEANUP;
}
persistent = server->persistent; /* if our server-context is not persistent we can't */
1999-08-17 21:54:25 +08:00
session = oci_open_user(server,username,password,persistent,exclusive);
1999-04-22 06:49:16 +08:00
if (! session) {
goto CLEANUP;
}
/* set our session */
connection->session = session;
/* allocate our private error-handle */
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIHandleAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid **)&connection->pError,
OCI_HTYPE_ERROR,
0,
NULL);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "oci_do_connect: OCIHandleAlloc OCI_HTYPE_ERROR",OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* allocate our service-context */
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIHandleAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid **)&connection->pServiceContext,
OCI_HTYPE_SVCCTX,
0,
NULL);
1999-08-17 21:54:25 +08:00
if (OCI(error) != OCI_SUCCESS) {
oci_error(OCI(pError), "oci_do_connect: OCIHandleAlloc OCI_HTYPE_SVCCTX",OCI(error));
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/* Set the server handle in service handle */
1999-05-12 22:28:01 +08:00
connection->error =
OCIAttrSet(connection->pServiceContext,
OCI_HTYPE_SVCCTX,
server->pServer,
0,
OCI_ATTR_SERVER,
connection->pError);
if (connection->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "oci_do_connect: OCIAttrSet OCI_ATTR_SERVER", connection->error);
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
1999-05-12 22:28:01 +08:00
/* Set the Authentication handle in the service handle */
connection->error =
OCIAttrSet(connection->pServiceContext,
OCI_HTYPE_SVCCTX,
session->pSession,
0,
OCI_ATTR_SESSION,
connection->pError);
if (connection->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "oci_do_connect: OCIAttrSet OCI_ATTR_SESSION", connection->error);
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
/*
OCIAttrSet((dvoid *)session->server->pServer,
OCI_HTYPE_SERVER,
(dvoid *) "demo",
0,
OCI_ATTR_EXTERNAL_NAME,
connection->pError);
OCIAttrSet((dvoid *)session->server->pServer,
OCI_HTYPE_SERVER,
(dvoid *) "txn demo2",
0,
OCI_ATTR_INTERNAL_NAME,
connection->pError);
*/
connection->id = zend_list_insert(connection, le_conn);
1999-04-22 06:49:16 +08:00
connection->descriptors = emalloc(sizeof(HashTable));
if (!connection->descriptors ||
1999-09-13 19:13:53 +08:00
zend_hash_init(connection->descriptors, 13, NULL, _oci_descr_dtor, 0) == FAILURE) {
1999-04-22 06:49:16 +08:00
goto CLEANUP;
}
connection->open = 1;
1999-08-17 21:54:25 +08:00
oci_debug("oci_do_connect: id=%d",connection->id);
1999-04-22 06:49:16 +08:00
RETURN_RESOURCE(connection->id);
1999-07-08 22:12:07 +08:00
1999-04-22 06:49:16 +08:00
CLEANUP:
1999-08-17 21:54:25 +08:00
oci_debug("oci_do_connect: FAILURE -> CLEANUP called");
if (connection->id) {
zend_list_delete(connection->id);
} else {
1999-09-29 21:35:12 +08:00
_oci_connection_dtor(connection);
}
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
/* }}} */
/************************* EXTENSION FUNCTIONS *************************/
/* {{{ proto int OCIDefineByName(int stmt, string name, mixed &var [,int type])
Define a PHP variable to an Oracle column by name.
if you want to define a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE defining!!!
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocidefinebyname)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **name, **var, **type;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_define *define, *tmp_define;
ub2 ocitype = SQLT_STR; /* zero terminated string */
int ac = ARG_COUNT(ht);
1999-04-22 06:49:16 +08:00
if (ac < 3 || ac > 4 || getParametersEx(ac, &stmt, &name, &var, &type) == FAILURE) {
WRONG_PARAM_COUNT;
}
1999-04-22 06:49:16 +08:00
switch (ac) {
case 4:
convert_to_long_ex(type);
ocitype = (ub2) (*type)->value.lval;
/* possible breakthru */
1999-04-22 06:49:16 +08:00
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
convert_to_string_ex(name);
1999-04-22 06:49:16 +08:00
if (statement->defines == NULL) {
statement->defines = emalloc(sizeof(HashTable));
zend_hash_init(statement->defines, 13, NULL, _oci_define_dtor, 0);
1999-04-22 06:49:16 +08:00
}
define = ecalloc(1,sizeof(oci_define));
if (zend_hash_add(statement->defines,
(*name)->value.str.val,
(*name)->value.str.len,
define,
sizeof(oci_define),
(void **)&tmp_define) == SUCCESS) {
1999-04-22 06:49:16 +08:00
efree(define);
define = tmp_define;
} else {
1999-12-04 20:06:32 +08:00
efree(define);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
define->name = (text*) estrndup((*name)->value.str.val,(*name)->value.str.len);
define->name_len = (*name)->value.str.len;
1999-04-22 06:49:16 +08:00
define->type = ocitype;
define->pval = *var;
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int OCIBindByName(int stmt, string name, mixed &var, int maxlength [,int type])
Bind a PHP variable to an Oracle placeholder by name.
if you want to bind a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE binding!!!
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocibindbyname)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **name, **var, **maxlen, **type, **tmp;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_statement *bindstmt;
oci_bind *bind, *tmp_bind;
oci_descriptor *descr;
ub2 ocitype = SQLT_STR; /* zero terminated string */
1999-04-22 06:49:16 +08:00
sb4 ocimaxlen;
1999-05-12 22:28:01 +08:00
OCIStmt *mystmt = 0;
1999-04-22 06:49:16 +08:00
dvoid *mydescr = 0;
int ac = ARG_COUNT(ht);
1999-04-22 06:49:16 +08:00
if (ac < 4 || ac > 5 || getParametersEx(ac, &stmt, &name, &var, &maxlen, &type) == FAILURE) {
WRONG_PARAM_COUNT;
}
1999-04-22 06:49:16 +08:00
switch (ac) {
case 5:
convert_to_long_ex(type);
ocitype = (*type)->value.lval;
/* possible breakthru */
1999-04-22 06:49:16 +08:00
}
convert_to_long_ex(maxlen);
ocimaxlen = (*maxlen)->value.lval;
1999-04-22 06:49:16 +08:00
OCI_GET_STMT(statement,stmt);
switch ((*var)->type) {
1999-04-22 06:49:16 +08:00
case IS_OBJECT :
if (zend_hash_find((*var)->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor property");
RETURN_FALSE;
1999-04-22 06:49:16 +08:00
}
if (zend_hash_index_find(statement->conn->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor");
RETURN_FALSE;
1999-04-22 06:49:16 +08:00
}
1999-04-22 06:49:16 +08:00
mydescr = (dvoid *) descr->ocidescr;
1999-04-22 06:49:16 +08:00
if (! mydescr) {
RETURN_FALSE;
1999-04-22 06:49:16 +08:00
}
break;
default:
1999-05-12 22:28:01 +08:00
if (ocitype == SQLT_RSET) { /* refcursor binding */
OCI_GET_STMT(bindstmt,var);
1999-05-12 22:28:01 +08:00
ocimaxlen = 0;
mystmt = bindstmt->pStmt;
} else { /* everything else is now handled as a string */
convert_to_string_ex(var);
1999-05-12 22:28:01 +08:00
if (ocimaxlen == -1) {
if ((*var)->value.str.len == 0) {
php_error(E_WARNING, "OCIBindByName bindlength is 0");
1999-05-12 22:28:01 +08:00
}
1999-06-09 18:40:08 +08:00
if (ocitype == SQLT_BIN) {
ocimaxlen = (*var)->value.str.len;
1999-06-09 18:40:08 +08:00
} else {
ocimaxlen = (*var)->value.str.len + 1;
1999-06-09 18:40:08 +08:00
/* SQLT_STR needs a trailing 0 - maybe we need to resize the var buffers????? */
}
1999-04-22 06:49:16 +08:00
}
}
break;
}
convert_to_string_ex(name);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
bind = ecalloc(1,sizeof(oci_bind));
1999-04-22 06:49:16 +08:00
if (statement->binds == NULL) {
statement->binds = emalloc(sizeof(HashTable));
zend_hash_init(statement->binds, 13, NULL, NULL, 0);
1999-04-22 06:49:16 +08:00
}
if (zend_hash_next_index_insert(statement->binds, bind,
sizeof(oci_bind),
(void **)&tmp_bind) == SUCCESS) {
1999-04-22 06:49:16 +08:00
efree(bind);
bind = tmp_bind;
}
bind->value = *var;
1999-04-22 06:49:16 +08:00
bind->descr = mydescr;
1999-05-12 22:28:01 +08:00
bind->pStmt = mystmt;
1999-04-22 06:49:16 +08:00
bind->maxsize = ocimaxlen;
1999-05-12 22:28:01 +08:00
statement->error =
OCIBindByName(statement->pStmt, /* statement handle */
(OCIBind **)&bind->pBind, /* bind hdl (will alloc) */
statement->pError, /* error handle */
(text*) (*name)->value.str.val, /* placeholder name */
(*name)->value.str.len, /* placeholder length */
1999-05-12 22:28:01 +08:00
(dvoid *)0, /* in/out data */
ocimaxlen, /* max size of input/output data */
(ub2)ocitype, /* in/out data type */
(dvoid *)&bind->indicator, /* indicator (ignored) */
(ub2 *)0, /* size array (ignored) */
(ub2 *)&bind->retcode, /* return code (ignored) */
(ub4)0, /* maxarr_len (PL/SQL only?) */
(ub4 *)0, /* actual array size (PL/SQL only?) */
OCI_DATA_AT_EXEC /* mode */);
if (statement->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(statement->pError, "OCIBindByName", statement->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
1999-05-12 22:28:01 +08:00
statement->error =
OCIBindDynamic(bind->pBind,
statement->pError,
(dvoid *)bind,
1999-08-17 21:54:25 +08:00
oci_bind_in_callback,
1999-05-12 22:28:01 +08:00
(dvoid *)bind,
1999-08-17 21:54:25 +08:00
oci_bind_out_callback);
1999-05-12 22:28:01 +08:00
if (statement->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(statement->pError, "OCIBindDynamic", statement->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string ocifreedesc(object lob)
*/
PHP_FUNCTION(ocifreedesc)
1999-04-22 06:49:16 +08:00
{
pval *id, **conn, **desc;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
1999-04-22 06:49:16 +08:00
1999-07-12 19:49:32 +08:00
if ((id = getThis()) != 0) {
if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
php_error(E_WARNING, "unable to find my statement property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&desc) == FAILURE) {
php_error(E_WARNING, "unable to find my locator property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
oci_debug("OCOfreedesc: descr=%d",(*desc)->value.lval);
1999-04-22 06:49:16 +08:00
zend_hash_index_del(connection->descriptors,(*desc)->value.lval);
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string ocisavelob(object lob)
1999-04-22 06:49:16 +08:00
*/
PHP_FUNCTION(ocisavelob)
1999-04-22 06:49:16 +08:00
{
pval *id, **tmp, **conn, **arg,**oarg;
1999-04-22 06:49:16 +08:00
OCILobLocator *mylob;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
oci_descriptor *descr;
int offparam;
1999-04-22 06:49:16 +08:00
ub4 loblen;
ub4 curloblen;
ub4 offset;
1999-04-22 06:49:16 +08:00
1999-07-12 19:49:32 +08:00
if ((id = getThis()) != 0) {
if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
php_error(E_WARNING, "unable to find my statement property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
php_error(E_WARNING, "unable to find my locator property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
if (zend_hash_index_find(connection->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor %d",(*tmp)->value.lval);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
mylob = (OCILobLocator *) descr->ocidescr;
if (! mylob) {
RETURN_FALSE;
}
offset = 0;
if (getParametersEx(2, &arg, &oarg) == SUCCESS) {
convert_to_long_ex(oarg);
offparam = (*oarg)->value.lval;
connection->error =
OCILobGetLength(connection->pServiceContext,
connection->pError,
mylob,
&curloblen);
oci_debug("OCIsavedesc: curloblen=%d",curloblen);
if (offparam == -1) {
offset = curloblen;
} else if (offparam >= curloblen) {
php3_error(E_WARNING, "Offset smaller than current LOB-Size - appending");
offset = curloblen;
} else {
offset = offparam;
}
} else if (getParametersEx(1, &arg) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
offset++;
convert_to_string_ex(arg);
loblen = (*arg)->value.str.len;
1999-04-22 06:49:16 +08:00
if (loblen < 1) {
php3_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
1999-05-12 22:28:01 +08:00
connection->error =
OCILobWrite(connection->pServiceContext,
connection->pError,
mylob,
&loblen,
(ub4) offset,
(dvoid *) (*arg)->value.str.val,
(ub4) loblen,
OCI_ONE_PIECE,
(dvoid *)0,
(OCICallbackLobWrite) 0,
(ub2) 0,
(ub1) SQLCS_IMPLICIT );
oci_debug("OCIsavedesc: size=%d offset=%d",loblen,offset);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCILobWrite", connection->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string ocisavelobfile(object lob)
*/
PHP_FUNCTION(ocisavelobfile)
{
pval *id, **tmp, **conn, **arg;
OCILobLocator *mylob;
oci_connection *connection;
oci_descriptor *descr;
char *filename;
int fp;
char buf[8192];
ub4 offset = 1;
ub4 loblen;
if ((id = getThis()) != 0) {
if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
php_error(E_WARNING, "unable to find my statement property");
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
php_error(E_WARNING, "unable to find my locator property");
RETURN_FALSE;
}
if (zend_hash_index_find(connection->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor %d",(*tmp)->value.lval);
RETURN_FALSE;
}
mylob = (OCILobLocator *) descr->ocidescr;
if (! mylob) {
RETURN_FALSE;
}
if (getParametersEx(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(arg);
if (_php3_check_open_basedir((*arg)->value.str.val)) {
RETURN_FALSE;
}
filename = (*arg)->value.str.val;
if ((fp = open(filename, O_RDONLY)) == -1) {
php_error(E_WARNING, "Can't open file %s", filename);
RETURN_FALSE;
}
while ((loblen = read(fp, &buf, sizeof(buf))) > 0) {
connection->error =
OCILobWrite(connection->pServiceContext,
connection->pError,
mylob,
&loblen,
(ub4) offset,
(dvoid *) &buf,
(ub4) loblen,
OCI_ONE_PIECE,
(dvoid *)0,
(OCICallbackLobWrite) 0,
(ub2) 0,
(ub1) SQLCS_IMPLICIT);
oci_debug("OCIsavelob: size=%d",loblen);
if (connection->error) {
oci_error(connection->pError, "OCILobWrite", connection->error);
close(fp);
RETURN_FALSE;
}
offset += loblen;
}
close(fp);
RETURN_TRUE;
}
RETURN_FALSE;
}
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ proto string ociloadlob(object lob)
1999-04-22 06:49:16 +08:00
*/
PHP_FUNCTION(ociloadlob)
1999-04-22 06:49:16 +08:00
{
pval *id, **tmp, **conn;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
oci_descriptor *descr;
1999-04-22 06:49:16 +08:00
char *buffer;
ub4 loblen;
1999-07-12 19:49:32 +08:00
if ((id = getThis()) != 0) {
if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
php_error(E_WARNING, "unable to find my statement property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
php_error(E_WARNING, "unable to find my locator property");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
if (zend_hash_index_find(connection->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor %d",(*tmp)->value.lval);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
loblen = oci_loadlob(connection,descr,&buffer);
1999-04-22 06:49:16 +08:00
if (loblen >= 0) {
1999-04-22 06:49:16 +08:00
RETURN_STRINGL(buffer,loblen,0);
}
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto void ociwritelobtofile(object lob [,string filename][,int start][,int length])
*/
PHP_FUNCTION(ociwritelobtofile)
{
pval *id, **tmp, **conn, **zfilename, **zstart, **zlength;
char *filename = NULL;
int start = -1;
ub4 length = -1;
oci_connection *connection;
oci_descriptor *descr;
char *buffer;
ub4 loblen;
int ac = ARG_COUNT(ht);
int fp = -1;
OCILobLocator *mylob;
int coffs;
if ((id = getThis()) != 0) {
if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
php_error(E_WARNING, "unable to find my statement property");
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
php_error(E_WARNING, "unable to find my locator property");
RETURN_FALSE;
}
if (zend_hash_index_find(connection->descriptors, (*tmp)->value.lval, (void **)&descr) == FAILURE) {
php_error(E_WARNING, "unable to find my descriptor %d",(*tmp)->value.lval);
RETURN_FALSE;
}
mylob = (OCILobLocator *) descr->ocidescr;
if (! mylob) {
RETURN_FALSE;
}
if (ac < 0 || ac > 3 || getParametersEx(ac, &zfilename, &zstart, &zlength) == FAILURE) {
WRONG_PARAM_COUNT;
}
switch (ac) {
case 3:
convert_to_long_ex(zlength);
length = (*zlength)->value.lval;
case 2:
convert_to_long_ex(zstart);
start = (*zstart)->value.lval;
case 1:
convert_to_string_ex(zfilename);
filename = (*zfilename)->value.str.val;
}
if (filename && *filename) {
if (_php3_check_open_basedir(filename)) {
goto bail;
}
if ((fp = open(filename,O_CREAT|O_TRUNC|O_WRONLY)) == -1) {
php_error(E_WARNING, "Can't create file %s", filename);
goto bail;
}
}
connection->error =
OCILobGetLength(connection->pServiceContext,
connection->pError,
descr->ocidescr,
&loblen);
if (connection->error) {
oci_error(connection->pError, "OCILobGetLength", connection->error);
goto bail;
}
if (descr->type == OCI_DTYPE_FILE) {
connection->error =
OCILobFileOpen(connection->pServiceContext,
connection->pError,
descr->ocidescr,
OCI_FILE_READONLY);
if (connection->error) {
oci_error(connection->pError, "OCILobFileOpen",connection->error);
goto bail;
}
}
if (start == -1) {
start = 0;
}
if (length == -1) {
length = loblen - start;
}
if ((start + length) > loblen) {
length = loblen - start;
}
#define OCI_LOB_READ_BUFFER 128*1024
buffer = emalloc(OCI_LOB_READ_BUFFER);
coffs = start;
oci_debug("ociwritelobtofile(start = %d, length = %d, loblen = %d",start,length,loblen);
while (length > 0) {
ub4 toread;
if (length > OCI_LOB_READ_BUFFER) {
toread = OCI_LOB_READ_BUFFER;
} else {
toread = length;
}
oci_debug("OCILobRead(coffs = %d, toread = %d",coffs,toread);
connection->error =
OCILobRead(connection->pServiceContext,
connection->pError,
descr->ocidescr,
&toread, /* IN/OUT bytes toread/read */
coffs+1, /* offset (starts with 1) */
(dvoid *) buffer,
toread, /* size of buffer */
(dvoid *)0,
(OCICallbackLobRead) 0, /* callback... */
(ub2) 0, /* The character set ID of the buffer data. */
(ub1) SQLCS_IMPLICIT); /* The character set form of the buffer data. */
oci_debug("OCILobRead(read - %d",toread);
if (connection->error) {
oci_error(connection->pError, "OCILobRead", connection->error);
goto bail;
}
if (fp != -1) {
if (write(fp,buffer,toread) != toread) {
php_error(E_WARNING, "cannot write file!");
goto bail;
}
} else {
if (php3_header()) {
PHPWRITE(buffer,toread);
}
}
length -= toread;
coffs += toread;
}
efree(buffer);
buffer = 0;
if (fp != -1) {
close(fp);
fp = 0;
}
if (descr->type == OCI_DTYPE_FILE) {
connection->error =
OCILobFileClose(connection->pServiceContext,
connection->pError,
descr->ocidescr);
if (connection->error) {
oci_error(connection->pError, "OCILobFileClose", connection->error);
goto bail;
}
}
RETURN_TRUE;
}
bail:
if (fp != -1) {
close(fp);
}
if (buffer) {
efree(buffer);
}
RETURN_FALSE;
}
/* }}} */
1999-04-22 06:49:16 +08:00
/* {{{ proto string OCINewDescriptor(int connection [,int type ])
initialize a new empty descriptor LOB/FILE (LOB is default)
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocinewdescriptor)
1999-04-22 06:49:16 +08:00
{
pval **conn, **type;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
oci_descriptor descr;
1999-04-22 06:49:16 +08:00
int mylob;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
descr.type = OCI_DTYPE_LOB;
if (getParametersEx(2, &conn, &type) == SUCCESS) {
convert_to_long_ex(type);
descr.type = (*type)->value.lval;
} else if (getParametersEx(1, &conn) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
switch (descr.type) {
case OCI_DTYPE_FILE:
case OCI_DTYPE_LOB:
case OCI_DTYPE_ROWID:
break;
default:
php_error(E_WARNING, "Unknown descriptor type %d.",descr.type);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
OCI(error) =
OCIDescriptorAlloc(OCI(pEnv),
1999-05-12 22:28:01 +08:00
(dvoid*)&(descr.ocidescr),
descr.type,
(size_t) 0,
(dvoid **) 0);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
if (OCI(error)) {
oci_error(OCI(pError),"OCIDescriptorAlloc %d",OCI(error));
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
1999-08-17 21:54:25 +08:00
zend_hash_index_update(connection->descriptors, connection->descriptors_count,&descr,sizeof(oci_descriptor),NULL);
1999-04-22 06:49:16 +08:00
mylob = connection->descriptors_count++;
1999-08-17 21:54:25 +08:00
oci_debug("OCINewDescriptor: new descriptor for %d -> %x",mylob,descr.ocidescr);
1999-04-22 06:49:16 +08:00
object_init_ex(return_value, oci_lob_class_entry_ptr);
add_property_resource(return_value, "descriptor", (long) mylob);
add_property_resource(return_value, "connection", connection->id);
zend_list_addref(connection->id);
1999-04-22 06:49:16 +08:00
}
/* }}} */
/* {{{ proto string OCIRollback(int conn)
rollback the current context
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocirollback)
1999-04-22 06:49:16 +08:00
{
pval **conn;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &conn) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
connection->error =
OCITransRollback(connection->pServiceContext,
connection->pError,
(ub4)0);
1999-05-12 22:28:01 +08:00
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCIRollback", connection->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string OCICommit(int conn)
commit the current context
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicommit)
1999-04-22 06:49:16 +08:00
{
pval **conn;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &conn) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
connection->error =
OCITransCommit(connection->pServiceContext,
connection->pError,
(ub4)0);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (connection->error) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCICommit", connection->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string OCIColumnName(int stmt, int col)
Tell the name of a column.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicolumnname)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **col;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *outcol;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &stmt, &col) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
outcol = oci_get_col(statement, -1, col);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
RETURN_FALSE;
}
RETURN_STRINGL(outcol->name, outcol->name_len, 1);
}
/* }}} */
/* {{{ proto int OCIColumnSize(int stmt, int col)
Tell the maximum data size of a column.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicolumnsize)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **col;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *outcol;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &stmt, &col) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
outcol = oci_get_col(statement, -1, col);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
RETURN_FALSE;
}
1999-07-08 22:12:07 +08:00
RETURN_LONG(outcol->data_size);
1999-04-22 06:49:16 +08:00
}
/* }}} */
/* {{{ proto mixed OCIColumnType(int stmt, int col)
Tell the data type of a column.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicolumntype)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **col;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *outcol;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &stmt, &col) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
outcol = oci_get_col(statement, -1, col);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
RETURN_FALSE;
}
1999-07-08 22:12:07 +08:00
switch (outcol->data_type) {
1999-04-22 06:49:16 +08:00
case SQLT_DAT:
RETVAL_STRING("DATE",1);
break;
case SQLT_NUM:
RETVAL_STRING("NUMBER",1);
break;
case SQLT_LNG:
RETVAL_STRING("LONG",1);
break;
case SQLT_BIN:
RETVAL_STRING("RAW",1);
break;
case SQLT_LBI:
RETVAL_STRING("LONG RAW",1);
break;
case SQLT_CHR:
RETVAL_STRING("VARCHAR",1);
break;
1999-05-12 22:28:01 +08:00
case SQLT_RSET:
RETVAL_STRING("REFCURSOR",1);
break;
1999-04-22 06:49:16 +08:00
case SQLT_AFC:
RETVAL_STRING("CHAR",1);
break;
case SQLT_BLOB:
RETVAL_STRING("BLOB",1);
break;
case SQLT_CLOB:
RETVAL_STRING("CLOB",1);
break;
case SQLT_BFILE:
RETVAL_STRING("BFILE",1);
break;
case SQLT_RDD:
RETVAL_STRING("ROWID",1);
break;
default:
1999-07-08 22:12:07 +08:00
RETVAL_LONG(outcol->data_type);
1999-04-22 06:49:16 +08:00
}
}
/* }}} */
/* {{{ proto int OCIColumnIsNULL(int stmt, int col)
Tell whether a column is NULL.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicolumnisnull)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **col;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *outcol;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &stmt, &col) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
outcol = oci_get_col(statement, -1, col);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
RETURN_FALSE;
}
if (outcol->indicator == -1) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
1999-11-10 13:50:20 +08:00
/* {{{ proto void OCIDebug(int onoff)
1999-04-22 06:49:16 +08:00
Toggle internal debugging output for the OCI extension.
*/
/* Disables or enables the internal debug output.
* By default it is disabled.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociinternaldebug)
1999-04-22 06:49:16 +08:00
{
pval **arg;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &arg) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
convert_to_long_ex(arg);
OCI(debug_mode) = (*arg)->value.lval;
1999-04-22 06:49:16 +08:00
}
/* }}} */
/* {{{ proto int OCIExecute(int stmt [,int mode])
Execute a parsed statement.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociexecute)
1999-04-22 06:49:16 +08:00
{
pval **stmt,**mode;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
ub4 execmode;
if (getParametersEx(2, &stmt, &mode) == SUCCESS) {
convert_to_long_ex(mode);
execmode = (*mode)->value.lval;
} else if (getParametersEx(1, &stmt) == SUCCESS) {
1999-04-22 06:49:16 +08:00
execmode = OCI_COMMIT_ON_SUCCESS;
} else {
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
if (oci_execute(statement, "OCIExecute",execmode,list)) {
1999-05-12 22:28:01 +08:00
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto int OCICancel(int stmt)
Prepare a new row of data for reading.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocicancel)
1999-05-12 22:28:01 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-05-12 22:28:01 +08:00
if (getParametersEx(1, &stmt) == FAILURE) {
1999-05-12 22:28:01 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-08-17 21:54:25 +08:00
if (oci_fetch(statement, 0, "OCICancel")) {
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto int OCIFetch(int stmt)
Prepare a new row of data for reading.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocifetch)
1999-04-22 06:49:16 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
ub4 nrows = 1; /* only one row at a time is supported for now */
if (getParametersEx(1, &stmt) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-08-17 21:54:25 +08:00
if (oci_fetch(statement, nrows, "OCIFetch")) {
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto int OCIFetchInto(int stmt, array &output [, int mode])
Fetch a row of result data into an array.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocifetchinto)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **array, *element, **fmode;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *column;
1999-04-22 06:49:16 +08:00
ub4 nrows = 1;
int i;
int mode = OCI_NUM;
int ac = ARG_COUNT(ht);
1999-04-22 06:49:16 +08:00
if (ac < 2 || ac > 3 || getParametersEx(ac, &stmt, &array, &fmode) == FAILURE) {
WRONG_PARAM_COUNT;
}
switch (ac) {
case 3:
convert_to_long_ex(fmode);
mode = (*fmode)->value.lval;
/* possible breakthru */
1999-04-22 06:49:16 +08:00
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
if (!oci_fetch(statement, nrows, "OCIFetchInto")) {
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
/*
if we don't want NULL columns back, we need to recreate the array
as it could have a different number of enties for each fetched row
*/
1999-04-22 06:49:16 +08:00
if (! (mode & OCI_RETURN_NULLS)) {
if ((*array)->type == IS_ARRAY) {
1999-04-22 06:49:16 +08:00
/* XXX is that right?? */
zend_hash_destroy((*array)->value.ht);
efree((*array)->value.ht);
var_reset(*array);
1999-04-22 06:49:16 +08:00
}
}
if ((*array)->type != IS_ARRAY) {
pval_destructor(*array);
if (array_init(*array) == FAILURE) {
php_error(E_WARNING, "OCIFetchInto: unable to convert arg 2 to array");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
}
zend_hash_internal_pointer_reset((*array)->value.ht);
1999-08-18 20:51:51 +08:00
1999-04-22 06:49:16 +08:00
for (i = 0; i < statement->ncolumns; i++) {
column = oci_get_col(statement, i + 1, 0);
1999-04-22 06:49:16 +08:00
if (column == NULL) { /* should not happen... */
continue;
}
if ((column->indicator == -1) && ((mode & OCI_RETURN_NULLS) == 0)) {
continue;
}
1999-07-12 19:49:32 +08:00
if ((mode & OCI_NUM) || (! (mode & OCI_ASSOC))) { /* OCI_NUM is default */
MAKE_STD_ZVAL(element);
1999-09-13 19:13:53 +08:00
1999-08-17 21:54:25 +08:00
oci_make_pval(element,statement,column, "OCIFetchInto",mode);
1999-07-12 18:36:19 +08:00
zend_hash_index_update((*array)->value.ht, i, (void *)&element, sizeof(pval*), NULL);
1999-04-22 06:49:16 +08:00
}
if (mode & OCI_ASSOC) {
1999-07-12 19:49:32 +08:00
MAKE_STD_ZVAL(element);
1999-09-13 19:13:53 +08:00
1999-08-17 21:54:25 +08:00
oci_make_pval(element,statement,column, "OCIFetchInto",mode);
zend_hash_update((*array)->value.ht, column->name, column->name_len+1, (void *)&element, sizeof(pval*), NULL);
1999-04-22 06:49:16 +08:00
}
}
RETURN_LONG(statement->ncolumns);
}
/* }}} */
/* {{{ proto int OCIFetchStatement(int stmt, array &output)
Fetch all rows of result data into an array.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocifetchstatement)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **array, *element, **fmode, *tmp;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column **columns;
1999-06-09 18:40:08 +08:00
pval ***outarrs;
1999-04-22 06:49:16 +08:00
ub4 nrows = 1;
int i;
int mode = OCI_NUM;
int rows = 0;
char namebuf[ 128 ];
int ac = ARG_COUNT(ht);
1999-04-22 06:49:16 +08:00
if (ac < 2 || ac > 3 || getParametersEx(ac, &stmt, &array, &fmode) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
switch (ac) {
case 3:
convert_to_long_ex(fmode);
mode = (*fmode)->value.lval;
/* possible breakthru */
1999-04-22 06:49:16 +08:00
}
OCI_GET_STMT(statement,stmt);
pval_destructor(*array);
array_init(*array);
1999-04-22 06:49:16 +08:00
1999-08-17 21:54:25 +08:00
columns = emalloc(statement->ncolumns * sizeof(oci_out_column *));
1999-06-09 18:40:08 +08:00
outarrs = emalloc(statement->ncolumns * sizeof(pval*));
1999-04-22 06:49:16 +08:00
for (i = 0; i < statement->ncolumns; i++) {
columns[ i ] = oci_get_col(statement, i + 1, 0);
1999-04-22 06:49:16 +08:00
1999-07-12 19:49:32 +08:00
MAKE_STD_ZVAL(tmp);
1999-06-09 18:40:08 +08:00
array_init(tmp);
1999-04-22 06:49:16 +08:00
memcpy(namebuf,columns[ i ]->name, columns[ i ]->name_len);
namebuf[ columns[ i ]->name_len ] = 0;
zend_hash_update((*array)->value.ht, namebuf, columns[ i ]->name_len+1, (void *) &tmp, sizeof(pval*), (void **) &(outarrs[ i ]));
1999-04-22 06:49:16 +08:00
}
1999-08-17 21:54:25 +08:00
while (oci_fetch(statement, nrows, "OCIFetchStatement")) {
1999-04-22 06:49:16 +08:00
for (i = 0; i < statement->ncolumns; i++) {
1999-07-12 19:49:32 +08:00
MAKE_STD_ZVAL(element);
1999-09-13 19:13:53 +08:00
1999-08-17 21:54:25 +08:00
oci_make_pval(element,statement,columns[ i ], "OCIFetchStatement",OCI_RETURN_LOBS);
1999-06-09 18:40:08 +08:00
zend_hash_index_update((*(outarrs[ i ]))->value.ht, rows, (void *)&element, sizeof(pval*), NULL);
1999-04-22 06:49:16 +08:00
}
rows++;
}
efree(columns);
efree(outarrs);
RETURN_LONG(rows);
}
/* }}} */
/* {{{ proto int OCIFreeStatement(int stmt)
Free all resources associated with a statement.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocifreestatement)
1999-04-22 06:49:16 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &stmt) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
zend_list_delete(statement->id);
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int OCILogoff(int conn)
Disconnect from database.
*/
/* Logs off and disconnects.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocilogoff)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_connection *connection;
pval **conn;
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &conn) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
1999-06-09 18:40:08 +08:00
connection->open = 0;
zend_hash_apply(list,(int (*)(void *))_stmt_cleanup);
1999-06-09 18:40:08 +08:00
if (zend_list_delete(connection->id) == SUCCESS) {
1999-04-22 06:49:16 +08:00
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
1999-05-12 22:28:01 +08:00
/* }}} */
1999-11-10 13:50:20 +08:00
/* {{{ proto int OCINLogon(string user, string pass[, string db])
1999-05-12 22:28:01 +08:00
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.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocinlogon)
1999-05-12 22:28:01 +08:00
{
1999-08-17 21:54:25 +08:00
oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0,1);
1999-05-12 22:28:01 +08:00
}
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ proto int OCILogon(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.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocilogon)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0,0);
1999-04-22 06:49:16 +08:00
}
/* }}} */
/* {{{ proto int OCIPLogon(string user, string pass[, string db])
1999-11-10 13:50:20 +08:00
Connect to an Oracle database using a persistent connection and log on. returns a new session.
1999-04-22 06:49:16 +08:00
*/
/* 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.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociplogon)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,1,0);
1999-04-22 06:49:16 +08:00
}
/* }}} */
1999-05-12 22:28:01 +08:00
/* {{{ proto int OCIError([int stmt|conn])
Return the last error of stmt|conn|global. If no error happened returns false.
1999-04-22 06:49:16 +08:00
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocierror)
1999-04-22 06:49:16 +08:00
{
pval **arg;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_connection *connection;
1999-04-22 06:49:16 +08:00
text errbuf[512];
1999-06-09 18:40:08 +08:00
sb4 errcode = 0;
1999-05-12 22:28:01 +08:00
sword error = 0;
1999-04-22 06:49:16 +08:00
dvoid *errh = NULL;
1999-08-17 21:54:25 +08:00
OCILS_FETCH();
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &arg) == SUCCESS) {
statement = (oci_statement *) zend_fetch_resource(arg, -1, NULL, NULL, 1, le_stmt);
if (statement) {
1999-05-12 22:28:01 +08:00
errh = statement->pError;
error = statement->error;
} else {
connection = (oci_connection *) zend_fetch_resource(arg, -1, NULL, NULL, 1, le_conn);
if (connection) {
1999-05-12 22:28:01 +08:00
errh = connection->pError;
error = connection->error;
}
}
} else {
1999-08-17 21:54:25 +08:00
errh = OCI(pError);
error = OCI(error);
1999-04-22 06:49:16 +08:00
}
1999-05-12 22:28:01 +08:00
if (! error) { /* no error set in the handle */
RETURN_FALSE;
1999-04-22 06:49:16 +08:00
}
if (! errh) {
php_error(E_WARNING, "OCIError: unable to find Error handle");
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
OCIErrorGet(errh,1,NULL,&errcode,errbuf,(ub4)sizeof(errbuf),(ub4)OCI_HTYPE_ERROR);
if (errcode) {
array_init(return_value);
add_assoc_long(return_value, "code", errcode);
1999-06-09 18:40:08 +08:00
add_assoc_string(return_value, "message", (char*) errbuf, 1);
1999-04-22 06:49:16 +08:00
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto int OCINumCols(int stmt)
Return the number of result columns in a statement.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocinumcols)
1999-04-22 06:49:16 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
if (getParametersEx(1, &stmt) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
RETURN_LONG(statement->ncolumns);
}
/* }}} */
/* {{{ proto int OCIParse(int conn, string query)
Parse a query and return a statement.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociparse)
1999-04-22 06:49:16 +08:00
{
pval **conn, **query;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
oci_statement *statement;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &conn, &query) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-04-22 06:49:16 +08:00
convert_to_string_ex(query);
statement = oci_parse(connection,(*query)->value.str.val,(*query)->value.str.len);
1999-04-22 06:49:16 +08:00
RETURN_RESOURCE(statement->id);
1999-07-08 22:12:07 +08:00
}
/* }}} */
/* {{{ proto int OCIParse(int conn, string query)
Parse a query and return a statement.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocisetprefetch)
1999-07-08 22:12:07 +08:00
{
pval **stmt, **size;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-07-08 22:12:07 +08:00
if (getParametersEx(2, &stmt, &size) == FAILURE) {
1999-07-08 22:12:07 +08:00
WRONG_PARAM_COUNT;
}
convert_to_long_ex(size);
1999-07-08 22:12:07 +08:00
OCI_GET_STMT(statement,stmt);
1999-07-08 22:12:07 +08:00
oci_setprefetch(statement,(*size)->value.lval);
1999-07-08 22:12:07 +08:00
RETURN_TRUE;
1999-04-22 06:49:16 +08:00
}
1999-05-12 22:28:01 +08:00
/* }}} */
/* {{{ proto int OCINewCursor(int conn)
return a new cursor (Statement-Handle) - use this to bind ref-cursors!
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocinewcursor)
1999-05-12 22:28:01 +08:00
{
pval **conn;
1999-08-17 21:54:25 +08:00
oci_connection *connection;
oci_statement *statement;
1999-05-12 22:28:01 +08:00
if (getParametersEx(1, &conn) == FAILURE) {
1999-05-12 22:28:01 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-05-12 22:28:01 +08:00
statement = oci_parse(connection,0,0);
RETURN_RESOURCE(statement->id);
1999-05-12 22:28:01 +08:00
}
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ proto string OCIResult(int stmt, mixed column)
Return a single column of result data.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociresult)
1999-04-22 06:49:16 +08:00
{
pval **stmt, **col;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
oci_out_column *outcol = NULL;
1999-04-22 06:49:16 +08:00
if (getParametersEx(2, &stmt, &col) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
outcol = oci_get_col(statement, -1, col);
1999-04-22 06:49:16 +08:00
if (outcol == NULL) {
RETURN_FALSE;
}
1999-08-17 21:54:25 +08:00
oci_make_pval(return_value,statement,outcol, "OCIResult",0);
1999-04-22 06:49:16 +08:00
}
/* }}} */
/* {{{ proto string OCIServerVersion(int conn)
Return a string containing server version information.
*/
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ociserverversion)
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
oci_connection *connection;
pval **conn;
1999-04-22 06:49:16 +08:00
char version[256];
if (getParametersEx(1, &conn) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_CONN(connection,conn);
1999-05-12 22:28:01 +08:00
connection->error =
OCIServerVersion(connection->pServiceContext,
connection->pError,
1999-06-09 18:40:08 +08:00
(text*)version,
1999-05-12 22:28:01 +08:00
sizeof(version),
OCI_HTYPE_SVCCTX);
1999-05-12 22:28:01 +08:00
if (connection->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(connection->pError, "OCIServerVersion", connection->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
1999-04-22 06:49:16 +08:00
RETURN_STRING(version,1);
}
/* }}} */
/* {{{ proto int OCIStatementType(int stmt)
Return the query type of an OCI statement.
*/
1999-06-09 18:40:08 +08:00
1999-04-22 06:49:16 +08:00
/* XXX it would be better with a general interface to OCIAttrGet() */
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocistatementtype)
1999-04-22 06:49:16 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
ub2 stmttype;
if (getParametersEx(1, &stmt) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
statement->error =
OCIAttrGet((dvoid *)statement->pStmt,
OCI_HTYPE_STMT,
(ub2 *)&stmttype,
(ub4 *)0,
OCI_ATTR_STMT_TYPE,
statement->pError);
if (statement->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(statement->pError, "OCIStatementType", statement->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
switch (stmttype) {
case OCI_STMT_SELECT:
RETVAL_STRING("SELECT",1);
break;
case OCI_STMT_UPDATE:
RETVAL_STRING("UPDATE",1);
break;
case OCI_STMT_DELETE:
RETVAL_STRING("DELETE",1);
break;
case OCI_STMT_INSERT:
RETVAL_STRING("INSERT",1);
break;
case OCI_STMT_CREATE:
RETVAL_STRING("CREATE",1);
break;
case OCI_STMT_DROP:
RETVAL_STRING("DROP",1);
break;
case OCI_STMT_ALTER:
RETVAL_STRING("ALTER",1);
break;
case OCI_STMT_BEGIN:
RETVAL_STRING("BEGIN",1);
break;
case OCI_STMT_DECLARE:
RETVAL_STRING("DECLARE",1);
break;
default:
RETVAL_STRING("UNKNOWN",1);
}
}
1999-08-10 22:33:59 +08:00
PHP_FUNCTION(ocirowcount)
1999-04-22 06:49:16 +08:00
{
pval **stmt;
1999-08-17 21:54:25 +08:00
oci_statement *statement;
1999-04-22 06:49:16 +08:00
ub4 rowcount;
if (getParametersEx(1, &stmt) == FAILURE) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT;
}
OCI_GET_STMT(statement,stmt);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
statement->error =
OCIAttrGet((dvoid *)statement->pStmt,
OCI_HTYPE_STMT,
(ub2 *)&rowcount,
(ub4 *)0,
OCI_ATTR_ROW_COUNT,
statement->pError);
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if (statement->error != OCI_SUCCESS) {
1999-08-17 21:54:25 +08:00
oci_error(statement->pError, "OCIRowCount", statement->error);
1999-04-22 06:49:16 +08:00
RETURN_FALSE;
}
RETURN_LONG(rowcount);
}
/* }}} */
#endif /* HAVE_OCI8 */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/