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
|
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-04-22 06:49:16 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
|
| 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
|
|
|
|
+----------------------------------------------------------------------+
|
1999-04-25 02:54:02 +08:00
|
|
|
|
| Authors: Stig S<EFBFBD>ther Bakken <ssb@fast.no> |
|
2000-10-29 17:14:55 +08:00
|
|
|
|
| Thies C. Arntzen <thies@thieso.net> |
|
2001-04-13 22:43:39 +08:00
|
|
|
|
| |
|
|
|
|
|
| Collection support by Andy Sautins <asautins@veripost.net> |
|
2001-04-14 16:38:46 +08:00
|
|
|
|
| Temporary LOB support by David Benson <dbenson@mancala.com> |
|
1999-04-22 06:49:16 +08:00
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
*/
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/* TODO list:
|
|
|
|
|
*
|
2000-01-16 21:30:57 +08:00
|
|
|
|
* - php.ini flags
|
|
|
|
|
* especialliy important for things like oci_ping
|
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
|
|
|
|
|
* - Character sets for NCLOBS
|
|
|
|
|
* - split the module into an upper (php-callable) and lower (c-callable) layer!
|
|
|
|
|
* - remove all XXXs
|
|
|
|
|
* - clean up and documentation
|
|
|
|
|
* - make OCIInternalDebug accept a mask of flags....
|
|
|
|
|
* - add some flags to OCIFetchStatement (maxrows etc...)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
* - have one ocifree() call.
|
|
|
|
|
* - make it possible to have persistent statements?
|
|
|
|
|
* - implement connection pooling in ZTS mode.
|
|
|
|
|
* - implement automatic commit *OR* rollback on script end
|
|
|
|
|
* - failover
|
|
|
|
|
* - change all the lob stuff to work without classes (optional)!
|
|
|
|
|
* - make sure that the callbacks terminate the strings with \0
|
|
|
|
|
* - cleanup the ociexecute semantics for refcursors
|
2000-02-27 22:31:04 +08:00
|
|
|
|
* - make $lob->savefile use O_BINARY
|
|
|
|
|
* - line 2728: ub4 length = -1; needs fixing
|
2000-02-28 02:02:14 +08:00
|
|
|
|
* - delay OCIInitialize() as far as we can.
|
2001-04-26 01:48:30 +08:00
|
|
|
|
* - add PHP Array <-> OCICollection conversion
|
|
|
|
|
* - add Collection iterator object for INDEX BY tables
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* {{{ includes & stuff */
|
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
#include "php.h"
|
2000-04-07 05:07:44 +08:00
|
|
|
|
#include "ext/standard/info.h"
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-04-14 17:51:29 +08:00
|
|
|
|
/* #define HAVE_OCI8_TEMP_LOB 1 */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#define WITH_COLLECTIONS 1
|
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
#if HAVE_OCI8
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
1999-12-05 03:19:57 +08:00
|
|
|
|
#include "php_oci8.h"
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
/* True globals, no need for thread safety */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
static int le_conn;
|
|
|
|
|
static int le_stmt;
|
|
|
|
|
static int le_desc;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
static int le_coll;
|
|
|
|
|
#endif
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static int le_server;
|
|
|
|
|
static int le_session;
|
1999-09-13 18:52:54 +08:00
|
|
|
|
static zend_class_entry *oci_lob_class_entry_ptr;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
static zend_class_entry *oci_coll_class_entry_ptr;
|
|
|
|
|
#endif
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
|
|
|
|
#ifndef SQLT_BFILEE
|
1999-12-23 16:18:35 +08:00
|
|
|
|
#define SQLT_BFILEE 114
|
1999-04-25 02:54:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef SQLT_CFILEE
|
1999-12-23 16:18:35 +08:00
|
|
|
|
#define SQLT_CFILEE 115
|
1999-04-25 02:54:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
#define SAFE_STRING(s) ((s)?(s):"")
|
|
|
|
|
|
2000-04-28 18:37:17 +08:00
|
|
|
|
#ifndef PHP_WIN32
|
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
|
|
|
|
|
1999-09-13 19:49:07 +08:00
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
2000-08-07 20:01:52 +08:00
|
|
|
|
#ifndef O_BINARY
|
|
|
|
|
#define O_BINARY 0
|
|
|
|
|
#endif
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ 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 */
|
|
|
|
|
|
2000-05-23 17:33:51 +08:00
|
|
|
|
#ifdef COMPILE_DL_OCI8
|
2000-05-02 08:30:36 +08:00
|
|
|
|
ZEND_GET_MODULE(oci8)
|
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
|
|
|
|
|
2001-02-12 22:36:28 +08:00
|
|
|
|
static ub4 oci_handle_error(oci_connection *connection, ub4 errcode);
|
1999-08-17 21:54:25 +08:00
|
|
|
|
static ub4 oci_error(OCIError *err_p, char *what, sword status);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
static int oci_ping(oci_server *server);
|
|
|
|
|
static void oci_debug(const char *format, ...);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static void _oci_conn_list_dtor(oci_connection *connection TSRMLS_DC);
|
2001-07-31 13:44:11 +08:00
|
|
|
|
static void _oci_stmt_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
|
|
|
|
static void _oci_descriptor_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
2001-07-31 13:44:11 +08:00
|
|
|
|
static void _oci_coll_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#endif
|
2001-07-31 13:44:11 +08:00
|
|
|
|
static void _oci_server_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
|
|
|
|
static void _oci_session_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
|
|
|
|
static void php_oci_free_conn_list(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
1999-09-13 19:13:53 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static void _oci_column_hash_dtor(void *data TSRMLS_DC);
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static void _oci_define_hash_dtor(void *data);
|
|
|
|
|
static void _oci_bind_hash_dtor(void *data);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_connection *oci_get_conn(zval ** TSRMLS_DC);
|
|
|
|
|
static oci_statement *oci_get_stmt(zval ** TSRMLS_DC);
|
|
|
|
|
static oci_descriptor *oci_get_desc(int TSRMLS_DC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
/* Questionable name. Very close to oci_get_col */
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_collection *oci_get_coll(int TSRMLS_DC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#endif
|
1999-09-30 16:41:45 +08:00
|
|
|
|
static oci_out_column *oci_get_col(oci_statement *, int, zval **);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static int _oci_make_zval(zval *, oci_statement *, oci_out_column *, char *, int mode TSRMLS_DC);
|
1999-09-30 16:41:45 +08:00
|
|
|
|
static oci_statement *oci_parse(oci_connection *, char *, int);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
static int oci_execute(oci_statement *, char *, ub4 mode);
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static int oci_fetch(oci_statement *, ub4, char * TSRMLS_DC);
|
2000-08-07 19:34:48 +08:00
|
|
|
|
static int oci_loadlob(oci_connection *, oci_descriptor *, char **, ub4 *length);
|
2000-01-16 21:30:57 +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
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static oci_server *_oci_open_server(char *dbname,int persistent);
|
1999-08-17 21:54:25 +08:00
|
|
|
|
static void _oci_close_server(oci_server *server);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static oci_session *_oci_open_session(oci_server* server,char *username,char *password,int persistent,int exclusive);
|
|
|
|
|
static void _oci_close_session(oci_session *session);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
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
|
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-25 02:54:02 +08:00
|
|
|
|
|
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);
|
2000-03-03 09:28:27 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumnscale);
|
|
|
|
|
PHP_FUNCTION(ocicolumnprecision);
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumntype);
|
2000-03-03 09:28:27 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumntyperaw);
|
1999-08-10 22:33:59 +08:00
|
|
|
|
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);
|
1999-09-13 18:52:54 +08:00
|
|
|
|
PHP_FUNCTION(ocifreedesc);
|
|
|
|
|
PHP_FUNCTION(ocisavelob);
|
1999-09-13 19:49:07 +08:00
|
|
|
|
PHP_FUNCTION(ocisavelobfile);
|
1999-09-13 18:52:54 +08:00
|
|
|
|
PHP_FUNCTION(ociloadlob);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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);
|
2001-04-14 17:51:29 +08:00
|
|
|
|
#ifdef HAVE_OCI8_TEMP_LOB
|
2001-04-14 16:38:46 +08:00
|
|
|
|
PHP_FUNCTION(ociwritetemporarylob);
|
|
|
|
|
PHP_FUNCTION(ocicloselob);
|
|
|
|
|
#endif
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
PHP_FUNCTION(ocinewcollection);
|
2001-06-06 08:08:21 +08:00
|
|
|
|
PHP_FUNCTION(ocifreecollection);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
PHP_FUNCTION(ocicollappend);
|
|
|
|
|
PHP_FUNCTION(ocicollgetelem);
|
|
|
|
|
PHP_FUNCTION(ocicollassignelem);
|
|
|
|
|
PHP_FUNCTION(ocicollassign);
|
|
|
|
|
PHP_FUNCTION(ocicollsize);
|
|
|
|
|
PHP_FUNCTION(ocicollmax);
|
|
|
|
|
PHP_FUNCTION(ocicolltrim);
|
|
|
|
|
#endif
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#define OCI_GET_STMT(statement,value) \
|
2001-08-01 07:47:35 +08:00
|
|
|
|
statement = oci_get_stmt(value TSRMLS_CC); \
|
1999-09-30 16:41:45 +08:00
|
|
|
|
if (statement == NULL) { \
|
|
|
|
|
RETURN_FALSE; \
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#define OCI_GET_CONN(connection,value) \
|
2001-08-01 07:47:35 +08:00
|
|
|
|
connection = oci_get_conn(value TSRMLS_CC); \
|
1999-09-30 16:41:45 +08:00
|
|
|
|
if (connection == NULL) { \
|
|
|
|
|
RETURN_FALSE; \
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#define OCI_GET_DESC(descriptor,index) \
|
2001-08-01 07:47:35 +08:00
|
|
|
|
descriptor = oci_get_desc(index TSRMLS_CC); \
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (descriptor == NULL) { \
|
|
|
|
|
RETURN_FALSE; \
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
#define OCI_GET_COLL(collection,index) \
|
2001-08-01 07:47:35 +08:00
|
|
|
|
collection = oci_get_coll(index TSRMLS_CC); \
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (collection == NULL) { \
|
|
|
|
|
RETURN_FALSE; \
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
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)
|
2000-03-03 09:28:27 +08:00
|
|
|
|
PHP_FE(ocicolumnscale, NULL)
|
|
|
|
|
PHP_FE(ocicolumnprecision, NULL)
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FE(ocicolumntype, NULL)
|
2000-03-03 09:28:27 +08:00
|
|
|
|
PHP_FE(ocicolumntyperaw, NULL)
|
1999-08-10 22:33:59 +08:00
|
|
|
|
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)
|
1999-09-13 19:49:07 +08:00
|
|
|
|
PHP_FE(ocifreedesc, NULL)
|
|
|
|
|
PHP_FE(ocisavelob, NULL)
|
|
|
|
|
PHP_FE(ocisavelobfile, NULL)
|
|
|
|
|
PHP_FE(ociloadlob, NULL)
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
2001-06-06 08:08:21 +08:00
|
|
|
|
PHP_FE(ocifreecollection,NULL)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
PHP_FE(ocicollappend, NULL)
|
|
|
|
|
PHP_FE(ocicollgetelem, NULL)
|
|
|
|
|
PHP_FE(ocicollassignelem,NULL)
|
|
|
|
|
PHP_FE(ocicollassign, NULL)
|
|
|
|
|
PHP_FE(ocicollsize, NULL)
|
|
|
|
|
PHP_FE(ocicollmax, NULL)
|
|
|
|
|
PHP_FE(ocicolltrim, NULL)
|
|
|
|
|
PHP_FE(ocinewcollection, NULL)
|
|
|
|
|
#endif
|
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
|
|
|
|
};
|
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
static zend_function_entry php_oci_lob_class_functions[] = {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
PHP_FALIAS(load, ociloadlob, NULL)
|
|
|
|
|
PHP_FALIAS(writetofile, ociwritelobtofile,NULL)
|
2001-04-14 17:51:29 +08:00
|
|
|
|
#ifdef HAVE_OCI8_TEMP_LOB
|
2001-04-14 16:38:46 +08:00
|
|
|
|
PHP_FALIAS(writetemporary, ociwritetemporarylob,NULL)
|
|
|
|
|
PHP_FALIAS(close, ocicloselob, NULL)
|
|
|
|
|
#endif
|
1999-10-28 01:51:22 +08:00
|
|
|
|
PHP_FALIAS(save, ocisavelob, NULL)
|
|
|
|
|
PHP_FALIAS(savefile, ocisavelobfile, NULL)
|
|
|
|
|
PHP_FALIAS(free, ocifreedesc, NULL)
|
1999-09-13 18:52:54 +08:00
|
|
|
|
{NULL,NULL,NULL}
|
|
|
|
|
};
|
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
static zend_function_entry php_oci_coll_class_functions[] = {
|
|
|
|
|
PHP_FALIAS(append, ocicollappend, NULL)
|
|
|
|
|
PHP_FALIAS(getelem, ocicollgetelem, NULL)
|
|
|
|
|
PHP_FALIAS(assignelem, ocicollassignelem, NULL)
|
|
|
|
|
PHP_FALIAS(assign, ocicollassign, NULL)
|
|
|
|
|
PHP_FALIAS(size, ocicollsize, NULL)
|
|
|
|
|
PHP_FALIAS(max, ocicollmax, NULL)
|
|
|
|
|
PHP_FALIAS(trim, ocicolltrim, NULL)
|
2001-06-06 08:08:21 +08:00
|
|
|
|
PHP_FALIAS(free, ocifreecollection, NULL)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{NULL,NULL,NULL}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
|
zend_module_entry oci8_module_entry = {
|
2000-03-07 02:44:01 +08:00
|
|
|
|
"oci8", /* extension name */
|
1999-08-17 21:54:25 +08:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ debug malloc/realloc/free */
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#define OCI_USE_EMALLOC 0 /* set this to 1 if you want to use the php memory manager! */
|
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
#if OCI_USE_EMALLOC
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ startup, shutdown and info functions */
|
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
|
static void php_oci_init_globals(php_oci_globals *oci_globals_p TSRMLS_DC)
|
1999-08-17 21:54:25 +08:00
|
|
|
|
{
|
2000-07-15 22:54:04 +08:00
|
|
|
|
OCI(shutdown) = 0;
|
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
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
PHP_MINIT_FUNCTION(oci)
|
|
|
|
|
{
|
1999-09-13 18:52:54 +08:00
|
|
|
|
zend_class_entry oci_lob_class_entry;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
zend_class_entry oci_coll_class_entry;
|
|
|
|
|
#endif
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
#define PHP_OCI_INIT_MODE OCI_DEFAULT | OCI_OBJECT
|
1999-08-17 21:54:25 +08:00
|
|
|
|
#else
|
1999-12-23 16:18:35 +08:00
|
|
|
|
#define PHP_OCI_INIT_MODE OCI_DEFAULT
|
1999-12-09 19:02:41 +08:00
|
|
|
|
#endif
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-09 19:02:41 +08:00
|
|
|
|
#if OCI_USE_EMALLOC
|
|
|
|
|
OCIInitialize(PHP_OCI_INIT_MODE, NULL, ocimalloc, ocirealloc, ocifree);
|
|
|
|
|
#else
|
|
|
|
|
OCIInitialize(PHP_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
|
|
|
|
|
#endif
|
1999-08-19 00:48:59 +08:00
|
|
|
|
|
1999-12-09 19:02:41 +08:00
|
|
|
|
#ifdef ZTS
|
2001-07-27 18:16:41 +08:00
|
|
|
|
ts_allocate_id(&oci_globals_id, sizeof(php_oci_globals), (ts_allocate_ctor) php_oci_init_globals, NULL);
|
1999-12-09 19:02:41 +08:00
|
|
|
|
#else
|
2001-07-28 19:36:37 +08:00
|
|
|
|
php_oci_init_globals(&oci_globals TSRMLS_CC);
|
1999-08-17 21:54:25 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-10-26 01:44:02 +08:00
|
|
|
|
le_stmt = zend_register_list_destructors_ex(_oci_stmt_list_dtor, NULL, "oci8 statement", module_number);
|
|
|
|
|
le_conn = zend_register_list_destructors_ex(php_oci_free_conn_list, NULL, "oci8 connection", module_number);
|
|
|
|
|
le_desc = zend_register_list_destructors_ex(_oci_descriptor_list_dtor, NULL, "oci8 descriptor", module_number);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
le_coll = zend_register_list_destructors_ex(_oci_coll_list_dtor, NULL, "oci8 collection", module_number);
|
|
|
|
|
#endif
|
2000-10-26 01:44:02 +08:00
|
|
|
|
le_server = zend_register_list_destructors_ex(_oci_server_list_dtor, NULL, "oci8 server", module_number);
|
|
|
|
|
le_session = zend_register_list_destructors_ex(_oci_session_list_dtor, NULL, "oci8 session", module_number);
|
1999-08-17 21:54:25 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
INIT_CLASS_ENTRY(oci_lob_class_entry, "OCI-Lob", php_oci_lob_class_functions);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
INIT_CLASS_ENTRY(oci_coll_class_entry, "OCI-Collection", php_oci_coll_class_functions);
|
|
|
|
|
#endif
|
1999-09-13 18:52:54 +08:00
|
|
|
|
|
2001-07-30 09:56:43 +08:00
|
|
|
|
oci_lob_class_entry_ptr = zend_register_internal_class(&oci_lob_class_entry TSRMLS_CC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
2001-07-30 09:56:43 +08:00
|
|
|
|
oci_coll_class_entry_ptr = zend_register_internal_class(&oci_coll_class_entry TSRMLS_CC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#endif
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-10-29 17:14:55 +08:00
|
|
|
|
/* thies@thieso.net 990203 i do not think that we will need all of them - just in here for completeness for now! */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
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);
|
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
REGISTER_LONG_CONSTANT("OCI_B_SQLT_NTY",SQLT_NTY, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
REGISTER_STRING_CONSTANT("OCI_SYSDATE","SYSDATE",CONST_PERSISTENT);
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
PHP_RINIT_FUNCTION(oci)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* XXX NYI
|
1999-08-17 21:54:25 +08:00
|
|
|
|
OCI(num_links) =
|
|
|
|
|
OCI(num_persistent);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
*/
|
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
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("php_rinit_oci");
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
static int _session_pcleanup(oci_session *session TSRMLS_DC)
|
1999-04-25 02:54:02 +08:00
|
|
|
|
{
|
2000-02-01 22:39:59 +08:00
|
|
|
|
_oci_close_session(session);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
return 1;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
static int _server_pcleanup(oci_server *server TSRMLS_DC)
|
1999-04-25 02:54:02 +08:00
|
|
|
|
{
|
1999-08-17 21:54:25 +08:00
|
|
|
|
_oci_close_server(server);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
return 1;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2000-02-01 22:39:59 +08:00
|
|
|
|
OCI(shutdown) = 1;
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START php_mshutdown_oci");
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(OCI(user), (apply_func_t)_session_pcleanup TSRMLS_CC);
|
|
|
|
|
zend_hash_apply(OCI(server), (apply_func_t)_server_pcleanup TSRMLS_CC);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
zend_hash_destroy(OCI(user));
|
|
|
|
|
zend_hash_destroy(OCI(server));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
free(OCI(user));
|
|
|
|
|
free(OCI(server));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
OCIHandleFree((dvoid *)OCI(pEnv), OCI_HTYPE_ENV);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("END php_mshutdown_oci");
|
1999-06-09 18:40:08 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
return SUCCESS;
|
1999-06-09 18:40:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
PHP_RSHUTDOWN_FUNCTION(oci)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START php_rshutdown_oci");
|
|
|
|
|
|
2001-07-08 20:37:08 +08:00
|
|
|
|
#if 0
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* XXX free all statements, rollback all outstanding transactions */
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(OCI(user), (apply_func_t) _session_cleanup TSRMLS_CC);
|
|
|
|
|
zend_hash_apply(OCI(server), (apply_func_t) _server_cleanup TSRMLS_CC);
|
2000-02-01 22:39:59 +08:00
|
|
|
|
#endif
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("END php_rshutdown_oci");
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
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
|
|
|
|
{
|
2000-04-07 05:07:44 +08:00
|
|
|
|
|
|
|
|
|
php_info_print_table_start();
|
|
|
|
|
php_info_print_table_row(2, "OCI8 Support", "enabled");
|
2000-08-07 19:34:48 +08:00
|
|
|
|
php_info_print_table_row(2, "Revision", "$Revision$");
|
2000-04-28 18:37:17 +08:00
|
|
|
|
#ifndef PHP_WIN32
|
2000-05-08 17:06:48 +08:00
|
|
|
|
php_info_print_table_row(2, "Oracle Version", PHP_OCI8_VERSION );
|
|
|
|
|
php_info_print_table_row(2, "Compile-time ORACLE_HOME", PHP_OCI8_DIR );
|
|
|
|
|
php_info_print_table_row(2, "Libraries Used", PHP_OCI8_SHARED_LIBADD );
|
1999-04-22 06:49:16 +08:00
|
|
|
|
#endif
|
2000-04-07 05:07:44 +08:00
|
|
|
|
php_info_print_table_end();
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ _oci_define_hash_dtor() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static void
|
2000-01-16 21:30:57 +08:00
|
|
|
|
_oci_define_hash_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;
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("_oci_define_hash_dtor: %s",define->name);
|
|
|
|
|
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&define->zval);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
if (define->name) {
|
|
|
|
|
efree(define->name);
|
|
|
|
|
define->name = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ _oci_bind_hash_dtor() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static void
|
2000-01-16 21:30:57 +08:00
|
|
|
|
_oci_bind_hash_dtor(void *data)
|
|
|
|
|
{
|
|
|
|
|
oci_bind *bind = (oci_bind *) data;
|
|
|
|
|
|
|
|
|
|
oci_debug("_oci_bind_hash_dtor:");
|
|
|
|
|
|
2001-02-28 04:16:35 +08:00
|
|
|
|
zval_ptr_dtor(&(bind->zval));
|
2000-01-16 21:30:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_bind_pre_exec() */
|
|
|
|
|
|
|
|
|
|
static int
|
2001-07-31 12:53:54 +08:00
|
|
|
|
_oci_bind_pre_exec(void *data TSRMLS_DC)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
{
|
|
|
|
|
oci_bind *bind = (oci_bind *) data;
|
|
|
|
|
|
|
|
|
|
/* reset all bind stuff to a normal state..-. */
|
|
|
|
|
|
|
|
|
|
bind->indicator = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-07 18:31:43 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_bind_post_exec() */
|
|
|
|
|
|
|
|
|
|
static int
|
2001-07-31 12:53:54 +08:00
|
|
|
|
_oci_bind_post_exec(void *data TSRMLS_DC)
|
2000-02-07 18:31:43 +08:00
|
|
|
|
{
|
|
|
|
|
oci_bind *bind = (oci_bind *) data;
|
|
|
|
|
|
|
|
|
|
if (bind->indicator == -1) { /* NULL */
|
|
|
|
|
zval *val = bind->zval;
|
|
|
|
|
zval_dtor(val);
|
|
|
|
|
ZVAL_NULL(val);
|
2001-07-10 02:01:18 +08:00
|
|
|
|
} else if (bind->zval->type == IS_STRING && (bind->zval->value.str.val != empty_string)) {
|
2001-07-09 14:48:15 +08:00
|
|
|
|
bind->zval->value.str.val = erealloc(bind->zval->value.str.val, bind->zval->value.str.len+1);
|
2001-07-08 20:37:08 +08:00
|
|
|
|
bind->zval->value.str.val[ bind->zval->value.str.len ] = '\0';
|
2000-02-07 18:31:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-08 20:37:08 +08:00
|
|
|
|
|
2000-02-07 18:31:43 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_column_hash_dtor() */
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static void
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_column_hash_dtor(void *data TSRMLS_DC)
|
1999-09-13 19:13:53 +08:00
|
|
|
|
{
|
|
|
|
|
oci_out_column *column = (oci_out_column *) data;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START _oci_column_hash_dtor: %s",column->name);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (column->stmtid) {
|
|
|
|
|
zend_list_delete(column->stmtid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (column->is_descr) {
|
|
|
|
|
zend_list_delete(column->descid);
|
|
|
|
|
} else {
|
|
|
|
|
if (column->data) {
|
|
|
|
|
efree(column->data);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("END _oci_column_hash_dtor: %s",column->name);
|
1999-09-29 22:20:27 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
if (column->name) {
|
|
|
|
|
efree(column->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ _oci_stmt_list_dtor() */
|
1999-10-06 00:06:54 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
static void
|
2001-07-31 13:44:11 +08:00
|
|
|
|
_oci_stmt_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
|
oci_statement *statement = (oci_statement *)rsrc->ptr;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START _oci_stmt_list_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) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_destroy(statement->columns);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
efree(statement->columns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (statement->binds) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_destroy(statement->binds);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
efree(statement->binds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (statement->defines) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_destroy(statement->defines);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
efree(statement->defines);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_list_delete(statement->conn->id);
|
1999-10-06 00:06:54 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("END _oci_stmt_list_dtor: id=%d",statement->id);
|
1999-10-06 00:06:54 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
efree(statement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ _oci_conn_list_dtor() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_conn_list_dtor(oci_connection *connection TSRMLS_DC)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
as the connection is "only" a in memory service context we do not disconnect from oracle.
|
|
|
|
|
*/
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START _oci_conn_list_dtor: id=%d",connection->id);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
if (connection->pServiceContext) {
|
2000-05-25 15:44:45 +08:00
|
|
|
|
connection->error =
|
|
|
|
|
OCITransRollback(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
(ub4)0);
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "failed to rollback outstanding transactions!", connection->error);
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
OCIHandleFree((dvoid *) connection->pServiceContext, (ub4) OCI_HTYPE_SVCCTX);
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-05 18:45:55 +08:00
|
|
|
|
if (connection->session && connection->session->exclusive) {
|
|
|
|
|
/* exclusive connection created via OCINLogon() close their
|
|
|
|
|
associated session when destructed */
|
|
|
|
|
zend_list_delete(connection->session->num);
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
if (connection->pError) {
|
|
|
|
|
OCIHandleFree((dvoid *) connection->pError, (ub4) OCI_HTYPE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("END _oci_conn_list_dtor: id=%d",connection->id);
|
1999-09-29 22:20:27 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
efree(connection);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* }}} */
|
2000-10-21 02:25:16 +08:00
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* {{{ php_oci_free_conn_list
|
|
|
|
|
*/
|
2001-07-31 13:44:11 +08:00
|
|
|
|
static void php_oci_free_conn_list(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2000-10-21 02:25:16 +08:00
|
|
|
|
{
|
|
|
|
|
oci_connection *conn = (oci_connection *)rsrc->ptr;
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_conn_list_dtor(conn TSRMLS_CC);
|
2000-10-21 02:25:16 +08:00
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* }}} */
|
2000-10-21 02:25:16 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
|
|
|
|
|
/* {{{ _oci_coll_list_dtor()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2001-07-31 13:44:11 +08:00
|
|
|
|
_oci_coll_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{
|
|
|
|
|
oci_collection *coll = (oci_collection *)rsrc->ptr;
|
2001-04-20 06:00:34 +08:00
|
|
|
|
oci_debug("START _oci_coll_list_dtor: %d",coll->id);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
zend_list_delete(coll->conn->id);
|
2001-04-20 06:00:34 +08:00
|
|
|
|
/* Note sure if we need to free the object. Have an
|
|
|
|
|
oracle TAR out on this one.
|
|
|
|
|
OCIDescriptorFree(descr->ocidescr, descr->type); */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-20 06:00:34 +08:00
|
|
|
|
oci_debug("END _oci_coll_list_dtor: %d",coll->id);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
efree(coll);
|
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* }}} */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ _oci_descriptor_list_dtor()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2001-07-31 13:44:11 +08:00
|
|
|
|
_oci_descriptor_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
|
oci_descriptor *descr = (oci_descriptor *)rsrc->ptr;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("START _oci_descriptor_list_dtor: %d",descr->id);
|
|
|
|
|
|
|
|
|
|
zend_list_delete(descr->conn->id);
|
|
|
|
|
|
|
|
|
|
OCIDescriptorFree(descr->ocidescr, descr->type);
|
|
|
|
|
|
|
|
|
|
oci_debug("END _oci_descriptor_list_dtor: %d",descr->id);
|
|
|
|
|
|
|
|
|
|
efree(descr);
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_server_list_dtor()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2001-07-31 13:44:11 +08:00
|
|
|
|
_oci_server_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2000-02-01 22:39:59 +08:00
|
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
|
oci_server *server = (oci_server *)rsrc->ptr;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (server->persistent)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_oci_close_server(server);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_session_list_dtor()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2001-07-31 13:44:11 +08:00
|
|
|
|
_oci_session_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
2000-02-01 22:39:59 +08:00
|
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
|
oci_session *session = (oci_session *)rsrc->ptr;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (session->persistent)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_oci_close_session(session);
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* }}} */
|
2001-02-12 22:36:28 +08:00
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* {{{ oci_handle_error
|
|
|
|
|
*/
|
2001-02-12 22:36:28 +08:00
|
|
|
|
static ub4
|
|
|
|
|
oci_handle_error(oci_connection *connection, ub4 errcode)
|
|
|
|
|
{
|
2001-02-17 23:54:40 +08:00
|
|
|
|
switch (errcode) {
|
|
|
|
|
case 22: /* ORA-00022 Invalid session id */
|
|
|
|
|
case 1012: /* ORA-01012: */
|
|
|
|
|
case 3113: /* ORA-03113: end-of-file on communication channel */
|
2001-07-26 06:34:25 +08:00
|
|
|
|
case 604:
|
|
|
|
|
case 1041:
|
2001-05-04 22:53:45 +08:00
|
|
|
|
connection->is_open = 0;
|
|
|
|
|
connection->session->is_open = 0;
|
|
|
|
|
connection->session->server->is_open = 0;
|
2001-02-17 23:54:40 +08:00
|
|
|
|
return 1; /* fatal error */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; /* no fatal error */
|
2001-02-12 22:36:28 +08:00
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
|
/* }}} */
|
2001-02-12 22:36:28 +08:00
|
|
|
|
|
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) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
case OCI_SUCCESS:
|
|
|
|
|
break;
|
|
|
|
|
case OCI_SUCCESS_WITH_INFO:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_SUCCESS_WITH_INFO", what);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_NEED_DATA:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_NEED_DATA", what);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_NO_DATA:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_NO_DATA", what);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_ERROR:
|
|
|
|
|
OCIErrorGet(err_p, (ub4)1, NULL, &errcode, errbuf,
|
|
|
|
|
(ub4)sizeof(errbuf), (ub4)OCI_HTYPE_ERROR);
|
|
|
|
|
php_error(E_WARNING, "%s: %s", what, errbuf);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_INVALID_HANDLE:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_INVALID_HANDLE", what);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_STILL_EXECUTING:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_STILL_EXECUTING", what);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_CONTINUE:
|
|
|
|
|
php_error(E_WARNING, "%s: OCI_CONTINUE", what);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
return errcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
1999-09-30 16:41:45 +08:00
|
|
|
|
/* {{{ oci_ping() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
static int oci_ping(oci_server *server)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-09-30 16:41:45 +08:00
|
|
|
|
char version[256];
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCI(error) =
|
|
|
|
|
OCIServerVersion(server->pServer,
|
|
|
|
|
OCI(pError),
|
1999-09-30 16:41:45 +08:00
|
|
|
|
(text*)version,
|
|
|
|
|
sizeof(version),
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCI_HTYPE_SERVER);
|
|
|
|
|
if (OCI(error) == OCI_SUCCESS) {
|
|
|
|
|
return 1;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_error(OCI(pError), "oci_ping", OCI(error));
|
|
|
|
|
|
|
|
|
|
return 0;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/************************* INTERNAL FUNCTIONS *************************/
|
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
/* {{{ oci_debug() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-19 21:11:02 +08:00
|
|
|
|
static void oci_debug(const char *format, ...)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_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';
|
2001-02-15 22:49:01 +08:00
|
|
|
|
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
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_connection *oci_get_conn(zval **conn TSRMLS_DC)
|
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
|
|
|
|
|
2001-07-30 12:58:07 +08:00
|
|
|
|
connection = (oci_connection *) zend_fetch_resource(conn TSRMLS_CC, -1, "OCI8-Connection", NULL, 1, le_conn);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (connection && connection->is_open) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
return connection;
|
|
|
|
|
} else {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
return (oci_connection *) NULL;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_statement *oci_get_stmt(zval **stmt TSRMLS_DC)
|
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
|
|
|
|
|
2001-07-30 12:58:07 +08:00
|
|
|
|
statement = (oci_statement *) zend_fetch_resource(stmt TSRMLS_CC, -1, "OCI8-Statement", NULL, 1, le_stmt);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (statement && statement->conn->is_open) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
return statement;
|
|
|
|
|
} else {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
return (oci_statement *) NULL;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ oci_get_desc() */
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_descriptor *oci_get_desc(int ind TSRMLS_DC)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
{
|
|
|
|
|
oci_descriptor *descriptor;
|
|
|
|
|
int actual_resource_type;
|
|
|
|
|
|
|
|
|
|
descriptor = (oci_descriptor *) zend_list_find(ind, &actual_resource_type);
|
|
|
|
|
|
|
|
|
|
if (descriptor && (actual_resource_type == le_desc)) {
|
|
|
|
|
return descriptor;
|
|
|
|
|
} else {
|
|
|
|
|
return (oci_descriptor *) 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 *
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_get_col(oci_statement *statement, int col, zval **value)
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (value) {
|
|
|
|
|
if ((*value)->type == IS_STRING) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
for (i = 0; i < statement->ncolumns; i++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
outcol = oci_get_col(statement, i + 1, 0);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
if (outcol == NULL) {
|
|
|
|
|
continue;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
} else if (((int) outcol->name_len == (*value)->value.str.len)
|
|
|
|
|
&& (! strncmp(outcol->name,(*value)->value.str.val,(*value)->value.str.len))) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return outcol;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
convert_to_long_ex(value);
|
|
|
|
|
return oci_get_col(statement,(*value)->value.lval,0);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (col != -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_index_find(statement->columns, col, (void **)&outcol) == FAILURE) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
php_error(E_WARNING, "Invalid column %d", col);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return outcol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* {{{ oci_new_desc() */
|
|
|
|
|
|
|
|
|
|
static oci_descriptor*
|
|
|
|
|
oci_new_desc(int type,oci_connection *connection)
|
|
|
|
|
{
|
|
|
|
|
oci_descriptor *descr;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
descr = emalloc(sizeof(oci_descriptor));
|
|
|
|
|
|
|
|
|
|
descr->type = type;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCI(error) =
|
|
|
|
|
OCIDescriptorAlloc(OCI(pEnv),
|
|
|
|
|
(dvoid*)&(descr->ocidescr),
|
|
|
|
|
descr->type,
|
|
|
|
|
(size_t) 0,
|
|
|
|
|
(dvoid **) 0);
|
|
|
|
|
|
|
|
|
|
if (OCI(error)) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
ub4 error;
|
|
|
|
|
error = oci_error(OCI(pError),"OCIDescriptorAlloc %d",OCI(error));
|
|
|
|
|
oci_handle_error(connection, error);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
descr->id = zend_list_insert(descr,le_desc);
|
|
|
|
|
descr->conn = connection;
|
|
|
|
|
zend_list_addref(connection->id);
|
|
|
|
|
|
|
|
|
|
oci_debug("oci_new_desc %d",descr->id);
|
|
|
|
|
|
|
|
|
|
return descr;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
|
|
|
|
|
/* {{{ _oci_get_ocicoll() */
|
|
|
|
|
|
|
|
|
|
static int
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_get_ocicoll(zval *id,oci_collection **collection TSRMLS_DC)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{
|
|
|
|
|
zval **coll;
|
|
|
|
|
|
|
|
|
|
if (zend_hash_find(id->value.obj.properties, "collection", sizeof("collection"), (void **)&coll) == FAILURE) {
|
|
|
|
|
php_error(E_WARNING, "cannot find collection");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((*collection = oci_get_coll((*coll)->value.lval TSRMLS_CC)) == NULL) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
php_error(E_WARNING, "collection not found");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (*coll)->value.lval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_get_ocidesc() */
|
|
|
|
|
|
|
|
|
|
static int
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_get_ocidesc(zval *id,oci_descriptor **descriptor TSRMLS_DC)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
{
|
|
|
|
|
zval **desc;
|
|
|
|
|
|
|
|
|
|
if (zend_hash_find(id->value.obj.properties, "descriptor", sizeof("descriptor"), (void **)&desc) == FAILURE) {
|
|
|
|
|
php_error(E_WARNING, "cannot find descriptor");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((*descriptor = oci_get_desc((*desc)->value.lval TSRMLS_CC)) == NULL) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
php_error(E_WARNING, "descriptor not found");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (*desc)->value.lval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_make_zval() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
static int
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_make_zval(zval *value,oci_statement *statement,oci_out_column *column, char *func, int mode TSRMLS_DC)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_descriptor *descr;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 loblen;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int size;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
char *buffer;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
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))
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("_oci_make_zval: %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 */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
ZVAL_NULL(value);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (column->is_cursor) { /* REFCURSOR -> simply return the statement id */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
ZVAL_RESOURCE(value,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 */
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
descr = oci_get_desc(column->descid TSRMLS_CC);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (! descr) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
php_error(E_WARNING, "unable to find my descriptor %d",column->data);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
2001-02-18 19:10:30 +08:00
|
|
|
|
if (oci_loadlob(statement->conn,descr,&buffer,&loblen)) {
|
2001-07-11 20:42:25 +08:00
|
|
|
|
ZVAL_FALSE(value);
|
2001-02-18 19:10:30 +08:00
|
|
|
|
} else {
|
|
|
|
|
ZVAL_STRINGL(value,buffer,loblen,0);
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
} else {
|
|
|
|
|
/* return the locator */
|
1999-09-13 18:52:54 +08:00
|
|
|
|
object_init_ex(value, oci_lob_class_entry_ptr);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
add_property_resource(value, "descriptor", column->descid);
|
|
|
|
|
zend_list_addref(column->descid);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
switch (column->retcode) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
case 0:
|
|
|
|
|
/* intact value */
|
|
|
|
|
if (column->piecewise) {
|
|
|
|
|
size = column->retlen4;
|
|
|
|
|
} else {
|
|
|
|
|
size = column->retlen;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* XXX we SHOULD maybe have a different behaviour for unknown results! */
|
2001-07-11 20:42:25 +08:00
|
|
|
|
ZVAL_FALSE(value);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
return 0;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
ZVAL_STRINGL(value,column->data,size,1);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
2001-02-12 22:36:28 +08:00
|
|
|
|
if (statement->error) {
|
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
|
|
|
|
}
|
1999-07-08 22:12:07 +08:00
|
|
|
|
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));
|
2001-02-12 22:36:28 +08:00
|
|
|
|
if (statement->error) {
|
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
|
|
|
|
}
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
1999-09-30 16:41:45 +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;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
statement = ecalloc(1,sizeof(oci_statement));
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
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) {
|
2000-05-30 17:25:02 +08:00
|
|
|
|
OCIHandleFree(statement->pStmt, OCI_HTYPE_STMT);
|
|
|
|
|
OCIHandleFree(statement->pError, OCI_HTYPE_ERROR);
|
|
|
|
|
efree(statement);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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);
|
|
|
|
|
|
1999-10-06 00:06:54 +08:00
|
|
|
|
zend_list_addref(statement->conn->id);
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_execute(oci_statement *statement, char *func,ub4 mode)
|
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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int dtype;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
dvoid *buf;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_descriptor *descr;
|
2001-07-31 12:53:54 +08:00
|
|
|
|
TSRMLS_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,
|
2000-01-16 21:30:57 +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));
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
|
|
|
|
if (statement->error) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stmttype == OCI_STMT_SELECT) {
|
|
|
|
|
iters = 0;
|
|
|
|
|
} else {
|
|
|
|
|
iters = 1;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
if (statement->last_query) {
|
|
|
|
|
/* if we execute refcursors we don't have a query and
|
|
|
|
|
we don't want to execute!!! */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-07 18:31:43 +08:00
|
|
|
|
if (statement->binds) {
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(statement->binds, (apply_func_t) _oci_bind_pre_exec TSRMLS_CC);
|
2000-02-07 18:31:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
statement->error =
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_error(statement->pError,
|
2000-01-16 21:30:57 +08:00
|
|
|
|
"OCIStmtExecute",
|
|
|
|
|
OCIStmtExecute(statement->conn->pServiceContext,
|
|
|
|
|
statement->pStmt,
|
|
|
|
|
statement->pError,
|
|
|
|
|
iters,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
mode));
|
2000-02-07 18:31:43 +08:00
|
|
|
|
if (statement->binds) {
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(statement->binds, (apply_func_t) _oci_bind_post_exec TSRMLS_CC);
|
2000-02-07 18:31:43 +08:00
|
|
|
|
}
|
2001-02-17 23:54:40 +08:00
|
|
|
|
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
2001-02-17 23:54:40 +08:00
|
|
|
|
|
|
|
|
|
if (statement->error) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
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++;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
2001-06-20 00:03:35 +08:00
|
|
|
|
ALLOC_HASHTABLE(statement->columns);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_hash_init(statement->columns, 13, NULL, _oci_column_hash_dtor, 0);
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
counter = 1;
|
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
statement->error =
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_error(statement->pError,
|
2000-01-16 21:30:57 +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));
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (statement->error) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return 0; /* XXX we loose memory!!! */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statement->ncolumns = colcount;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
for (counter = 1; counter <= colcount; counter++) {
|
1999-08-17 21:54:25 +08:00
|
|
|
|
memset(&column,0,sizeof(oci_out_column));
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_index_update(statement->columns, counter, &column,
|
2000-01-16 21:30:57 +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;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
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,
|
2001-01-07 19:43:07 +08:00
|
|
|
|
(dvoid**)¶m,
|
1999-05-12 22:28:01 +08:00
|
|
|
|
counter));
|
|
|
|
|
if (statement->error) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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
|
|
|
|
|
2000-03-03 09:28:27 +08:00
|
|
|
|
statement->error =
|
|
|
|
|
oci_error(statement->pError,
|
|
|
|
|
"OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_SCALE",
|
|
|
|
|
OCIAttrGet((dvoid *)param,
|
|
|
|
|
OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid *)&outcol->scale,
|
|
|
|
|
(dvoid *)0,
|
|
|
|
|
OCI_ATTR_SCALE,
|
|
|
|
|
statement->pError));
|
|
|
|
|
if (statement->error) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
2000-03-03 09:28:27 +08:00
|
|
|
|
return 0; /* XXX we lose memory!!! */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statement->error =
|
|
|
|
|
oci_error(statement->pError,
|
|
|
|
|
"OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_PRECISION",
|
|
|
|
|
OCIAttrGet((dvoid *)param,
|
|
|
|
|
OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid *)&outcol->precision,
|
|
|
|
|
(dvoid *)0,
|
|
|
|
|
OCI_ATTR_PRECISION,
|
|
|
|
|
statement->pError));
|
|
|
|
|
if (statement->error) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
2000-03-03 09:28:27 +08:00
|
|
|
|
return 0; /* XXX we lose 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_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) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
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:
|
1999-09-30 16:41:45 +08:00
|
|
|
|
outcol->pstmt = oci_parse(statement->conn,0,0);
|
|
|
|
|
outcol->stmtid = outcol->pstmt->id;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
define_type = SQLT_RSET;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
outcol->is_cursor = 1;
|
|
|
|
|
outcol->storage_size4 = -1;
|
|
|
|
|
outcol->retlen = -1;
|
|
|
|
|
dynamic = OCI_DEFAULT;
|
1999-09-13 23:19:29 +08:00
|
|
|
|
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) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
dtype = OCI_DTYPE_FILE;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
} else if (outcol->data_type == SQLT_RDD ) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
dtype = OCI_DTYPE_ROWID;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
} else {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
dtype = OCI_DTYPE_LOB;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
descr = oci_new_desc(dtype,statement->conn);
|
|
|
|
|
outcol->descid = descr->id;
|
|
|
|
|
buf = &(descr->ocidescr);
|
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 {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
define_type = SQLT_CHR;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
}
|
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:
|
2000-01-16 21:30:57 +08:00
|
|
|
|
define_type = SQLT_CHR;
|
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 */
|
1999-09-13 23:19:29 +08:00
|
|
|
|
(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 */
|
1999-09-13 23:19:29 +08:00
|
|
|
|
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 */
|
1999-09-13 23:19:29 +08:00
|
|
|
|
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) {
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
static int
|
2001-07-31 12:53:54 +08:00
|
|
|
|
_oci_column_pre_fetch(void *data TSRMLS_DC)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
{
|
|
|
|
|
oci_out_column *col = (oci_out_column *) data;
|
|
|
|
|
|
|
|
|
|
if (col->piecewise) {
|
|
|
|
|
col->retlen4 = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
static int
|
2001-08-01 07:47:35 +08:00
|
|
|
|
oci_fetch(oci_statement *statement, ub4 nrows, char *func TSRMLS_DC)
|
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
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (statement->columns) {
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(statement->columns, (apply_func_t) _oci_column_pre_fetch TSRMLS_CC);
|
1999-06-09 18:40:08 +08:00
|
|
|
|
}
|
1999-09-13 23:19:29 +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) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
zend_hash_destroy(statement->columns);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
efree(statement->columns);
|
|
|
|
|
statement->columns = 0;
|
2000-06-08 17:49:31 +08:00
|
|
|
|
statement->ncolumns = 0;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
}
|
|
|
|
|
statement->executed = 0;
|
|
|
|
|
|
|
|
|
|
statement->error = 0; /* OCI_NO_DATA is NO error for us!!! */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-13 23:19:29 +08:00
|
|
|
|
while (statement->error == OCI_NEED_DATA) {
|
|
|
|
|
for (i = 0; i < statement->ncolumns; i++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
column = oci_get_col(statement, i + 1, 0);
|
1999-09-13 23:19:29 +08:00
|
|
|
|
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,
|
1999-12-08 22:04:55 +08:00
|
|
|
|
&column->indicator,
|
|
|
|
|
&column->retcode);
|
1999-09-13 23:19:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statement->error =
|
|
|
|
|
OCIStmtFetch(statement->pStmt,
|
|
|
|
|
statement->pError, nrows,
|
|
|
|
|
OCI_FETCH_NEXT,
|
|
|
|
|
OCI_DEFAULT);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < statement->ncolumns; i++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
column = oci_get_col(statement, i + 1, 0);
|
1999-09-13 23:19:29 +08:00
|
|
|
|
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++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
column = oci_get_col(statement, i + 1, 0);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (column == NULL) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-06-09 18:40:08 +08:00
|
|
|
|
if (! column->define) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1999-07-12 18:36:19 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval_dtor(column->define->zval);
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_make_zval(column->define->zval,statement,column,"OCIFetch",0 TSRMLS_CC);
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
1999-09-13 18:52:54 +08:00
|
|
|
|
/* {{{ oci_loadlob() */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
#define LOBREADSIZE 1048576l /* 1MB */
|
1999-09-17 16:25:03 +08:00
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
static int
|
|
|
|
|
oci_loadlob(oci_connection *connection, oci_descriptor *mydescr, char **buffer,ub4 *loblen)
|
|
|
|
|
{
|
|
|
|
|
ub4 siz = 0;
|
2000-10-07 17:10:54 +08:00
|
|
|
|
ub4 readlen = 0;
|
2000-08-07 19:34:48 +08:00
|
|
|
|
char *buf;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
*loblen = 0;
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-09-17 16:25:03 +08:00
|
|
|
|
return -1;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-08-07 19:34:48 +08:00
|
|
|
|
|
|
|
|
|
connection->error =
|
|
|
|
|
OCILobGetLength(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mydescr->ocidescr,
|
|
|
|
|
&readlen);
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
2001-02-18 19:10:30 +08:00
|
|
|
|
oci_error(connection->pError, "OCILobGetLength",connection->error);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
2000-08-07 19:34:48 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf = emalloc(readlen + 1);
|
|
|
|
|
|
2000-10-07 17:10:54 +08:00
|
|
|
|
while (readlen > 0) { /* thies loop should not be entered on readlen == 0 */
|
2000-08-07 19:34:48 +08:00
|
|
|
|
connection->error =
|
|
|
|
|
OCILobRead(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mydescr->ocidescr,
|
|
|
|
|
&readlen, /* IN/OUT bytes toread/read */
|
|
|
|
|
siz + 1, /* offset (starts with 1) */
|
2000-08-16 23:23:05 +08:00
|
|
|
|
(dvoid *) ((char *) buf + siz),
|
2000-08-07 19:34:48 +08:00
|
|
|
|
readlen, /* 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. */
|
|
|
|
|
|
|
|
|
|
siz += readlen;
|
|
|
|
|
readlen = LOBREADSIZE;
|
|
|
|
|
|
|
|
|
|
if (connection->error == OCI_NEED_DATA) {
|
|
|
|
|
buf = erealloc(buf,siz + LOBREADSIZE + 1);
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-10-07 17:10:54 +08:00
|
|
|
|
}
|
2000-08-07 19:34:48 +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, "OCILobRead", connection->error);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
2000-08-07 19:34:48 +08:00
|
|
|
|
efree(buf);
|
1999-09-17 16:25:03 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
2000-08-07 19:34:48 +08:00
|
|
|
|
efree(buf);
|
1999-09-17 16:25:03 +08:00
|
|
|
|
return -1;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
buf = erealloc(buf,siz+1);
|
|
|
|
|
buf[ siz ] = 0;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
*buffer = buf;
|
|
|
|
|
*loblen = siz;
|
|
|
|
|
|
|
|
|
|
oci_debug("OCIloadlob: size=%d",siz);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-08-07 19:34:48 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* }}} */
|
1999-08-17 21:54:25 +08:00
|
|
|
|
/* {{{ oci_failover_callback() */
|
1999-05-12 22:28:01 +08:00
|
|
|
|
#if 0 /* not needed yet ! */
|
1999-04-25 02:54:02 +08:00
|
|
|
|
static sb4
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_failover_callback(dvoid *svchp,
|
1999-04-25 02:54:02 +08:00
|
|
|
|
dvoid* envhp,
|
|
|
|
|
dvoid *fo_ctx,
|
|
|
|
|
ub4 fo_type,
|
|
|
|
|
ub4 fo_event)
|
|
|
|
|
{
|
|
|
|
|
/*
|
2000-10-29 17:14:55 +08:00
|
|
|
|
this stuff is from an oci sample - it will get cleaned up as soon as i understand it!!! (thies@thieso.net 990420)
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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");
|
2000-02-11 03:41:21 +08:00
|
|
|
|
php_sleep(3);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* 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
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_bind_in_callback(dvoid *ictxp, /* context pointer */
|
|
|
|
|
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-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_bind *phpbind;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *val;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (!(phpbind=(oci_bind *)ictxp) || !(val = phpbind->zval)) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
php_error(E_WARNING, "!phpbind || !phpbind->val");
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return OCI_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (ZVAL_IS_NULL(val)) {
|
|
|
|
|
/* we're going to insert a NULL column */
|
|
|
|
|
phpbind->indicator = -1;
|
|
|
|
|
*bufpp = 0;
|
|
|
|
|
*alenp = -1;
|
|
|
|
|
*indpp = (dvoid *)&phpbind->indicator;
|
|
|
|
|
} else 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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
*alenp = val->value.str.len;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*indpp = (dvoid *)&phpbind->indicator;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
} else if (phpbind->pStmt != 0) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* RSET */
|
1999-05-12 22:28:01 +08:00
|
|
|
|
*bufpp = phpbind->pStmt;
|
|
|
|
|
*alenp = -1; /* seems to be allright */
|
|
|
|
|
*indpp = (dvoid *)&phpbind->indicator;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
} 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
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_bind_out_callback(dvoid *octxp, /* context pointer */
|
|
|
|
|
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-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_bind *phpbind;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *val;
|
|
|
|
|
sb4 retval = OCI_ERROR;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (!(phpbind=(oci_bind *)octxp) || !(val = phpbind->zval)) {
|
|
|
|
|
php_error(E_WARNING, "!phpbind || !phpbind->val");
|
|
|
|
|
return retval;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-22 21:56:48 +08:00
|
|
|
|
if ((val->type == IS_OBJECT) || (val->type == IS_RESOURCE)) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
retval = OCI_CONTINUE;
|
2000-02-07 18:31:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
convert_to_string(val);
|
|
|
|
|
zval_dtor(val);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
val->value.str.len = OCI_PIECE_SIZE; /* 64K-1 is max XXX */
|
|
|
|
|
val->value.str.val = emalloc(phpbind->zval->value.str.len);
|
|
|
|
|
|
|
|
|
|
/* XXX we assume that zend-zval len has 4 bytes */
|
|
|
|
|
*alenpp = (ub4*) &phpbind->zval->value.str.len;
|
|
|
|
|
*bufpp = phpbind->zval->value.str.val;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*piecep = OCI_ONE_PIECE;
|
|
|
|
|
*rcodepp = &phpbind->retcode;
|
|
|
|
|
*indpp = &phpbind->indicator;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
retval = OCI_CONTINUE;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
return retval;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-02-01 22:39:59 +08:00
|
|
|
|
/* {{{ _oci_open_session()
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
static oci_session *_oci_open_session(oci_server* server,char *username,char *password,int persistent,int exclusive)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_session *session = 0, *psession = 0;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
OCISvcCtx *svchp = 0;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
char *hashed_details;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_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!
|
|
|
|
|
*/
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
hashed_details = (char *) malloc(strlen(SAFE_STRING(username))+
|
|
|
|
|
strlen(SAFE_STRING(password))+
|
|
|
|
|
strlen(SAFE_STRING(server->dbname))+1);
|
|
|
|
|
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
zend_hash_find(OCI(user), hashed_details, strlen(hashed_details)+1, (void **) &session);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (session) {
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (session->is_open) {
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (persistent) {
|
|
|
|
|
session->persistent = 1;
|
|
|
|
|
}
|
2000-02-01 22:39:59 +08:00
|
|
|
|
free(hashed_details);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
return session;
|
|
|
|
|
} else {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
_oci_close_session(session);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
/* breakthru to open */
|
|
|
|
|
}
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
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;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
session->hashed_details = hashed_details;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
session->server = server;
|
2000-03-06 16:02:15 +08:00
|
|
|
|
session->exclusive = exclusive;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
/* 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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_open_session: 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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_open_session: 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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_open_session: 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-05-12 22:28:01 +08:00
|
|
|
|
if (exclusive) {
|
2000-03-01 16:17:33 +08:00
|
|
|
|
psession = session;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
} else {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
zend_hash_update(OCI(user),
|
|
|
|
|
session->hashed_details,
|
|
|
|
|
strlen(session->hashed_details)+1,
|
|
|
|
|
(void *)session,
|
|
|
|
|
sizeof(oci_session),
|
|
|
|
|
(void**)&psession);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
psession->num = zend_list_insert(psession,le_session);
|
2001-05-04 22:53:45 +08:00
|
|
|
|
psession->is_open = 1;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_debug("_oci_open_session new sess=%d user=%s",psession->num,username);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-03-06 16:02:15 +08:00
|
|
|
|
if (! exclusive) free(session);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
return psession;
|
|
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
|
oci_debug("_oci_open_session: FAILURE -> CLEANUP called");
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
_oci_close_session(session);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-02-01 22:39:59 +08:00
|
|
|
|
/* {{{ _oci_close_session()
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void
|
2000-02-01 22:39:59 +08:00
|
|
|
|
_oci_close_session(oci_session *session)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
1999-04-25 02:54:02 +08:00
|
|
|
|
OCISvcCtx *svchp;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
char *hashed_details;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
if (! session) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-05 18:45:55 +08:00
|
|
|
|
oci_debug("START _oci_close_session: logging-off sess=%d",session->num);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (session->is_open) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* 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-04-25 02:54:02 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
if (OCI(error) != OCI_SUCCESS) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_close_session OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI(error));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_close_session: OCIAttrSet OCI_ATTR_SERVER", OCI(error));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_close_session: OCIAttrSet OCI_ATTR_SESSION", OCI(error));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_close_session: OCISessionEnd", OCI(error));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
2000-07-03 23:05:46 +08:00
|
|
|
|
|
|
|
|
|
OCIHandleFree((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX);
|
|
|
|
|
|
1999-04-25 02:54:02 +08:00
|
|
|
|
} else {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_debug("_oci_close_session: logging-off DEAD session");
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (session->pSession) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
OCIHandleFree((dvoid *) session->pSession, (ub4) OCI_HTYPE_SESSION);
|
|
|
|
|
}
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
|
|
|
|
hashed_details = session->hashed_details;
|
|
|
|
|
|
|
|
|
|
if (! OCI(shutdown)) {
|
|
|
|
|
zend_hash_del(OCI(user), hashed_details, strlen(hashed_details)+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(hashed_details);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-02-01 22:39:59 +08:00
|
|
|
|
/* {{{ _oci_open_server()
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*/
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
|
|
|
|
static oci_server *_oci_open_server(char *dbname,int persistent)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_server *server, *pserver = 0;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
check if we already have this server open
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
we will reuse servers within a request no matter if the user requested persistent
|
1999-04-22 06:49:16 +08:00
|
|
|
|
connections or not!
|
|
|
|
|
|
|
|
|
|
but only as pesistent requested connections will be kept between requests!
|
|
|
|
|
*/
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
zend_hash_find(OCI(server), dbname, strlen(dbname)+1, (void **) &pserver);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (pserver) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
/* XXX ini-flag */
|
|
|
|
|
/*
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (! oci_ping(pserver)) {
|
2001-05-04 22:53:45 +08:00
|
|
|
|
pserver->is_open = 0;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
}
|
|
|
|
|
*/
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (pserver->is_open) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* if our new users uses this connection persistent, we're keeping it! */
|
|
|
|
|
if (persistent) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
pserver->persistent = persistent;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
return pserver;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
} else { /* server "died" in the meantime - try to reconnect! */
|
2000-02-01 22:39:59 +08:00
|
|
|
|
_oci_close_server(pserver);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/* breakthru to open */
|
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
server = calloc(1,sizeof(oci_server));
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
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),
|
2000-02-01 22:39:59 +08:00
|
|
|
|
(text*)server->dbname,
|
|
|
|
|
strlen(server->dbname),
|
1999-05-12 22:28:01 +08:00
|
|
|
|
(ub4) OCI_DEFAULT);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
if (OCI(error)) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_open_server", OCI(error));
|
1999-04-22 06:49:16 +08:00
|
|
|
|
goto CLEANUP;
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
zend_hash_update(OCI(server),
|
|
|
|
|
server->dbname,
|
|
|
|
|
strlen(server->dbname)+1,
|
|
|
|
|
(void *)server,
|
|
|
|
|
sizeof(oci_server),
|
|
|
|
|
(void**)&pserver);
|
|
|
|
|
|
|
|
|
|
pserver->num = zend_list_insert(pserver,le_server);
|
2001-05-04 22:53:45 +08:00
|
|
|
|
pserver->is_open = 1;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
|
|
|
|
|
oci_debug("_oci_open_server new conn=%d dname=%s",server->num,server->dbname);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
free(server);
|
|
|
|
|
|
|
|
|
|
return pserver;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
CLEANUP:
|
|
|
|
|
oci_debug("_oci_open_server: FAILURE -> CLEANUP called");
|
|
|
|
|
|
|
|
|
|
_oci_close_server(server);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
#if 0
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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
|
|
|
|
|
1999-04-25 02:54:02 +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));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
|
|
|
|
if (error) {
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_error(OCI(pError), "_oci_open_server OCIAttrSet OCI_ATTR_FOCBK", error);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
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-04-25 02:54:02 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
/* }}} */
|
|
|
|
|
/* {{{ _oci_close_server()
|
|
|
|
|
*/
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
static int _oci_session_cleanup(void *data TSRMLS_DC)
|
2000-02-01 22:39:59 +08:00
|
|
|
|
{
|
2000-02-07 18:31:43 +08:00
|
|
|
|
list_entry *le = (list_entry *) data;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (le->type == le_session) {
|
|
|
|
|
oci_server *server = ((oci_session*) le->ptr)->server;
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (server->is_open == 2)
|
2000-02-01 22:39:59 +08:00
|
|
|
|
return 1;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-08-17 21:54:25 +08:00
|
|
|
|
_oci_close_server(oci_server *server)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-02-01 22:39:59 +08:00
|
|
|
|
char *dbname;
|
2000-08-05 18:07:39 +08:00
|
|
|
|
int oldopen;
|
2001-07-28 19:36:37 +08:00
|
|
|
|
TSRMLS_FETCH();
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
oldopen = server->is_open;
|
|
|
|
|
server->is_open = 2;
|
2000-02-01 22:39:59 +08:00
|
|
|
|
if (! OCI(shutdown)) {
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(&EG(regular_list), (apply_func_t) _oci_session_cleanup TSRMLS_CC);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
2001-05-04 22:53:45 +08:00
|
|
|
|
server->is_open = oldopen;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
oci_debug("START _oci_close_server: detaching conn=%d dbname=%s",server->num,server->dbname);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
|
|
|
|
/* XXX close server here */
|
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
if (server->is_open) {
|
1999-08-17 21:54:25 +08:00
|
|
|
|
if (server->pServer && OCI(pError)) {
|
|
|
|
|
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:31:01 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
if (OCI(error)) {
|
|
|
|
|
oci_error(OCI(pError), "oci_close_server OCIServerDetach", OCI(error));
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
1999-08-19 12:13:56 +08:00
|
|
|
|
oci_debug("_oci_close_server: closing DEAD server");
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
if (server->pServer) {
|
1999-04-25 02:54:02 +08:00
|
|
|
|
OCIHandleFree((dvoid *) server->pServer, (ub4) OCI_HTYPE_SERVER);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
}
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
dbname = server->dbname;
|
|
|
|
|
|
|
|
|
|
if (! OCI(shutdown)) {
|
|
|
|
|
zend_hash_del(OCI(server),dbname,strlen(dbname)+1);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
free(dbname);
|
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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **userParam, **passParam, **dbParam;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_server *server = 0;
|
|
|
|
|
oci_session *session = 0;
|
|
|
|
|
oci_connection *connection = 0;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(3, &userParam, &passParam, &dbParam) == SUCCESS) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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;
|
1999-12-19 06:40:35 +08:00
|
|
|
|
} else if (zend_get_parameters_ex(2, &userParam, &passParam) == SUCCESS) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-01 22:39:59 +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 */
|
|
|
|
|
|
2000-02-01 22:39:59 +08:00
|
|
|
|
session = _oci_open_session(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;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-25 02:54:02 +08:00
|
|
|
|
/*
|
|
|
|
|
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);
|
|
|
|
|
*/
|
|
|
|
|
|
1999-10-06 00:06:54 +08:00
|
|
|
|
connection->id = zend_list_insert(connection, le_conn);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
connection->is_open = 1;
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
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
|
|
|
|
|
1999-07-05 14:29:04 +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");
|
1999-04-25 02:54:02 +08:00
|
|
|
|
|
|
|
|
|
if (connection->id) {
|
1999-10-06 00:06:54 +08:00
|
|
|
|
zend_list_delete(connection->id);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
} else {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_conn_list_dtor(connection TSRMLS_CC);
|
1999-04-25 02:54:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/************************* EXTENSION FUNCTIONS *************************/
|
|
|
|
|
|
2000-03-15 05:17:07 +08:00
|
|
|
|
/* {{{ proto int ocidefinebyname(int stmt, string name, mixed &var [, int type])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
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-04-22 06:49:16 +08:00
|
|
|
|
*/
|
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocidefinebyname)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt, **name, **var, **type;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_define *define, *tmp_define;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
ub2 ocitype = SQLT_CHR; /* zero terminated string */
|
2000-06-06 03:47:54 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (ac < 3 || ac > 4 || zend_get_parameters_ex(ac, &stmt, &name, &var, &type) == FAILURE) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +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
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_string_ex(name);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
if (statement->defines == NULL) {
|
2001-06-20 00:03:35 +08:00
|
|
|
|
ALLOC_HASHTABLE(statement->defines);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_hash_init(statement->defines, 13, NULL, _oci_define_hash_dtor, 0);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
define = ecalloc(1,sizeof(oci_define));
|
|
|
|
|
|
1999-08-03 03:17:14 +08:00
|
|
|
|
if (zend_hash_add(statement->defines,
|
1999-09-30 16:41:45 +08:00
|
|
|
|
(*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;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
define->zval = *var;
|
|
|
|
|
zval_add_ref(var);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocibindbyname(int stmt, string name, mixed &var, int maxlength [, int type])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
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-04-22 06:49:16 +08:00
|
|
|
|
*/
|
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocibindbyname)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt, **name, **var, **maxlen, **type;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_statement *bindstmt;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_bind bind, *bindp;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_descriptor *descr;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
int mode = OCI_DATA_AT_EXEC;
|
|
|
|
|
dvoid *mycoll = 0;
|
|
|
|
|
#endif
|
2000-01-16 21:30:57 +08:00
|
|
|
|
ub2 ocitype = SQLT_CHR; /* unterminated string */
|
1999-05-12 22:28:01 +08:00
|
|
|
|
OCIStmt *mystmt = 0;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
dvoid *mydescr = 0;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
sb4 value_sz = -1;
|
2000-06-06 03:47:54 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS(), inx;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-10-23 03:33:59 +08:00
|
|
|
|
if (ac < 3 || ac > 5 || zend_get_parameters_ex(ac, &stmt, &name, &var, &maxlen, &type) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
}
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
switch (ac) {
|
|
|
|
|
case 5:
|
|
|
|
|
convert_to_long_ex(type);
|
2000-04-24 20:35:30 +08:00
|
|
|
|
ocitype = (ub2) (*type)->value.lval;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
/* possible breakthru */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
case 4:
|
|
|
|
|
convert_to_long_ex(maxlen);
|
|
|
|
|
value_sz = (*maxlen)->value.lval;
|
|
|
|
|
/* possible breakthru */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
2000-10-23 03:33:59 +08:00
|
|
|
|
switch (ocitype) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
case SQLT_NTY:
|
|
|
|
|
if((*var)->type != IS_OBJECT) {
|
|
|
|
|
php_error(E_WARNING,"Variable must be allocated using OCINewCollection()");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(*var,&coll TSRMLS_CC)) == 0) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
php_error(E_WARNING,"Variable must be allocated using OCINewCollection()");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (! (mycoll = (dvoid *) coll->coll)) {
|
|
|
|
|
php_error(E_WARNING,"Collection empty");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
value_sz = sizeof(void*);
|
|
|
|
|
mode = OCI_DEFAULT;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2000-10-23 03:33:59 +08:00
|
|
|
|
case SQLT_BFILEE:
|
|
|
|
|
case SQLT_CFILEE:
|
|
|
|
|
case SQLT_CLOB:
|
|
|
|
|
case SQLT_BLOB:
|
2001-03-02 17:12:55 +08:00
|
|
|
|
case SQLT_RDD:
|
2000-10-23 03:33:59 +08:00
|
|
|
|
if ((*var)->type != IS_OBJECT) {
|
|
|
|
|
php_error(E_WARNING,"Variable must be allocated using OCINewDescriptor()");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocidesc(*var,&descr TSRMLS_CC)) == 0) {
|
2000-10-23 03:33:59 +08:00
|
|
|
|
php_error(E_WARNING,"Variable must be allocated using OCINewDescriptor()");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
2000-10-23 03:33:59 +08:00
|
|
|
|
if (! (mydescr = (dvoid *) descr->ocidescr)) {
|
|
|
|
|
php_error(E_WARNING,"Descriptor empty");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
value_sz = sizeof(void*);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SQLT_RSET:
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCI_GET_STMT(bindstmt,var);
|
2000-10-23 03:33:59 +08:00
|
|
|
|
|
|
|
|
|
if (! (mystmt = bindstmt->pStmt)) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
value_sz = sizeof(void*);
|
2000-10-23 03:33:59 +08:00
|
|
|
|
break;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ocitype == SQLT_CHR) && (value_sz == -1)) {
|
|
|
|
|
convert_to_string_ex(var);
|
|
|
|
|
value_sz = (*var)->value.str.len;
|
2000-04-21 17:54:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value_sz == 0) {
|
|
|
|
|
value_sz = 1;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_string_ex(name);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (! statement->binds) {
|
2001-06-20 00:03:35 +08:00
|
|
|
|
ALLOC_HASHTABLE(statement->binds);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_hash_init(statement->binds, 13, NULL, _oci_bind_hash_dtor, 0);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
memset((void*)&bind,0,sizeof(oci_bind));
|
|
|
|
|
zend_hash_next_index_insert(statement->binds,&bind,sizeof(oci_bind),(void **)&bindp);
|
|
|
|
|
|
|
|
|
|
bindp->descr = mydescr;
|
|
|
|
|
bindp->pStmt = mystmt;
|
|
|
|
|
bindp->zval = *var;
|
|
|
|
|
zval_add_ref(var);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
statement->error =
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCIBindByName(statement->pStmt, /* statement handle */
|
|
|
|
|
(OCIBind **)&bindp->pBind, /* bind hdl (will alloc) */
|
|
|
|
|
statement->pError, /* error handle */
|
|
|
|
|
(text*) (*name)->value.str.val, /* placeholder name */
|
|
|
|
|
(*name)->value.str.len, /* placeholder length */
|
|
|
|
|
(dvoid *)0, /* in/out data */
|
2000-02-01 22:39:59 +08:00
|
|
|
|
value_sz, /* OCI_MAX_DATA_SIZE, */ /* max size of input/output data */
|
2000-01-16 21:30:57 +08:00
|
|
|
|
(ub2)ocitype, /* in/out data type */
|
|
|
|
|
(dvoid *)&bindp->indicator, /* indicator (ignored) */
|
|
|
|
|
(ub2 *)0, /* size array (ignored) */
|
|
|
|
|
(ub2 *)&bindp->retcode, /* return code (ignored) */
|
|
|
|
|
(ub4)0, /* maxarr_len (PL/SQL only?) */
|
|
|
|
|
(ub4 *)0, /* actual array size (PL/SQL only?) */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
mode /* mode */);
|
|
|
|
|
#else
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCI_DATA_AT_EXEC /* mode */);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#endif
|
2000-01-16 21:30:57 +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, "OCIBindByName", statement->error);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
if(mode == OCI_DATA_AT_EXEC) {
|
|
|
|
|
#endif
|
1999-05-12 22:28:01 +08:00
|
|
|
|
statement->error =
|
2000-01-16 21:30:57 +08:00
|
|
|
|
OCIBindDynamic(bindp->pBind,
|
1999-05-12 22:28:01 +08:00
|
|
|
|
statement->pError,
|
2000-01-16 21:30:57 +08:00
|
|
|
|
(dvoid *)bindp,
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_bind_in_callback,
|
2000-01-16 21:30:57 +08:00
|
|
|
|
(dvoid *)bindp,
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_bind_out_callback);
|
2000-01-16 21:30:57 +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, "OCIBindDynamic", statement->error);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
if(ocitype == SQLT_NTY) {
|
|
|
|
|
/* Bind object */
|
|
|
|
|
statement->error = OCIBindObject(bindp->pBind,
|
|
|
|
|
statement->pError,
|
|
|
|
|
coll->tdo,
|
|
|
|
|
(dvoid **) &(coll->coll),
|
|
|
|
|
(ub4 *) 0, (dvoid **) 0, (ub4 *) 0);
|
|
|
|
|
if (statement->error) {
|
|
|
|
|
oci_error(statement->pError, "OCIBindObject", statement->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* {{{ proto string ocifreedesc(object lob)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Deletes large object description */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
PHP_FUNCTION(ocifreedesc)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *id;
|
|
|
|
|
int inx;
|
|
|
|
|
oci_descriptor *descriptor;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-07-12 19:49:32 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
inx = _oci_get_ocidesc(id,&descriptor TSRMLS_CC);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (inx) {
|
|
|
|
|
oci_debug("OCIfreedesc: descr=%d",inx);
|
|
|
|
|
zend_list_delete(inx);
|
|
|
|
|
RETURN_TRUE;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-14 21:06:03 +08:00
|
|
|
|
php_error(E_NOTICE, "OCIFreeDesc() should not be called like this. Use $somelob->free() to free a LOB");
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
/* {{{ proto string ocisavelob(object lob)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Saves a large object */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
PHP_FUNCTION(ocisavelob)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *id, **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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int offparam,inx;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 loblen;
|
1999-09-14 20:41:00 +08:00
|
|
|
|
ub4 curloblen;
|
|
|
|
|
ub4 offset;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-07-12 19:49:32 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocidesc(id,&descr TSRMLS_CC)) == 0) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
mylob = (OCILobLocator *) descr->ocidescr;
|
|
|
|
|
|
|
|
|
|
if (! mylob) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
connection = descr->conn;
|
|
|
|
|
|
1999-09-14 20:41:00 +08:00
|
|
|
|
offset = 0;
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &arg, &oarg) == SUCCESS) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_long_ex(oarg);
|
|
|
|
|
offparam = (*oarg)->value.lval;
|
1999-09-14 20:41:00 +08:00
|
|
|
|
|
|
|
|
|
connection->error =
|
|
|
|
|
OCILobGetLength(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mylob,
|
|
|
|
|
&curloblen);
|
|
|
|
|
|
|
|
|
|
oci_debug("OCIsavedesc: curloblen=%d",curloblen);
|
|
|
|
|
|
|
|
|
|
if (offparam == -1) {
|
|
|
|
|
offset = curloblen;
|
2001-05-31 01:49:33 +08:00
|
|
|
|
} else if ((ub4) offparam >= curloblen) {
|
1999-12-18 04:55:31 +08:00
|
|
|
|
php_error(E_WARNING, "Offset smaller than current LOB-Size - appending");
|
1999-09-14 20:41:00 +08:00
|
|
|
|
offset = curloblen;
|
|
|
|
|
} else {
|
|
|
|
|
offset = offparam;
|
|
|
|
|
}
|
1999-12-19 06:40:35 +08:00
|
|
|
|
} else if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 20:41:00 +08:00
|
|
|
|
offset++;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_string_ex(arg);
|
|
|
|
|
loblen = (*arg)->value.str.len;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
if (loblen < 1) {
|
1999-12-18 04:55:31 +08:00
|
|
|
|
php_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-09-14 20:41:00 +08:00
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
connection->error =
|
|
|
|
|
OCILobWrite(connection->pServiceContext,
|
1999-09-14 20:41:00 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
mylob,
|
|
|
|
|
&loblen,
|
|
|
|
|
(ub4) offset,
|
1999-09-30 16:41:45 +08:00
|
|
|
|
(dvoid *) (*arg)->value.str.val,
|
1999-09-14 20:41:00 +08:00
|
|
|
|
(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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-13 19:49:07 +08:00
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
1999-09-13 19:49:07 +08:00
|
|
|
|
/* {{{ proto string ocisavelobfile(object lob)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Saves a large object file */
|
1999-09-13 19:49:07 +08:00
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocisavelobfile)
|
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *id, **arg;
|
1999-09-13 19:49:07 +08:00
|
|
|
|
OCILobLocator *mylob;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_descriptor *descr;
|
|
|
|
|
char *filename;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int fp,inx;
|
1999-09-13 19:49:07 +08:00
|
|
|
|
char buf[8192];
|
|
|
|
|
ub4 offset = 1;
|
|
|
|
|
ub4 loblen;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocidesc(id,&descr TSRMLS_CC)) == 0) {
|
1999-09-13 19:49:07 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mylob = (OCILobLocator *) descr->ocidescr;
|
|
|
|
|
|
|
|
|
|
if (! mylob) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
connection = descr->conn;
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
1999-09-13 19:49:07 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_string_ex(arg);
|
1999-09-13 19:49:07 +08:00
|
|
|
|
|
2001-07-31 15:09:49 +08:00
|
|
|
|
if (php_check_open_basedir((*arg)->value.str.val TSRMLS_CC)) {
|
1999-09-13 19:49:07 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
filename = (*arg)->value.str.val;
|
1999-09-13 19:49:07 +08:00
|
|
|
|
|
2001-08-05 09:43:02 +08:00
|
|
|
|
if ((fp = VCWD_OPEN(filename, O_RDONLY|O_BINARY)) == -1) {
|
1999-09-13 19:49:07 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-09-13 19:49:07 +08:00
|
|
|
|
close(fp);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset += loblen;
|
|
|
|
|
}
|
|
|
|
|
close(fp);
|
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
/* {{{ proto string ociloadlob(object lob)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Loads a large object */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-13 18:52:54 +08:00
|
|
|
|
PHP_FUNCTION(ociloadlob)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *id;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_descriptor *descr;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
char *buffer;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int inx;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 loblen;
|
|
|
|
|
|
1999-07-12 19:49:32 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocidesc(id,&descr TSRMLS_CC)) == 0) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-18 19:10:30 +08:00
|
|
|
|
if (!oci_loadlob(descr->conn,descr,&buffer,&loblen)) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_STRINGL(buffer,loblen,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2000-02-23 23:54:23 +08:00
|
|
|
|
/* {{{ proto void ociwritelobtofile(object lob [, string filename] [, int start] [, int length])
|
|
|
|
|
Writes a large object into a file */
|
1999-10-28 01:51:22 +08:00
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ociwritelobtofile)
|
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval *id, **zfilename, **zstart, **zlength;
|
1999-10-28 01:51:22 +08:00
|
|
|
|
char *filename = NULL;
|
|
|
|
|
int start = -1;
|
|
|
|
|
ub4 length = -1;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_descriptor *descr;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
char *buffer=0;
|
1999-10-28 01:51:22 +08:00
|
|
|
|
ub4 loblen;
|
2000-06-06 03:47:54 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int fp = -1,inx;
|
1999-10-28 01:51:22 +08:00
|
|
|
|
OCILobLocator *mylob;
|
|
|
|
|
int coffs;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocidesc(id,&descr TSRMLS_CC)) == 0) {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mylob = (OCILobLocator *) descr->ocidescr;
|
|
|
|
|
|
|
|
|
|
if (! mylob) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
connection = descr->conn;
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (ac < 0 || ac > 3 || zend_get_parameters_ex(ac, &zfilename, &zstart, &zlength) == FAILURE) {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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) {
|
2001-07-31 15:09:49 +08:00
|
|
|
|
if (php_check_open_basedir(filename TSRMLS_CC)) {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-05 09:43:02 +08:00
|
|
|
|
if ((fp = VCWD_OPEN_MODE(filename,O_CREAT | O_RDWR | O_BINARY | O_TRUNC, 0600)) == -1) {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fp != -1) {
|
2001-05-31 01:49:33 +08:00
|
|
|
|
if ((ub4) write(fp,buffer,toread) != toread) {
|
1999-10-28 01:51:22 +08:00
|
|
|
|
php_error(E_WARNING, "cannot write file!");
|
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2001-02-15 22:49:01 +08:00
|
|
|
|
PHPWRITE(buffer,toread);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-10-28 01:51:22 +08:00
|
|
|
|
goto bail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bail:
|
|
|
|
|
if (fp != -1) {
|
|
|
|
|
close(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer) {
|
|
|
|
|
efree(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2001-04-14 17:51:29 +08:00
|
|
|
|
#ifdef HAVE_OCI8_TEMP_LOB
|
2001-04-14 16:38:46 +08:00
|
|
|
|
/* {{{ proto int ociwritetemporarylob(int stmt, int loc, string var)
|
|
|
|
|
Return the row count of an OCI statement */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ociwritetemporarylob)
|
|
|
|
|
{
|
|
|
|
|
zval *id, **var;
|
|
|
|
|
OCILobLocator *mylob;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_descriptor *descr;
|
|
|
|
|
ub4 offset = 1;
|
|
|
|
|
ub4 loblen;
|
|
|
|
|
|
|
|
|
|
oci_debug ("oci_write_temporary_lob");
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) == 0) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if (_oci_get_ocidesc(id,&descr TSRMLS_CC) == 0) {
|
2001-04-14 16:38:46 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mylob = (OCILobLocator *) descr->ocidescr;
|
|
|
|
|
|
|
|
|
|
if (! mylob) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection = descr->conn;
|
|
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(1, &var) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
convert_to_string_ex(var);
|
|
|
|
|
|
|
|
|
|
connection->error =
|
|
|
|
|
OCILobCreateTemporary(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mylob,
|
|
|
|
|
OCI_DEFAULT,
|
|
|
|
|
OCI_DEFAULT,
|
|
|
|
|
OCI_TEMP_CLOB,
|
|
|
|
|
TRUE,
|
|
|
|
|
OCI_DURATION_SESSION);
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCILobCreateTemporary", connection->error);
|
|
|
|
|
oci_handle_error(connection, connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection->error =
|
|
|
|
|
OCILobOpen(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mylob,
|
|
|
|
|
OCI_LOB_READWRITE);
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCILobOpen", connection->error);
|
|
|
|
|
oci_handle_error(connection, connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
convert_to_string_ex(var);
|
|
|
|
|
loblen = (*var)->value.str.len;
|
|
|
|
|
|
|
|
|
|
if (loblen < 1) {
|
|
|
|
|
php_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection->error =
|
|
|
|
|
OCILobWrite(connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mylob,
|
|
|
|
|
(ub4 *) &loblen,
|
|
|
|
|
(ub4) offset,
|
|
|
|
|
(dvoid *) (*var)->value.str.val,
|
|
|
|
|
(ub4) loblen,
|
|
|
|
|
OCI_ONE_PIECE,
|
|
|
|
|
(dvoid *)0,
|
|
|
|
|
(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
|
|
|
|
|
(ub2) 0,
|
|
|
|
|
(ub1) SQLCS_IMPLICIT );
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCILobWrite", connection->error);
|
|
|
|
|
oci_handle_error(connection, connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicloselob(object lob)
|
|
|
|
|
Closes lob descriptor */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicloselob)
|
|
|
|
|
{
|
|
|
|
|
zval *id;
|
|
|
|
|
int inx;
|
|
|
|
|
OCILobLocator *mylob;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_descriptor *descriptor;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
inx = _oci_get_ocidesc(id,&descriptor TSRMLS_CC);
|
2001-04-14 16:38:46 +08:00
|
|
|
|
if (inx) {
|
|
|
|
|
|
|
|
|
|
mylob = (OCILobLocator *) descriptor->ocidescr;
|
|
|
|
|
|
|
|
|
|
if (! mylob) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection = descriptor->conn;
|
|
|
|
|
|
|
|
|
|
connection->error = OCILobClose (connection->pServiceContext,
|
|
|
|
|
connection->pError,
|
|
|
|
|
mylob);
|
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCILobClose", connection->error);
|
|
|
|
|
oci_handle_error(connection, connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oci_debug("oci_close_lob: descr=%d",inx);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
php_error(E_NOTICE, "OCICloselob() should not be called like this. Use $somelob->close() to close a LOB");
|
|
|
|
|
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-03-15 05:17:07 +08:00
|
|
|
|
/* {{{ proto string ocinewdescriptor(int connection [, int type])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Initialize a new empty descriptor LOB/FILE (LOB is default) */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocinewdescriptor)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn, **type;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_descriptor *descr;
|
|
|
|
|
int dtype;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
dtype = OCI_DTYPE_LOB;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &conn, &type) == SUCCESS) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_long_ex(type);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
dtype = (*type)->value.lval;
|
1999-12-19 06:40:35 +08:00
|
|
|
|
} else if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_CONN(connection,conn);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
descr = oci_new_desc(dtype,connection);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
object_init_ex(return_value, oci_lob_class_entry_ptr);
|
|
|
|
|
add_property_resource(return_value, "descriptor", descr->id);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocirollback(int conn)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Rollback the current context */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocirollback)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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-04-25 02:54:02 +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, "OCIRollback", connection->error);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicommit(int conn)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Commit the current context */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicommit)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_CONN(connection,conn);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug("<OCITransCommit");
|
|
|
|
|
|
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
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
oci_debug(">OCITransCommit");
|
|
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicolumnname(int stmt, int col)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Tell the name of a column */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumnname)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocicolumnsize(int stmt, int col)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Tell the maximum data size of a column */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumnsize)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2000-03-03 09:28:27 +08:00
|
|
|
|
|
|
|
|
|
oci_debug("ocicolumnsize: %16s, retlen = %4d, retlen4 = %d, data_size = %4d, storage_size4 = %4d, indicator %4d, retcode = %4d",
|
|
|
|
|
outcol->name,outcol->retlen,outcol->retlen4,outcol->data_size,outcol->storage_size4,outcol->indicator,outcol->retcode);
|
|
|
|
|
|
|
|
|
|
/* Handle data type of LONG */
|
|
|
|
|
if(outcol->data_type == SQLT_LNG){
|
|
|
|
|
RETURN_LONG(outcol->storage_size4);
|
|
|
|
|
}else{
|
|
|
|
|
RETURN_LONG(outcol->data_size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocicolumnscale(int stmt, int col)
|
2000-03-03 09:28:27 +08:00
|
|
|
|
Tell the scale of a column */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicolumnscale)
|
|
|
|
|
{
|
|
|
|
|
zval **stmt, **col;
|
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_out_column *outcol;
|
|
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
|
|
|
|
outcol = oci_get_col(statement, -1, col);
|
|
|
|
|
if (outcol == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETURN_LONG(outcol->scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocicolumnprecision(int stmt, int col)
|
2000-03-03 09:28:27 +08:00
|
|
|
|
Tell the precision of a column */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicolumnprecision)
|
|
|
|
|
{
|
|
|
|
|
zval **stmt, **col;
|
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_out_column *outcol;
|
|
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
|
|
|
|
outcol = oci_get_col(statement, -1, col);
|
|
|
|
|
if (outcol == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETURN_LONG(outcol->precision);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2000-03-15 05:47:47 +08:00
|
|
|
|
/* {{{ proto mixed ocicolumntype(int stmt, int col)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Tell the data type of a column */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumntype)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt, **col;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_out_column *outcol;
|
2000-03-03 09:28:27 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-03 09:28:27 +08:00
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2000-03-15 05:47:47 +08:00
|
|
|
|
/* {{{ proto mixed ocicolumntyperaw(int stmt, int col)
|
2000-03-03 09:28:27 +08:00
|
|
|
|
Tell the raw oracle data type of a column */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicolumntyperaw)
|
|
|
|
|
{
|
|
|
|
|
zval **stmt, **col;
|
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_out_column *outcol;
|
|
|
|
|
|
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
|
|
|
|
outcol = oci_get_col(statement, -1, col);
|
|
|
|
|
if (outcol == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
RETVAL_LONG(outcol->data_type);
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocicolumnisnull(int stmt, int col)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Tell whether a column is NULL */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicolumnisnull)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2000-05-24 06:30:21 +08:00
|
|
|
|
/* {{{ proto void ociinternaldebug(int onoff)
|
|
|
|
|
Toggle internal debugging output for the OCI extension */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
/* 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
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **arg;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_long_ex(arg);
|
|
|
|
|
OCI(debug_mode) = (*arg)->value.lval;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ociexecute(int stmt [, int mode])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Execute a parsed statement */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ociexecute)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt,**mode;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 execmode;
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &mode) == SUCCESS) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_long_ex(mode);
|
|
|
|
|
execmode = (*mode)->value.lval;
|
1999-12-19 06:40:35 +08:00
|
|
|
|
} else if (zend_get_parameters_ex(1, &stmt) == SUCCESS) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
execmode = OCI_COMMIT_ON_SUCCESS;
|
|
|
|
|
} else {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (oci_execute(statement, "OCIExecute",execmode)) {
|
1999-05-12 22:28:01 +08:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocicancel(int stmt)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Prepare a new row of data for reading */
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocicancel)
|
1999-05-12 22:28:01 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-05-12 22:28:01 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if (oci_fetch(statement, 0, "OCICancel" TSRMLS_CC)) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocifetch(int stmt)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Prepare a new row of data for reading */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocifetch)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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 */
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if (oci_fetch(statement, nrows, "OCIFetch" TSRMLS_CC)) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocifetchinto(int stmt, array &output [, int mode])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Fetch a row of result data into an array */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocifetchinto)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
int i, used;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
int mode = OCI_NUM;
|
2000-06-06 03:47:54 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &stmt, &array, &fmode) == FAILURE) {
|
1999-09-30 16:41:45 +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
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if (!oci_fetch(statement, nrows, "OCIFetchInto" TSRMLS_CC)) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
zval_dtor(*array);
|
|
|
|
|
if (array_init(*array) == FAILURE) {
|
|
|
|
|
php_error(E_WARNING, "OCIFetchInto: unable to convert arg 2 to array");
|
|
|
|
|
RETURN_FALSE;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < statement->ncolumns; i++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
column = oci_get_col(statement, i + 1, 0);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (column == NULL) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
if ((column->indicator == -1) && ((mode & OCI_RETURN_NULLS) == 0)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
used = 0;
|
|
|
|
|
MAKE_STD_ZVAL(element);
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_make_zval(element,statement,column,"OCIFetchInto",mode TSRMLS_CC);
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
|
|
|
|
if ((mode & OCI_NUM) || (! (mode & OCI_ASSOC))) {
|
|
|
|
|
zend_hash_index_update((*array)->value.ht,i,(void *)&element,sizeof(zval*),NULL);
|
|
|
|
|
used=1;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode & OCI_ASSOC) {
|
2000-01-16 21:30:57 +08:00
|
|
|
|
if (used) {
|
|
|
|
|
element->refcount++;
|
|
|
|
|
}
|
|
|
|
|
zend_hash_update((*array)->value.ht,column->name,column->name_len+1,(void *)&element,sizeof(zval*),NULL);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_LONG(statement->ncolumns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocifetchstatement(int stmt, array &output)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Fetch all rows of result data into an array */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocifetchstatement)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt, **array, *element, **fmode, *tmp;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
|
|
|
|
oci_out_column **columns;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval ***outarrs;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 nrows = 1;
|
|
|
|
|
int i;
|
|
|
|
|
int mode = OCI_NUM;
|
|
|
|
|
int rows = 0;
|
2000-11-14 01:30:52 +08:00
|
|
|
|
char *namebuf;
|
2000-06-06 03:47:54 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &stmt, &array, &fmode) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
switch (ac) {
|
|
|
|
|
case 3:
|
|
|
|
|
convert_to_long_ex(fmode);
|
|
|
|
|
mode = (*fmode)->value.lval;
|
|
|
|
|
/* possible breakthru */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval_dtor(*array);
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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 *));
|
2000-01-16 21:30:57 +08:00
|
|
|
|
outarrs = emalloc(statement->ncolumns * sizeof(zval*));
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
for (i = 0; i < statement->ncolumns; i++) {
|
1999-09-30 16:41:45 +08:00
|
|
|
|
columns[ i ] = oci_get_col(statement, i + 1, 0);
|
2000-01-16 21:30:57 +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
|
|
|
|
|
2000-11-14 01:30:52 +08:00
|
|
|
|
namebuf = estrndup(columns[ i ]->name,columns[ i ]->name_len);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_hash_update((*array)->value.ht, namebuf, columns[ i ]->name_len+1, (void *) &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
|
2000-11-14 01:30:52 +08:00
|
|
|
|
efree(namebuf);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
while (oci_fetch(statement, nrows, "OCIFetchStatement" TSRMLS_CC)) {
|
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
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_make_zval(element,statement,columns[ i ], "OCIFetchStatement",OCI_RETURN_LOBS TSRMLS_CC);
|
1999-06-09 18:40:08 +08:00
|
|
|
|
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zend_hash_index_update((*(outarrs[ i ]))->value.ht, rows, (void *)&element, sizeof(zval*), NULL);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
rows++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
efree(columns);
|
|
|
|
|
efree(outarrs);
|
|
|
|
|
|
|
|
|
|
RETURN_LONG(rows);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocifreestatement(int stmt)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Free all resources associated with a statement */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocifreestatement)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
1999-10-06 00:06:54 +08:00
|
|
|
|
zend_list_delete(statement->id);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocilogoff(int conn)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Disconnect from database */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocilogoff)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#if 0
|
|
|
|
|
this function does nothing any more. server-connections get automagiclly closed on
|
|
|
|
|
request-end. connection handles will "dissappear" as soon as they are no longer
|
|
|
|
|
referenced. as this module makes heavy use of zends reference-counting mechanism
|
|
|
|
|
this is the desired behavior. it has always been a bad idea to close a connection that
|
|
|
|
|
has outstanding transactions. this way we have a nice-clean approach.
|
2000-10-29 17:14:55 +08:00
|
|
|
|
(thies@thieso.net 20000110)
|
2000-01-16 21:30:57 +08:00
|
|
|
|
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_CONN(connection,conn);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2001-05-04 22:53:45 +08:00
|
|
|
|
connection->is_open = 0;
|
1999-06-09 18:40:08 +08:00
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
|
zend_hash_apply(list, (apply_func_t) _stmt_cleanup TSRMLS_CC);
|
1999-06-09 18:40:08 +08:00
|
|
|
|
|
1999-10-06 00:06:54 +08:00
|
|
|
|
if (zend_list_delete(connection->id) == SUCCESS) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2000-01-16 21:30:57 +08:00
|
|
|
|
#endif
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-12 22:28:01 +08:00
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocinlogon(string user, string pass [, string db])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Connect to an Oracle database and log on. returns a new session */
|
1999-05-12 22:28:01 +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(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
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocilogon(string user, string pass [, string db])
|
|
|
|
|
Connect to an Oracle database 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(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ociplogon(string user, string pass [, string db])
|
2000-02-23 23:54:23 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2000-08-11 21:13:11 +08:00
|
|
|
|
/* {{{ proto array ocierror([int stmt|conn|global])
|
2000-02-23 23:54:23 +08:00
|
|
|
|
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
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == SUCCESS) {
|
2001-07-30 12:58:07 +08:00
|
|
|
|
statement = (oci_statement *) zend_fetch_resource(arg TSRMLS_CC, -1, NULL, NULL, 1, le_stmt);
|
1999-09-30 16:41:45 +08:00
|
|
|
|
if (statement) {
|
1999-05-12 22:28:01 +08:00
|
|
|
|
errh = statement->pError;
|
|
|
|
|
error = statement->error;
|
|
|
|
|
} else {
|
2001-07-30 12:58:07 +08:00
|
|
|
|
connection = (oci_connection *) zend_fetch_resource(arg TSRMLS_CC, -1, NULL, NULL, 1, le_conn);
|
1999-09-30 16:41:45 +08:00
|
|
|
|
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) {
|
1999-08-03 03:17:14 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocinumcols(int stmt)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Return the number of result columns in a statement */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocinumcols)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_LONG(statement->ncolumns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ociparse(int conn, string query)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Parse a query and return a statement */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ociparse)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn, **query;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &conn, &query) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_CONN(connection,conn);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +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
|
|
|
|
|
2000-05-30 17:25:02 +08:00
|
|
|
|
if (statement) {
|
|
|
|
|
RETURN_RESOURCE(statement->id);
|
|
|
|
|
} else {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-07-08 22:12:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
2001-07-14 20:45:42 +08:00
|
|
|
|
/* {{{ proto int ocisetprefetch(int stmt, int prefetch_rows)
|
|
|
|
|
sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocisetprefetch)
|
1999-07-08 22:12:07 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt, **size;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &size) == FAILURE) {
|
1999-07-08 22:12:07 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
convert_to_long_ex(size);
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
1999-07-08 22:12:07 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +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
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocinewcursor(int conn)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Return a new cursor (Statement-Handle) - use this to bind ref-cursors! */
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocinewcursor)
|
1999-05-12 22:28:01 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_connection *connection;
|
1999-09-30 16:41:45 +08:00
|
|
|
|
oci_statement *statement;
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-05-12 22:28:01 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_CONN(connection,conn);
|
1999-05-12 22:28:01 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +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
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto string ociresult(int stmt, mixed column)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Return a single column of result data */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ociresult)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **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
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &stmt, &col) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
OCI_GET_STMT(statement,stmt);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
1999-09-30 16:41:45 +08:00
|
|
|
|
outcol = oci_get_col(statement, -1, col);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
|
|
|
|
if (outcol == NULL) {
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
_oci_make_zval(return_value,statement,outcol, "OCIResult",0 TSRMLS_CC);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto string ociserverversion(int conn)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
Return a string containing server version information */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
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;
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **conn;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
char version[256];
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &conn) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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-09-30 16:41:45 +08:00
|
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(connection, connection->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_STRING(version,1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
2000-03-15 05:17:07 +08:00
|
|
|
|
|
|
|
|
|
/* {{{ proto int ocistatementtype(int stmt)
|
2000-02-23 23:54:23 +08:00
|
|
|
|
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
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub2 stmttype;
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
|
/* }}} */
|
1999-04-22 06:49:16 +08:00
|
|
|
|
|
2000-03-15 05:17:07 +08:00
|
|
|
|
/* {{{ proto int ocirowcount(int stmt)
|
|
|
|
|
Return the row count of an OCI statement */
|
|
|
|
|
|
1999-08-10 22:33:59 +08:00
|
|
|
|
PHP_FUNCTION(ocirowcount)
|
1999-04-22 06:49:16 +08:00
|
|
|
|
{
|
2000-01-16 21:30:57 +08:00
|
|
|
|
zval **stmt;
|
1999-08-17 21:54:25 +08:00
|
|
|
|
oci_statement *statement;
|
1999-04-22 06:49:16 +08:00
|
|
|
|
ub4 rowcount;
|
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &stmt) == FAILURE) {
|
1999-04-22 06:49:16 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
1999-09-30 16:41:45 +08:00
|
|
|
|
|
|
|
|
|
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);
|
2001-02-12 22:36:28 +08:00
|
|
|
|
oci_handle_error(statement->conn, statement->error);
|
1999-04-22 06:49:16 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RETURN_LONG(rowcount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
#ifdef WITH_COLLECTIONS
|
|
|
|
|
/* {{{ oci_get_coll() */
|
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
static oci_collection *oci_get_coll(int ind TSRMLS_DC)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{
|
|
|
|
|
oci_collection *collection;
|
|
|
|
|
int actual_resource_type;
|
|
|
|
|
|
|
|
|
|
collection = (oci_collection *) zend_list_find(ind, &actual_resource_type);
|
|
|
|
|
|
|
|
|
|
if (collection && (actual_resource_type == le_coll)) {
|
|
|
|
|
return collection;
|
|
|
|
|
} else {
|
|
|
|
|
return (oci_collection *) NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
|
/* }}} */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-06-06 08:08:21 +08:00
|
|
|
|
/* {{{ proto string ocifreecollection(object lob)
|
2001-04-26 01:48:30 +08:00
|
|
|
|
Deletes collection object*/
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-06-06 08:08:21 +08:00
|
|
|
|
PHP_FUNCTION(ocifreecollection)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{
|
|
|
|
|
zval *id;
|
|
|
|
|
int inx;
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
oci_connection *connection;
|
2001-05-31 01:43:32 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
inx = _oci_get_ocicoll(id,&coll TSRMLS_CC);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (inx) {
|
|
|
|
|
/*
|
2001-04-26 01:48:30 +08:00
|
|
|
|
* Do we need to free the object?
|
|
|
|
|
*
|
2001-04-13 22:43:39 +08:00
|
|
|
|
*/
|
|
|
|
|
connection = coll->conn;
|
2001-06-06 08:08:21 +08:00
|
|
|
|
oci_debug("OCIfreecollection: coll=%d",inx);
|
2001-05-23 07:16:03 +08:00
|
|
|
|
connection->error = OCIObjectFree(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
(dvoid *)coll->coll,
|
|
|
|
|
(ub2)(OCI_OBJECTFREE_FORCE));
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIObjectFree", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
zend_list_delete(inx);
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicollappend(object collection,value)
|
|
|
|
|
Append an object to the collection */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicollappend)
|
|
|
|
|
{
|
|
|
|
|
zval *id, **arg;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
OCINumber num;
|
|
|
|
|
OCIString *ocistr = (OCIString *)0;
|
|
|
|
|
OCIInd new_ind = OCI_IND_NOTNULL;
|
|
|
|
|
OCIDate dt;
|
|
|
|
|
int inx;
|
|
|
|
|
double ndx;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection = coll->conn;
|
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(coll->element_typecode) {
|
|
|
|
|
case OCI_TYPECODE_DATE:
|
|
|
|
|
convert_to_string_ex(arg);
|
|
|
|
|
connection->error = OCIDateFromText(connection->pError,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
(*arg)->value.str.val,
|
|
|
|
|
(*arg)->value.str.len,
|
|
|
|
|
0,0,0,0,&dt);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIDateFromText", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
connection->error = OCICollAppend(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
(dvoid *) &dt,
|
|
|
|
|
(dvoid *) &new_ind,
|
|
|
|
|
(OCIColl *) coll->coll);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollAppend", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_TRUE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
break;
|
|
|
|
|
case OCI_TYPECODE_VARCHAR2 :
|
|
|
|
|
convert_to_string_ex(arg);
|
|
|
|
|
connection->error = OCIStringAssignText(OCI(pEnv),
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
(*arg)->value.str.val,
|
|
|
|
|
(*arg)->value.str.len,
|
|
|
|
|
&ocistr);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIStringAssignText", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
connection->error = OCICollAppend(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
(dvoid *) ocistr,
|
|
|
|
|
(dvoid *) &new_ind,
|
|
|
|
|
(OCIColl *) coll->coll);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollAppend", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_TRUE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
break;
|
|
|
|
|
case OCI_TYPECODE_UNSIGNED16 : /* UNSIGNED SHORT */
|
|
|
|
|
case OCI_TYPECODE_UNSIGNED32 : /* UNSIGNED LONG */
|
|
|
|
|
case OCI_TYPECODE_REAL : /* REAL */
|
|
|
|
|
case OCI_TYPECODE_DOUBLE : /* DOUBLE */
|
|
|
|
|
case OCI_TYPECODE_INTEGER : /* INT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED16 : /* SHORT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED32 : /* LONG */
|
|
|
|
|
case OCI_TYPECODE_DECIMAL : /* DECIMAL */
|
|
|
|
|
case OCI_TYPECODE_FLOAT : /* FLOAT */
|
|
|
|
|
case OCI_TYPECODE_NUMBER : /* NUMBER */
|
|
|
|
|
case OCI_TYPECODE_SMALLINT : /* SMALLINT */
|
|
|
|
|
convert_to_double_ex(arg);
|
|
|
|
|
ndx = (double)(*arg)->value.dval;
|
|
|
|
|
connection->error = OCINumberFromReal(connection->pError,&ndx,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
sizeof(double),&num);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCINumberFromReal", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection->error = OCICollAppend(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
(dvoid *) &num,
|
|
|
|
|
(dvoid *) &new_ind,
|
|
|
|
|
(OCIColl *) coll->coll);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_TRUE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
/* {{{ proto string ocicollgetelem(object collection,ndx)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
Retrieve the value at collection index ndx */
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
PHP_FUNCTION(ocicollgetelem)
|
2001-04-13 22:43:39 +08:00
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id,**arg;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
ub4 ndx;
|
|
|
|
|
int inx;
|
|
|
|
|
dvoid *elem;
|
|
|
|
|
dvoid *elemind;
|
|
|
|
|
boolean exists;
|
|
|
|
|
OCIString *ocistr = (OCIString *)0;
|
|
|
|
|
text *str;
|
|
|
|
|
char buff[1024];
|
2001-04-13 22:43:39 +08:00
|
|
|
|
int len;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
double dnum;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
convert_to_long_ex(arg);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
ndx = (*arg)->value.lval;
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection = coll->conn;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
connection->error = OCICollGetElem(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
coll->coll,
|
|
|
|
|
ndx,
|
|
|
|
|
&exists,
|
|
|
|
|
&elem,
|
|
|
|
|
&elemind);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollGetElem", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
switch(coll->element_typecode) {
|
|
|
|
|
case OCI_TYPECODE_DATE:
|
|
|
|
|
len = 1024;
|
|
|
|
|
OCIDateToText(connection->pError,
|
|
|
|
|
elem,
|
|
|
|
|
0, /* fmt */
|
|
|
|
|
0, /* fmt_length */
|
|
|
|
|
0, /* lang_name */
|
|
|
|
|
0, /* lang_length */
|
|
|
|
|
&len,buff);
|
|
|
|
|
RETURN_STRINGL(buff,len,1);
|
|
|
|
|
case OCI_TYPECODE_VARCHAR2 :
|
|
|
|
|
ocistr = *(OCIString **)elem;
|
|
|
|
|
str = OCIStringPtr(OCI(pEnv),ocistr);
|
|
|
|
|
RETURN_STRINGL(str,strlen(str),1);
|
|
|
|
|
break;
|
|
|
|
|
case OCI_TYPECODE_UNSIGNED16 : /* UNSIGNED SHORT */
|
2001-04-26 01:48:30 +08:00
|
|
|
|
case OCI_TYPECODE_UNSIGNED32 : /* UNSIGNED LONG */
|
|
|
|
|
case OCI_TYPECODE_REAL : /* REAL */
|
|
|
|
|
case OCI_TYPECODE_DOUBLE : /* DOUBLE */
|
|
|
|
|
case OCI_TYPECODE_INTEGER : /* INT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED16 : /* SHORT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED32 : /* LONG */
|
|
|
|
|
case OCI_TYPECODE_DECIMAL : /* DECIMAL */
|
|
|
|
|
case OCI_TYPECODE_FLOAT : /* FLOAT */
|
|
|
|
|
case OCI_TYPECODE_NUMBER : /* NUMBER */
|
|
|
|
|
case OCI_TYPECODE_SMALLINT : /* SMALLINT */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
connection->error = OCINumberToReal(connection->pError,
|
|
|
|
|
(CONST OCINumber *) elem,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
(uword) sizeof(dnum), (dvoid *) &dnum);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCINumberToReal", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
RETURN_DOUBLE(dnum);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-04-26 01:48:30 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
/* {{{ proto string ocicollassign(object collection,object)
|
|
|
|
|
Assign a collection from another existing collection */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicollassign)
|
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id,**from;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll,*from_coll;
|
|
|
|
|
int inx;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
if (zend_get_parameters_ex(1, &from) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(*from,&from_coll TSRMLS_CC)) == 0) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection = coll->conn;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
connection->error = OCICollAssign(OCI(pEnv),connection->pError,
|
|
|
|
|
from_coll->coll,coll->coll);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollAssignElem", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicollassignelem(object collection,ndx,val)
|
|
|
|
|
Assign element val to collection at index ndx */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicollassignelem)
|
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id,**index,**val;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
OCINumber num;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
OCIInd new_ind = OCI_IND_NOTNULL;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
ub4 ndx;
|
|
|
|
|
int inx;
|
|
|
|
|
OCIString *ocistr = (OCIString *)0;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
OCIDate dt;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
double dnum;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
if (zend_get_parameters_ex(2, &index,&val) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
convert_to_long_ex(index);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
ndx = (*index)->value.lval;
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection = coll->conn;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollAssignElem", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
switch(coll->element_typecode) {
|
|
|
|
|
case OCI_TYPECODE_DATE:
|
|
|
|
|
convert_to_string_ex(val);
|
|
|
|
|
connection->error = OCIDateFromText(connection->pError,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
(*val)->value.str.val,
|
|
|
|
|
(*val)->value.str.len,
|
|
|
|
|
0,0,0,0,&dt);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIDateFromText", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
connection->error = OCICollAssignElem(OCI(pEnv),
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
ndx,
|
|
|
|
|
(dword *)&dt,
|
|
|
|
|
&new_ind,
|
|
|
|
|
coll->coll);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
oci_error(connection->pError, "OCICollAssignElem", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case OCI_TYPECODE_VARCHAR2 :
|
|
|
|
|
convert_to_string_ex(val);
|
|
|
|
|
connection->error = OCIStringAssignText(OCI(pEnv),
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
(*val)->value.str.val,
|
|
|
|
|
(*val)->value.str.len,
|
|
|
|
|
&ocistr);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIStringAssignText", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
connection->error = OCICollAssignElem(OCI(pEnv),
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
ndx,
|
|
|
|
|
(dword *)ocistr,
|
|
|
|
|
&new_ind,
|
|
|
|
|
coll->coll);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
oci_error(connection->pError, "OCICollAssignElem", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case OCI_TYPECODE_UNSIGNED16 : /* UNSIGNED SHORT */
|
2001-04-26 01:48:30 +08:00
|
|
|
|
case OCI_TYPECODE_UNSIGNED32 : /* UNSIGNED LONG */
|
|
|
|
|
case OCI_TYPECODE_REAL : /* REAL */
|
|
|
|
|
case OCI_TYPECODE_DOUBLE : /* DOUBLE */
|
|
|
|
|
case OCI_TYPECODE_INTEGER : /* INT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED16 : /* SHORT */
|
|
|
|
|
case OCI_TYPECODE_SIGNED32 : /* LONG */
|
|
|
|
|
case OCI_TYPECODE_DECIMAL : /* DECIMAL */
|
|
|
|
|
case OCI_TYPECODE_FLOAT : /* FLOAT */
|
|
|
|
|
case OCI_TYPECODE_NUMBER : /* NUMBER */
|
|
|
|
|
case OCI_TYPECODE_SMALLINT : /* SMALLINT */
|
2001-04-13 22:43:39 +08:00
|
|
|
|
convert_to_double_ex(val);
|
|
|
|
|
dnum = (double)(*val)->value.dval;
|
|
|
|
|
connection->error = OCINumberFromReal(connection->pError,&dnum,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
sizeof(double),&num);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCINumberFromReal", connection->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
connection->error = OCICollAssignElem(OCI(pEnv),
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->pError,
|
|
|
|
|
ndx,
|
|
|
|
|
(dword *)&num,
|
|
|
|
|
&new_ind,
|
|
|
|
|
coll->coll);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
oci_error(connection->pError, "OCICollAssignElem", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicollsize(object collection)
|
|
|
|
|
Return the size of a collection */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicollsize)
|
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id;
|
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
sb4 sz;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
int inx;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
connection = coll->conn;
|
|
|
|
|
connection->error = OCICollSize(OCI(pEnv),coll->conn->pError,coll->coll,&sz);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCICollSize", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
RETURN_LONG(sz);
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
2001-04-26 01:48:30 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
/* {{{ proto string ocicollmax(object collection)
|
|
|
|
|
Return the max value of a collection. For a
|
|
|
|
|
varray this is the maximum length of the array */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicollmax)
|
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id;
|
|
|
|
|
oci_collection *coll;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
sb4 sz;
|
2001-04-26 01:48:30 +08:00
|
|
|
|
int inx;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
sz = OCICollMax(OCI(pEnv),coll->coll);
|
|
|
|
|
RETURN_LONG(sz);
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
/* {{{ proto string ocicolltrim(object collection,num)
|
|
|
|
|
Trim num elements from the end of a collection */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocicolltrim)
|
|
|
|
|
{
|
2001-04-26 01:48:30 +08:00
|
|
|
|
zval *id,**arg;
|
|
|
|
|
oci_collection *coll;
|
|
|
|
|
int inx;
|
|
|
|
|
|
|
|
|
|
if ((id = getThis()) != 0) {
|
2001-08-01 07:47:35 +08:00
|
|
|
|
if ((inx = _oci_get_ocicoll(id,&coll TSRMLS_CC)) == 0) {
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (zend_get_parameters_ex(1, &arg) == FAILURE) {
|
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
convert_to_long_ex(arg);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
coll->conn->error = OCICollTrim(OCI(pEnv),coll->conn->pError,(*arg)->value.lval,coll->coll);
|
|
|
|
|
if (coll->conn->error) {
|
|
|
|
|
oci_error(coll->conn->pError, "OCICollTrim", coll->conn->error);
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
RETURN_FALSE;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
2001-05-23 07:16:03 +08:00
|
|
|
|
/* {{{ proto string ocinewcollection(int connection, string tdo,[string schema])
|
2001-04-13 22:43:39 +08:00
|
|
|
|
Initialize a new collection */
|
|
|
|
|
|
|
|
|
|
PHP_FUNCTION(ocinewcollection)
|
|
|
|
|
{
|
|
|
|
|
dvoid *dschp1;
|
|
|
|
|
dvoid *parmp1;
|
|
|
|
|
dvoid *parmp2;
|
2001-05-23 07:16:03 +08:00
|
|
|
|
zval **conn, **tdo, **schema;
|
2001-04-13 22:43:39 +08:00
|
|
|
|
oci_connection *connection;
|
|
|
|
|
oci_collection *coll;
|
2001-05-23 07:16:03 +08:00
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
2001-05-23 07:16:03 +08:00
|
|
|
|
if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &conn, &tdo, &schema) == FAILURE) {
|
2001-04-13 22:43:39 +08:00
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
}
|
2001-05-23 07:16:03 +08:00
|
|
|
|
|
2001-04-13 22:43:39 +08:00
|
|
|
|
convert_to_string_ex(tdo);
|
|
|
|
|
|
2001-05-23 07:16:03 +08:00
|
|
|
|
if(ac == 3) {
|
|
|
|
|
convert_to_string_ex(schema);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
coll = emalloc(sizeof(oci_collection));
|
|
|
|
|
|
|
|
|
|
OCI_GET_CONN(connection,conn);
|
|
|
|
|
|
|
|
|
|
coll->conn = connection;
|
|
|
|
|
coll->id = zend_list_insert(coll,le_coll);
|
|
|
|
|
zend_list_addref(connection->id);
|
|
|
|
|
|
|
|
|
|
connection->error = OCITypeByName(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
connection->pServiceContext,
|
2001-05-23 07:16:03 +08:00
|
|
|
|
ac==3?(text *)(*schema)->value.str.val:(text *)0,
|
|
|
|
|
ac==3?(ub4)(*schema)->value.str.len: (ub4)0,
|
2001-04-26 01:48:30 +08:00
|
|
|
|
(text *) (*tdo)->value.str.val,
|
|
|
|
|
(ub4) (*tdo)->value.str.len,
|
|
|
|
|
(CONST text *) 0, (ub4) 0,
|
|
|
|
|
OCI_DURATION_SESSION,
|
|
|
|
|
OCI_TYPEGET_ALL,
|
|
|
|
|
&(coll->tdo));
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCITypeByName", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->error = OCIHandleAlloc(OCI(pEnv), (dvoid **) &dschp1,
|
|
|
|
|
(ub4) OCI_HTYPE_DESCRIBE,
|
|
|
|
|
(size_t) 0, (dvoid **) 0);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_HTYPE_DESCRIBE", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->error = OCIDescribeAny(connection->pServiceContext, connection->pError, (dvoid *) coll->tdo,
|
|
|
|
|
(ub4) 0, OCI_OTYPE_PTR, (ub1)1,
|
|
|
|
|
(ub1) OCI_PTYPE_TYPE, dschp1);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_OTYPE_PTR", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->error = OCIAttrGet((dvoid *) dschp1,
|
|
|
|
|
(ub4) OCI_HTYPE_DESCRIBE,
|
|
|
|
|
(dvoid *)&parmp1, (ub4 *)0, (ub4)OCI_ATTR_PARAM,connection->pError);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_ATTR_PARAM", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
/* get the collection type code of the attribute */
|
|
|
|
|
connection->error = OCIAttrGet((dvoid*) parmp1, (ub4) OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid*) &(coll->coll_typecode), (ub4 *) 0,
|
|
|
|
|
(ub4) OCI_ATTR_COLLECTION_TYPECODE,
|
|
|
|
|
connection->pError);
|
2001-04-13 22:43:39 +08:00
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_ATTR_COLLECTION_TYPECODE", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 01:48:30 +08:00
|
|
|
|
switch(coll->coll_typecode) {
|
|
|
|
|
case OCI_TYPECODE_VARRAY:
|
2001-05-23 07:16:03 +08:00
|
|
|
|
case OCI_TYPECODE_TABLE:
|
2001-04-26 01:48:30 +08:00
|
|
|
|
connection->error = OCIAttrGet((dvoid*) parmp1,
|
|
|
|
|
(ub4) OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid*) &parmp2, (ub4 *) 0,
|
|
|
|
|
(ub4) OCI_ATTR_COLLECTION_ELEMENT,
|
|
|
|
|
connection->pError);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_ATTR_COLLECTION_ELEMENT", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
connection->error = OCIAttrGet((dvoid*) parmp2,
|
|
|
|
|
(ub4) OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid*) &(coll->elem_ref), (ub4 *) 0,
|
|
|
|
|
(ub4) OCI_ATTR_REF_TDO,
|
|
|
|
|
connection->pError);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_ATTR_REF_TDO", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
connection->error = OCITypeByRef(OCI(pEnv), connection->pError, coll->elem_ref,
|
|
|
|
|
OCI_DURATION_SESSION,
|
|
|
|
|
OCI_TYPEGET_HEADER, &(coll->element_type));
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_TYPEGET_HEADER", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection->error = OCIAttrGet((dvoid*) parmp2,
|
|
|
|
|
(ub4) OCI_DTYPE_PARAM,
|
|
|
|
|
(dvoid*) &(coll->element_typecode), (ub4 *) 0,
|
|
|
|
|
(ub4) OCI_ATTR_TYPECODE,
|
|
|
|
|
connection->pError);
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCI_ATTR_TYPECODE", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
php_error(E_WARNING, "OCINewCollection - Unknown Type %d", coll->coll_typecode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create object to hold return table */
|
|
|
|
|
connection->error = OCIObjectNew(OCI(pEnv),
|
|
|
|
|
connection->pError,
|
|
|
|
|
connection->pServiceContext,
|
|
|
|
|
OCI_TYPECODE_TABLE,
|
|
|
|
|
coll->tdo,
|
|
|
|
|
(dvoid *)0,
|
|
|
|
|
OCI_DURATION_DEFAULT,
|
|
|
|
|
TRUE,
|
|
|
|
|
(dvoid **) &(coll->coll));
|
|
|
|
|
if (connection->error) {
|
|
|
|
|
oci_error(connection->pError, "OCIObjectNew", connection->error);
|
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
}
|
2001-04-13 22:43:39 +08:00
|
|
|
|
|
|
|
|
|
object_init_ex(return_value, oci_coll_class_entry_ptr);
|
|
|
|
|
add_property_resource(return_value, "collection",coll->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-04-22 06:49:16 +08:00
|
|
|
|
#endif /* HAVE_OCI8 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* tab-width: 4
|
|
|
|
|
* c-basic-offset: 4
|
|
|
|
|
* End:
|
2001-06-06 21:06:12 +08:00
|
|
|
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
|
|
|
|
* vim<600: sw=4 ts=4 tw=78
|
1999-04-22 06:49:16 +08:00
|
|
|
|
*/
|