1999-04-22 06:49:16 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 23:32:16 +08:00
| PHP Version 4 |
1999-04-22 06:49:16 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2003-01-01 00:08:15 +08:00
| Copyright ( c ) 1997 - 2003 The PHP Group |
1999-04-22 06:49:16 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2003-06-11 04:04:29 +08:00
| This source file is subject to version 3.0 of the PHP license , |
1999-07-16 21:13:16 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
| http : //www.php.net/license/3_0.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
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2003-04-30 18:19:21 +08:00
| Authors : Stig S <EFBFBD> ther Bakken < ssb @ fast . no > |
2002-02-28 16:29:35 +08:00
| Thies C . Arntzen < thies @ thieso . net > |
2003-01-30 02:31:48 +08:00
| Maxim Maletsky < maxim @ maxim . cx > |
2002-02-28 16:29:35 +08:00
| |
2001-04-13 22:43:39 +08:00
| Collection support by Andy Sautins < asautins @ veripost . net > |
2002-02-28 16:29:35 +08:00
| Temporary LOB support by David Benson < dbenson @ mancala . com > |
2003-12-16 18:29:11 +08:00
| ZTS per process OCIPLogon by Harald Radi < harald . radi @ nme . at > |
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
2003-12-16 18:29:11 +08:00
* allowpconns
* timeout
* maxlifetime
* maxpconns
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 ? )
* - 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 . . . .
2000-01-16 21:30:57 +08:00
* - have one ocifree ( ) call .
* - make it possible to have persistent statements ?
* - 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
2002-11-15 10:06:11 +08:00
* - make auto - rollback only happen if we have an outstanding transaction
2002-02-09 02:50:12 +08:00
* - implement ocidisconnect
2003-12-15 21:53:01 +08:00
* - add OCI9 - specific functions and separate them from OCI8 with ifdefs
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"
2003-12-16 18:29:11 +08:00
# include "php_ini.h"
1999-04-25 02:54:02 +08:00
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
2003-12-16 18:29:11 +08:00
/* True globals, only used by thread safe functions */
static TsHashTable * persistent_servers ;
static TsHashTable * persistent_sessions ;
static long num_persistent = 0 ;
static long num_links = 0 ;
1999-08-17 21:54:25 +08:00
/* True globals, no need for thread safety */
2002-11-16 01:59:19 +08:00
static int le_conn ;
static int le_stmt ;
static int le_desc ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
static int le_coll ;
2001-04-13 22:43:39 +08:00
# endif
2002-11-16 01:59:19 +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 ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
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):"")
2003-12-16 18:29:11 +08:00
# ifdef ZTS
MUTEX_T mx_lock ;
2003-12-16 19:15:55 +08:00
# define mutex_alloc(mutex) mutex = tsrm_mutex_alloc()
2003-12-16 18:29:11 +08:00
# define mutex_free(mutex) tsrm_mutex_free(mutex)
# define mutex_lock(mutex) tsrm_mutex_lock(mutex)
# define mutex_unlock(mutex) tsrm_mutex_unlock(mutex)
# define thread_id() tsrm_thread_id()
# else
2003-12-16 19:15:55 +08:00
# define mutex_alloc(mutex)
2003-12-16 18:29:11 +08:00
# define mutex_free(mutex)
# define mutex_lock(mutex)
# define mutex_unlock(mutex)
# define thread_id() 1
# endif
2001-08-16 00:00:56 +08:00
/* dirty marcos to make sure we _never_ call oracle-functions recursivly
*
* i ' m well aware that we should _never_ call exit directly - this core is for
* pure testing and commented out - as you can see ; - )
* thies @ thieso . net 20010723
*/
# define CALL_OCI(call) \
{ \
if ( OCI ( in_call ) ) { \
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OCI8 Recursive call! \n " ) ; \
2001-08-16 00:00:56 +08:00
exit ( - 1 ) ; \
} else { \
OCI ( in_call ) = 1 ; \
call ; \
OCI ( in_call ) = 0 ; \
} \
}
# define CALL_OCI_RETURN(retcode,call) \
{ \
if ( OCI ( in_call ) ) { \
retcode = - 1 ; \
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OCI8 Recursive call! \n " ) ; \
2001-08-16 00:00:56 +08:00
exit ( - 1 ) ; \
} else { \
OCI ( in_call ) = 1 ; \
retcode = call ; \
OCI ( in_call ) = 0 ; \
} \
}
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 )
2003-08-31 20:41:53 +08:00
# ifdef PHP_WIN32
# include "zend_arg_defs.c"
# endif
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 ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_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-08 03:56:33 +08:00
static void _oci_column_hash_dtor ( void * data ) ;
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 ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
/* 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 ) ;
2003-12-15 21:53:01 +08:00
static int oci_lobgetlen ( oci_connection * , oci_descriptor * , ub4 * length ) ;
2000-08-07 19:34:48 +08:00
static int oci_loadlob ( oci_connection * , oci_descriptor * , char * * , ub4 * length ) ;
2003-12-15 21:53:01 +08:00
static int oci_readlob ( oci_connection * , oci_descriptor * , char * * , ub4 * len ) ;
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
2002-12-06 21:44:35 +08:00
static oci_session * _oci_open_session ( oci_server * server , char * username , char * password , int persistent , int exclusive , char * charset ) ;
2000-02-01 22:39:59 +08:00
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 */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_bind_by_name ) ;
PHP_FUNCTION ( oci_define_by_name ) ;
PHP_FUNCTION ( oci_field_is_null ) ;
PHP_FUNCTION ( oci_field_name ) ;
PHP_FUNCTION ( oci_field_size ) ;
PHP_FUNCTION ( oci_field_scale ) ;
PHP_FUNCTION ( oci_field_precision ) ;
PHP_FUNCTION ( oci_field_type ) ;
PHP_FUNCTION ( oci_field_type_raw ) ;
PHP_FUNCTION ( oci_execute ) ;
PHP_FUNCTION ( oci_fetch ) ;
PHP_FUNCTION ( oci_cancel ) ;
1999-08-10 22:33:59 +08:00
PHP_FUNCTION ( ocifetchinto ) ;
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_fetch_all ) ;
PHP_FUNCTION ( oci_free_statement ) ;
PHP_FUNCTION ( oci_internal_debug ) ;
PHP_FUNCTION ( oci_close ) ;
PHP_FUNCTION ( oci_connect ) ;
PHP_FUNCTION ( oci_new_connect ) ;
PHP_FUNCTION ( oci_pconnect ) ;
PHP_FUNCTION ( oci_error ) ;
PHP_FUNCTION ( oci_free_descriptor ) ;
PHP_FUNCTION ( oci_commit ) ;
PHP_FUNCTION ( oci_rollback ) ;
PHP_FUNCTION ( oci_new_descriptor ) ;
PHP_FUNCTION ( oci_num_fields ) ;
PHP_FUNCTION ( oci_parse ) ;
PHP_FUNCTION ( oci_new_cursor ) ;
PHP_FUNCTION ( oci_result ) ;
PHP_FUNCTION ( oci_server_version ) ;
PHP_FUNCTION ( oci_statement_type ) ;
PHP_FUNCTION ( oci_num_rows ) ;
PHP_FUNCTION ( oci_set_prefetch ) ;
PHP_FUNCTION ( oci_password_change ) ;
PHP_FUNCTION ( oci_lob_save ) ;
PHP_FUNCTION ( oci_lob_import ) ;
PHP_FUNCTION ( oci_lob_export ) ;
PHP_FUNCTION ( oci_lob_load ) ;
PHP_FUNCTION ( oci_lob_tell ) ;
PHP_FUNCTION ( oci_lob_write ) ;
PHP_FUNCTION ( oci_lob_append ) ;
PHP_FUNCTION ( oci_lob_copy ) ;
PHP_FUNCTION ( oci_lob_truncate ) ;
PHP_FUNCTION ( oci_lob_erase ) ;
PHP_FUNCTION ( oci_lob_flush ) ;
2003-12-15 21:53:01 +08:00
PHP_FUNCTION ( ocisetbufferinglob ) ;
PHP_FUNCTION ( ocigetbufferinglob ) ;
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_is_equal ) ;
PHP_FUNCTION ( oci_lob_rewind ) ;
PHP_FUNCTION ( oci_lob_read ) ;
PHP_FUNCTION ( oci_lob_eof ) ;
PHP_FUNCTION ( oci_lob_seek ) ;
PHP_FUNCTION ( oci_lob_size ) ;
2001-04-14 17:51:29 +08:00
# ifdef HAVE_OCI8_TEMP_LOB
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_write_temporary ) ;
PHP_FUNCTION ( oci_lob_close ) ;
2001-04-14 16:38:46 +08:00
# endif
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_new_collection ) ;
PHP_FUNCTION ( oci_free_collection ) ;
PHP_FUNCTION ( oci_collection_append ) ;
PHP_FUNCTION ( oci_collection_element_get ) ;
PHP_FUNCTION ( oci_collection_element_assign ) ;
PHP_FUNCTION ( oci_collection_assign ) ;
PHP_FUNCTION ( oci_collection_size ) ;
PHP_FUNCTION ( oci_collection_max ) ;
PHP_FUNCTION ( oci_collection_trim ) ;
2001-04-13 22:43:39 +08:00
# 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
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
# define OCI_GET_COLL(collection,index) \
2002-11-16 01:59:19 +08:00
collection = oci_get_coll ( index TSRMLS_CC ) ; \
if ( collection = = NULL ) { \
RETURN_FALSE ; \
}
2001-04-13 22:43:39 +08:00
# endif
2003-12-15 21:53:01 +08:00
# define IS_LOB_INTERNAL(lob) \
if ( lob - > type ! = OCI_DTYPE_LOB ) { \
switch ( lob - > type ) { \
case OCI_DTYPE_FILE : \
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " internal LOB was expected, FILE locator is given " ) ; \
break ; \
case OCI_DTYPE_ROWID : \
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " internal LOB was expected, ROWID locator is given " ) ; \
break ; \
default : \
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " internal LOB was expected, locator of unknown type is given " ) ; \
break ; \
} \
RETURN_FALSE ; \
}
1999-04-22 06:49:16 +08:00
/* }}} */
/* {{{ extension definition structures */
2002-11-16 01:59:19 +08:00
# define OCI_ASSOC 1<<0
# define OCI_NUM 1<<1
# define OCI_BOTH (OCI_ASSOC|OCI_NUM)
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
# define OCI_RETURN_NULLS 1<<2
# define OCI_RETURN_LOBS 1<<3
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
# define OCI_FETCHSTATEMENT_BY_COLUMN 1<<4
# define OCI_FETCHSTATEMENT_BY_ROW 1<<5
# define OCI_FETCHSTATEMENT_BY (OCI_FETCHSTATEMENT_BY_COLUMN | OCI_FETCHSTATEMENT_BY_ROW)
2002-01-18 02:40:59 +08:00
1999-08-10 22:33:59 +08:00
static zend_function_entry php_oci_functions [ ] = {
2003-12-23 23:45:36 +08:00
PHP_FE ( oci_define_by_name , third_arg_force_ref )
PHP_FE ( oci_bind_by_name , third_arg_force_ref )
PHP_FE ( oci_field_is_null , NULL )
PHP_FE ( oci_field_name , NULL )
PHP_FE ( oci_field_size , NULL )
PHP_FE ( oci_field_scale , NULL )
PHP_FE ( oci_field_precision , NULL )
PHP_FE ( oci_field_type , NULL )
PHP_FE ( oci_field_type_raw , NULL )
PHP_FE ( oci_execute , NULL )
PHP_FE ( oci_cancel , NULL )
PHP_FE ( oci_fetch , NULL )
PHP_FE ( ocifetchinto , second_arg_force_ref )
PHP_FE ( oci_fetch_all , second_arg_force_ref )
PHP_FE ( oci_free_statement , NULL )
PHP_FE ( oci_internal_debug , NULL )
PHP_FE ( oci_num_fields , NULL )
PHP_FE ( oci_parse , NULL )
PHP_FE ( oci_new_cursor , NULL )
PHP_FE ( oci_result , NULL )
PHP_FE ( oci_server_version , NULL )
PHP_FE ( oci_statement_type , NULL )
PHP_FE ( oci_num_rows , NULL )
PHP_FE ( oci_close , NULL )
PHP_FE ( oci_connect , NULL )
PHP_FE ( oci_new_connect , NULL )
PHP_FE ( oci_pconnect , NULL )
PHP_FE ( oci_error , NULL )
PHP_FE ( oci_free_descriptor , NULL )
PHP_FE ( oci_lob_save , NULL )
PHP_FE ( oci_lob_import , NULL )
PHP_FE ( oci_lob_size , NULL )
PHP_FE ( oci_lob_load , NULL )
PHP_FE ( oci_lob_read , NULL )
PHP_FE ( oci_lob_eof , NULL )
PHP_FE ( oci_lob_tell , NULL )
PHP_FE ( oci_lob_truncate , NULL )
PHP_FE ( oci_lob_erase , NULL )
PHP_FE ( oci_lob_flush , NULL )
PHP_FE ( ocisetbufferinglob , NULL )
PHP_FE ( ocigetbufferinglob , NULL )
PHP_FE ( oci_lob_is_equal , NULL )
PHP_FE ( oci_lob_rewind , NULL )
PHP_FE ( oci_lob_write , NULL )
PHP_FE ( oci_lob_append , NULL )
PHP_FE ( oci_lob_copy , NULL )
PHP_FE ( oci_lob_export , NULL )
PHP_FE ( oci_commit , NULL )
PHP_FE ( oci_rollback , NULL )
PHP_FE ( oci_new_descriptor , NULL )
PHP_FE ( oci_set_prefetch , NULL )
PHP_FE ( oci_password_change , NULL )
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2003-12-23 23:45:36 +08:00
PHP_FE ( oci_free_collection , NULL )
PHP_FE ( oci_collection_append , NULL )
PHP_FE ( oci_collection_element_get , NULL )
PHP_FE ( oci_collection_element_assign , NULL )
PHP_FE ( oci_collection_assign , NULL )
PHP_FE ( oci_collection_size , NULL )
PHP_FE ( oci_collection_max , NULL )
PHP_FE ( oci_collection_trim , NULL )
PHP_FE ( oci_new_collection , NULL )
2001-04-13 22:43:39 +08:00
# endif
1999-11-13 01:05:57 +08:00
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( ocifreecursor , oci_free_statement , NULL )
PHP_FALIAS ( ocibindbyname , oci_bind_by_name , third_arg_force_ref )
PHP_FALIAS ( ocidefinebyname , oci_define_by_name , third_arg_force_ref )
PHP_FALIAS ( ocicolumnisnull , oci_field_is_null , NULL )
PHP_FALIAS ( ocicolumnname , oci_field_name , NULL )
PHP_FALIAS ( ocicolumnsize , oci_field_size , NULL )
PHP_FALIAS ( ocicolumnscale , oci_field_scale , NULL )
PHP_FALIAS ( ocicolumnprecision , oci_field_precision , NULL )
PHP_FALIAS ( ocicolumntype , oci_field_type , NULL )
PHP_FALIAS ( ocicolumntyperaw , oci_field_type_raw , NULL )
PHP_FALIAS ( ociexecute , oci_execute , NULL )
PHP_FALIAS ( ocicancel , oci_cancel , NULL )
PHP_FALIAS ( ocifetch , oci_fetch , NULL )
PHP_FALIAS ( ocifetchstatement , oci_fetch_all , second_arg_force_ref )
PHP_FALIAS ( ocifreestatement , oci_free_statement , NULL )
PHP_FALIAS ( ociinternaldebug , oci_internal_debug , NULL )
PHP_FALIAS ( ocinumcols , oci_num_fields , NULL )
PHP_FALIAS ( ociparse , oci_parse , NULL )
PHP_FALIAS ( ocinewcursor , oci_new_cursor , NULL )
PHP_FALIAS ( ociresult , oci_result , NULL )
PHP_FALIAS ( ociserverversion , oci_server_version , NULL )
PHP_FALIAS ( ocistatementtype , oci_statement_type , NULL )
PHP_FALIAS ( ocirowcount , oci_num_rows , NULL )
PHP_FALIAS ( ocilogoff , oci_close , NULL )
PHP_FALIAS ( ocilogon , oci_connect , NULL )
PHP_FALIAS ( ocinlogon , oci_new_connect , NULL )
PHP_FALIAS ( ociplogon , oci_pconnect , NULL )
PHP_FALIAS ( ocierror , oci_error , NULL )
PHP_FALIAS ( ocifreedesc , oci_free_descriptor , NULL )
PHP_FALIAS ( ocisavelob , oci_lob_save , NULL )
PHP_FALIAS ( ocisavelobfile , oci_lob_import , NULL )
PHP_FALIAS ( ociwritelobtofile , oci_lob_export , NULL )
PHP_FALIAS ( ociloadlob , oci_lob_load , NULL )
PHP_FALIAS ( ocicommit , oci_commit , NULL )
PHP_FALIAS ( ocirollback , oci_rollback , NULL )
PHP_FALIAS ( ocinewdescriptor , oci_new_descriptor , NULL )
PHP_FALIAS ( ocisetprefetch , oci_set_prefetch , NULL )
PHP_FALIAS ( ocipasswordchange , oci_password_change , NULL )
# ifdef PHP_OCI8_HAVE_COLLECTIONS
PHP_FALIAS ( ocifreecollection , oci_free_collection , NULL )
PHP_FALIAS ( ocinewcollection , oci_new_collection , NULL )
PHP_FALIAS ( ocicollappend , oci_collection_append , NULL )
PHP_FALIAS ( ocicollgetelem , oci_collection_element_get , NULL )
PHP_FALIAS ( ocicollassignelem , oci_collection_element_assign , NULL )
PHP_FALIAS ( ocicollsize , oci_collection_size , NULL )
PHP_FALIAS ( ocicollmax , oci_collection_max , NULL )
PHP_FALIAS ( ocicolltrim , oci_collection_trim , NULL )
# endif
{ 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 [ ] = {
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( load , oci_lob_load , NULL )
PHP_FALIAS ( tell , oci_lob_tell , NULL )
PHP_FALIAS ( truncate , oci_lob_truncate , NULL )
PHP_FALIAS ( erase , oci_lob_erase , NULL )
PHP_FALIAS ( flush , oci_lob_flush , NULL )
2003-12-15 21:53:01 +08:00
PHP_FALIAS ( setbuffering , ocisetbufferinglob , NULL )
PHP_FALIAS ( getbuffering , ocigetbufferinglob , NULL )
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( rewind , oci_lob_rewind , NULL )
PHP_FALIAS ( read , oci_lob_read , NULL )
PHP_FALIAS ( eof , oci_lob_eof , NULL )
PHP_FALIAS ( seek , oci_lob_seek , NULL )
PHP_FALIAS ( write , oci_lob_write , NULL )
PHP_FALIAS ( append , oci_lob_append , NULL )
PHP_FALIAS ( size , oci_lob_size , NULL )
PHP_FALIAS ( writetofile , oci_lob_export , NULL )
2001-04-14 17:51:29 +08:00
# ifdef HAVE_OCI8_TEMP_LOB
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( writetemporary , oci_lob_write_temporary , NULL )
PHP_FALIAS ( close , oci_lob_close , NULL )
2001-04-14 16:38:46 +08:00
# endif
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( save , oci_lob_save , NULL )
PHP_FALIAS ( savefile , oci_lob_import , NULL )
PHP_FALIAS ( free , oci_free_descriptor , NULL )
2002-11-16 01:59:19 +08:00
{ NULL , NULL , NULL }
1999-09-13 18:52:54 +08:00
} ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
static zend_function_entry php_oci_coll_class_functions [ ] = {
2003-12-23 23:45:36 +08:00
PHP_FALIAS ( append , oci_collection_append , NULL )
PHP_FALIAS ( getelem , oci_collection_element_get , NULL )
PHP_FALIAS ( assignelem , oci_collection_element_assign , NULL )
PHP_FALIAS ( assign , oci_collection_assign , NULL )
PHP_FALIAS ( size , oci_collection_size , NULL )
PHP_FALIAS ( max , oci_collection_max , NULL )
PHP_FALIAS ( trim , oci_collection_trim , NULL )
PHP_FALIAS ( free , oci_free_collection , NULL )
2002-11-16 01:59:19 +08:00
{ NULL , NULL , NULL }
2001-04-13 22:43:39 +08:00
} ;
# endif
1999-12-18 04:55:31 +08:00
zend_module_entry oci8_module_entry = {
2001-10-12 07:33:59 +08:00
STANDARD_MODULE_HEADER ,
2002-11-16 01:59:19 +08:00
" oci8 " , /* extension name */
php_oci_functions , /* extension function list */
PHP_MINIT ( oci ) , /* extension-wide startup function */
PHP_MSHUTDOWN ( oci ) , /* extension-wide shutdown function */
PHP_RINIT ( oci ) , /* per-request startup function */
PHP_RSHUTDOWN ( oci ) , /* per-request shutdown function */
PHP_MINFO ( oci ) , /* information function */
NO_VERSION_YET ,
STANDARD_MODULE_PROPERTIES
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 ;
2001-08-16 00:00:56 +08:00
OCI ( in_call ) = 0 ;
1999-04-22 06:49:16 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIEnvInit (
& OCI ( pEnv ) ,
OCI_DEFAULT ,
0 ,
NULL ) ) ;
CALL_OCI ( 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
2003-12-16 18:29:11 +08:00
static int _sessions_pcleanup ( zend_llist * session_list TSRMLS_DC )
{
zend_llist_destroy ( session_list ) ;
return 1 ;
}
static int _session_pcleanup ( oci_session * session TSRMLS_DC )
{
_oci_close_session ( session ) ;
return 1 ;
}
static int _server_pcleanup ( oci_server * server TSRMLS_DC )
{
_oci_close_server ( server ) ;
return 1 ;
}
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 ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
zend_class_entry oci_coll_class_entry ;
2001-04-13 22:43:39 +08:00
# endif
2000-02-01 22:39:59 +08:00
2003-01-07 23:55:59 +08:00
# ifdef HAVE_OCI8_SHARED_MODE
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
# define PHP_OCI_INIT_MODE_TMP OCI_SHARED | OCI_OBJECT
2003-01-07 23:55:59 +08:00
# else
2003-12-16 23:58:10 +08:00
# define PHP_OCI_INIT_MODE_TMP OCI_SHARED
2003-01-07 23:55:59 +08:00
# endif
# else
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
# define PHP_OCI_INIT_MODE_TMP OCI_DEFAULT | OCI_OBJECT
1999-08-17 21:54:25 +08:00
# else
2003-12-16 23:58:10 +08:00
# define PHP_OCI_INIT_MODE_TMP OCI_DEFAULT
1999-12-09 19:02:41 +08:00
# endif
1999-04-22 06:49:16 +08:00
2003-01-07 23:55:59 +08:00
# endif
2003-12-16 23:58:10 +08:00
# ifdef ZTS
# define PHP_OCI_INIT_MODE PHP_OCI_INIT_MODE_TMP | OCI_THREADED
# else
# define PHP_OCI_INIT_MODE PHP_OCI_INIT_MODE_TMP
# endif
2003-12-16 19:15:55 +08:00
mutex_alloc ( mx_lock ) ;
2003-12-16 18:29:11 +08:00
persistent_servers = malloc ( sizeof ( TsHashTable ) ) ;
persistent_sessions = malloc ( sizeof ( TsHashTable ) ) ;
zend_ts_hash_init ( persistent_servers , 13 , NULL , ( dtor_func_t ) _server_pcleanup , 1 ) ;
zend_ts_hash_init ( persistent_sessions , 13 , NULL , ( dtor_func_t ) _sessions_pcleanup , 1 ) ;
2001-08-16 00:00:56 +08:00
OCIInitialize ( PHP_OCI_INIT_MODE , NULL , NULL , NULL , NULL ) ;
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 ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
le_coll = zend_register_list_destructors_ex ( _oci_coll_list_dtor , NULL , " oci8 collection " , module_number ) ;
2001-04-13 22:43:39 +08:00
# 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 ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
INIT_CLASS_ENTRY ( oci_coll_class_entry , " OCI-Collection " , php_oci_coll_class_functions ) ;
2001-04-13 22:43:39 +08:00
# endif
1999-09-13 18:52:54 +08:00
2002-11-16 01:59:19 +08:00
oci_lob_class_entry_ptr = zend_register_internal_class ( & oci_lob_class_entry TSRMLS_CC ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +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 ) ;
2003-12-15 21:53:01 +08:00
/* for $LOB->seek() */
REGISTER_LONG_CONSTANT ( " OCI_SEEK_SET " , OCI_SEEK_SET , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SEEK_CUR " , OCI_SEEK_CUR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SEEK_END " , OCI_SEEK_END , CONST_CS | CONST_PERSISTENT ) ;
/* for $LOB->flush() */
REGISTER_LONG_CONSTANT ( " OCI_LOB_BUFFER_FREE " , OCI_LOB_BUFFER_FREE , CONST_CS | CONST_PERSISTENT ) ;
1999-04-22 06:49:16 +08:00
/* 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 ) ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
REGISTER_LONG_CONSTANT ( " OCI_B_SQLT_NTY " , SQLT_NTY , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_STRING_CONSTANT ( " OCI_SYSDATE " , " SYSDATE " , CONST_PERSISTENT ) ;
2001-04-13 22:43:39 +08:00
# 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
2002-01-18 02:40:59 +08:00
/* for OCIFetchStatement */
REGISTER_LONG_CONSTANT ( " OCI_FETCHSTATEMENT_BY_COLUMN " , OCI_FETCHSTATEMENT_BY_COLUMN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FETCHSTATEMENT_BY_ROW " , OCI_FETCHSTATEMENT_BY_ROW , 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 ) ;
2003-07-22 18:38:34 +08:00
/* for OCIWriteTemporaryLob */
# ifdef HAVE_OCI8_TEMP_LOB
REGISTER_LONG_CONSTANT ( " OCI_TEMP_CLOB " , OCI_TEMP_CLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_TEMP_BLOB " , OCI_TEMP_BLOB , CONST_CS | CONST_PERSISTENT ) ;
# endif
1999-04-22 06:49:16 +08:00
return SUCCESS ;
}
/* ----------------------------------------------------------------- */
1999-08-17 21:54:25 +08:00
PHP_RINIT_FUNCTION ( oci )
1999-04-22 06:49:16 +08:00
{
1999-08-17 21:54:25 +08:00
OCI ( debug_mode ) = 0 ; /* start "fresh" */
2001-08-16 00:00:56 +08:00
/* OCI(in_call) = 0; i don't think we want this! */
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
oci_debug ( " php_rinit_oci " ) ;
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
return SUCCESS ;
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 ;
2002-11-16 01:59:19 +08:00
oci_debug ( " START php_mshutdown_oci " ) ;
1999-04-25 02:54:02 +08:00
2003-12-16 18:29:11 +08:00
zend_ts_hash_destroy ( persistent_sessions ) ;
zend_ts_hash_destroy ( persistent_servers ) ;
1999-04-25 02:54:02 +08:00
2003-12-16 18:29:11 +08:00
free ( persistent_sessions ) ;
free ( persistent_servers ) ;
1999-04-25 02:54:02 +08:00
2003-12-16 18:29:11 +08:00
mutex_free ( mx_lock ) ;
1999-04-25 02:54:02 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) OCI ( pEnv ) ,
OCI_HTYPE_ENV ) ) ;
1999-04-25 02:54:02 +08:00
2002-11-16 01:59:19 +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
{
2002-11-16 01:59:19 +08:00
oci_debug ( " START php_rshutdown_oci " ) ;
2000-01-16 21:30:57 +08:00
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
2003-12-16 18:29:11 +08:00
zend_ts_hash_apply ( persistent_sessions , ( apply_func_t ) _session_cleanup TSRMLS_CC ) ;
zend_ts_hash_apply ( persistent_servers , ( apply_func_t ) _server_cleanup TSRMLS_CC ) ;
2000-02-01 22:39:59 +08:00
# endif
1999-04-25 02:54:02 +08:00
2002-11-16 01:59:19 +08:00
oci_debug ( " END php_rshutdown_oci " ) ;
1999-04-25 02:54:02 +08:00
2002-11-16 01:59:19 +08:00
return SUCCESS ;
1999-04-22 06:49:16 +08:00
}
1999-08-17 21:54:25 +08:00
PHP_MINFO_FUNCTION ( oci )
1999-04-22 06:49:16 +08:00
{
2003-12-16 18:29:11 +08:00
char buf [ 32 ] ;
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$ " ) ;
2003-12-16 18:29:11 +08:00
sprintf ( buf , " %ld " , num_persistent ) ;
php_info_print_table_row ( 2 , " Active Persistent Links " , buf ) ;
sprintf ( buf , " %ld " , num_links ) ;
php_info_print_table_row ( 2 , " Active Links " , buf ) ;
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
2003-12-16 23:58:10 +08:00
# ifdef HAVE_OCI8_TEMP_LOB
php_info_print_table_row ( 2 , " Temporary Lob support " , " enabled " ) ;
# else
php_info_print_table_row ( 2 , " Temporary Lob support " , " disabled " ) ;
# endif
# ifdef HAVE_OCI8_COLLECTIONS
php_info_print_table_row ( 2 , " Collections support " , " enabled " ) ;
# else
php_info_print_table_row ( 2 , " Collections support " , " disabled " ) ;
# 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: " ) ;
2002-11-16 01:59:19 +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..-. */
2002-11-16 01:59:19 +08:00
bind - > indicator = 0 ;
2000-01-16 21:30:57 +08:00
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 ;
2002-04-15 02:27:27 +08:00
if ( Z_TYPE_P ( val ) = = IS_STRING & & ( Z_STRVAL_P ( val ) ! = empty_string ) ) {
* Z_STRVAL_P ( val ) = ' \0 ' ; /* XXX avoid warning in debug mode */
}
2000-02-07 18:31:43 +08:00
zval_dtor ( val ) ;
ZVAL_NULL ( val ) ;
2001-09-26 16:35:48 +08:00
} else if ( Z_TYPE_P ( bind - > zval ) = = IS_STRING & & ( Z_STRVAL_P ( bind - > zval ) ! = empty_string ) ) {
Z_STRVAL_P ( bind - > zval ) = erealloc ( Z_STRVAL_P ( bind - > zval ) , Z_STRLEN_P ( bind - > zval ) + 1 ) ;
Z_STRVAL_P ( bind - > zval ) [ Z_STRLEN_P ( bind - > zval ) ] = ' \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-08 03:56:33 +08:00
_oci_column_hash_dtor ( void * data )
1999-09-13 19:13:53 +08:00
{
oci_out_column * column = ( oci_out_column * ) data ;
2001-08-08 03:56:33 +08:00
TSRMLS_FETCH ( ) ;
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 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
statement - > pStmt ,
OCI_HTYPE_STMT ) ) ;
1999-04-22 06:49:16 +08:00
statement - > pStmt = 0 ;
}
if ( statement - > pError ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
statement - > pError ,
OCI_HTYPE_ERROR ) ) ;
1999-04-22 06:49:16 +08:00
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
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 ) {
2002-02-10 20:41:52 +08:00
if ( connection - > needs_commit ) {
oci_debug ( " OCITransRollback " ) ;
CALL_OCI_RETURN ( connection - > error , OCITransRollback (
connection - > pServiceContext ,
connection - > pError ,
( ub4 ) 0 ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " failed to rollback outstanding transactions! " , connection - > error ) ;
}
connection - > needs_commit = 0 ;
} else {
oci_debug ( " nothing to do.. " ) ;
2000-05-25 15:44:45 +08:00
}
2000-01-16 21:30:57 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) connection - > pServiceContext ,
( ub4 ) OCI_HTYPE_SVCCTX ) ) ;
1999-04-22 06:49:16 +08:00
}
2003-12-16 18:29:11 +08:00
if ( connection - > session ) {
/* close associated session when destructed */
2000-08-05 18:45:55 +08:00
zend_list_delete ( connection - > session - > num ) ;
}
1999-04-22 06:49:16 +08:00
if ( connection - > pError ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) connection - > pError ,
( ub4 ) OCI_HTYPE_ERROR ) ) ;
1999-04-22 06:49:16 +08:00
}
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
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
/* {{{ _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
2001-04-20 06:00:34 +08:00
/* Note sure if we need to free the object. Have an
2002-11-16 01:59:19 +08:00
oracle TAR out on this one .
OCIDescriptorFree ( descr - > ocidescr , Z_TYPE_P ( descr ) ) ; */
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 ;
2002-11-16 01:59:19 +08:00
oci_debug ( " START _oci_descriptor_list_dtor: %d " , descr - > id ) ;
2000-01-16 21:30:57 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIDescriptorFree (
descr - > ocidescr ,
2001-09-26 05:58:48 +08:00
Z_TYPE_P ( descr ) ) ) ;
2000-01-16 21:30:57 +08:00
2002-11-16 01:59:19 +08:00
oci_debug ( " END _oci_descriptor_list_dtor: %d " , descr - > id ) ;
2000-01-16 21:30:57 +08:00
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
{
2003-12-16 23:48:20 +08:00
#if 0
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 ) ;
2003-12-16 23:48:20 +08:00
# endif
2000-02-01 22:39:59 +08:00
}
/* }}} */
/* {{{ _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 ;
2003-12-16 18:29:11 +08:00
if ( session - > persistent ) {
/* clear thread assignment */
session - > thread = 0 ;
2000-02-01 22:39:59 +08:00
return ;
2003-12-16 18:29:11 +08:00
}
2000-02-01 22:39:59 +08:00
_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 ) {
2002-01-30 15:41:04 +08:00
case 1013 : /* user requested cancel of current operation */
zend_bailout ( ) ;
break ;
2002-11-16 01:59:19 +08:00
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 :
2002-11-16 01:59:19 +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 */
2002-11-16 01:59:19 +08:00
}
2001-02-17 23:54:40 +08:00
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
{
2002-11-16 01:59:19 +08:00
text errbuf [ 512 ] ;
sb4 errcode = 0 ;
2003-01-19 08:45:53 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
switch ( status ) {
2000-01-16 21:30:57 +08:00
case OCI_SUCCESS :
break ;
case OCI_SUCCESS_WITH_INFO :
2003-01-28 03:52:11 +08:00
CALL_OCI ( OCIErrorGet (
err_p ,
( ub4 ) 1 ,
NULL ,
& errcode ,
errbuf ,
( ub4 ) sizeof ( errbuf ) ,
( ub4 ) OCI_HTYPE_ERROR ) ) ;
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_SUCCESS_WITH_INFO: %s " , what , errbuf ) ;
2000-01-16 21:30:57 +08:00
break ;
case OCI_NEED_DATA :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_NEED_DATA " , what ) ;
2000-01-16 21:30:57 +08:00
break ;
case OCI_NO_DATA :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_NO_DATA " , what ) ;
2000-01-16 21:30:57 +08:00
break ;
2001-08-16 00:00:56 +08:00
case OCI_ERROR : {
CALL_OCI ( OCIErrorGet (
err_p ,
( ub4 ) 1 ,
NULL ,
& errcode ,
errbuf ,
( ub4 ) sizeof ( errbuf ) ,
( ub4 ) OCI_HTYPE_ERROR ) ) ;
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: %s " , what , errbuf ) ;
2001-08-16 00:00:56 +08:00
break ;
}
2000-01-16 21:30:57 +08:00
case OCI_INVALID_HANDLE :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_INVALID_HANDLE " , what ) ;
2000-01-16 21:30:57 +08:00
break ;
case OCI_STILL_EXECUTING :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_STILL_EXECUTING " , what ) ;
2000-01-16 21:30:57 +08:00
break ;
case OCI_CONTINUE :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s: OCI_CONTINUE " , what ) ;
2000-01-16 21:30:57 +08:00
break ;
default :
break ;
2002-11-16 01:59:19 +08:00
}
return errcode ;
1999-04-22 06:49:16 +08:00
}
/* }}} */
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 ( ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIServerVersion (
server - > pServer ,
OCI ( pError ) ,
( text * ) version ,
sizeof ( version ) ,
OCI_HTYPE_SERVER ) ) ;
1999-09-30 16:41:45 +08:00
2000-01-16 21:30:57 +08:00
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 ) ) ;
2002-11-16 01:59:19 +08:00
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
2002-11-16 01:59:19 +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-10-07 04:13:39 +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 ;
2003-01-19 16:32:26 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
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 ) {
2002-11-16 01:59:19 +08:00
if ( Z_TYPE_PP ( value ) = = IS_STRING ) {
1999-04-22 06:49:16 +08:00
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
2002-11-16 01:59:19 +08:00
outcol = oci_get_col ( statement , i + 1 , 0 ) ;
if ( outcol = = NULL ) {
continue ;
} else if ( ( ( int ) outcol - > name_len = = Z_STRLEN_PP ( value ) )
& & ( ! strncmp ( outcol - > name , Z_STRVAL_PP ( value ) , Z_STRLEN_PP ( value ) ) ) ) {
return outcol ;
}
}
} else {
2000-01-16 21:30:57 +08:00
convert_to_long_ex ( value ) ;
2001-09-26 05:58:48 +08:00
return oci_get_col ( statement , Z_LVAL_PP ( value ) , 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 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , 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 ) ) ;
2002-11-16 01:59:19 +08:00
Z_TYPE_P ( descr ) = type ;
2000-01-16 21:30:57 +08:00
2001-09-26 05:58:48 +08:00
switch ( Z_TYPE_P ( descr ) ) {
2002-11-16 01:59:19 +08:00
case OCI_DTYPE_FILE :
case OCI_DTYPE_LOB :
case OCI_DTYPE_ROWID :
2000-01-16 21:30:57 +08:00
break ;
2002-11-16 01:59:19 +08:00
default :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unknown descriptor type %d. " , Z_TYPE_P ( descr ) ) ;
2000-01-16 21:30:57 +08:00
return 0 ;
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIDescriptorAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
( dvoid * ) & ( descr - > ocidescr ) ,
2001-09-26 05:58:48 +08:00
Z_TYPE_P ( descr ) ,
2001-08-16 00:00:56 +08:00
( size_t ) 0 ,
( dvoid * * ) 0 ) ) ;
2000-01-16 21:30:57 +08:00
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 ;
2003-12-15 21:53:01 +08:00
descr - > lob_current_position = 0 ;
descr - > lob_size = - 1 ; /* we should set it to -1 to know, that it's just not initialized */
descr - > buffering = 0 ; /* buffering is off by default */
2000-01-16 21:30:57 +08:00
zend_list_addref ( connection - > id ) ;
oci_debug ( " oci_new_desc %d " , descr - > id ) ;
return descr ;
}
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
/* {{{ _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
{
2002-11-16 01:59:19 +08:00
zval * * coll ;
if ( zend_hash_find ( Z_OBJPROP_P ( id ) , " collection " , sizeof ( " collection " ) , ( void * * ) & coll ) = = FAILURE ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " cannot find collection " ) ;
2002-11-16 01:59:19 +08:00
return 0 ;
}
if ( ( * collection = oci_get_coll ( Z_LVAL_PP ( coll ) TSRMLS_CC ) ) = = NULL ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " collection not found " ) ;
2002-11-16 01:59:19 +08:00
return 0 ;
}
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
return Z_LVAL_PP ( coll ) ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
# 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 ;
2001-08-11 18:52:52 +08:00
if ( zend_hash_find ( Z_OBJPROP_P ( id ) , " descriptor " , sizeof ( " descriptor " ) , ( void * * ) & desc ) = = FAILURE ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " cannot find descriptor " ) ;
2000-01-16 21:30:57 +08:00
return 0 ;
}
2001-09-26 05:58:48 +08:00
if ( ( * descriptor = oci_get_desc ( Z_LVAL_PP ( desc ) TSRMLS_CC ) ) = = NULL ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " descriptor not found " ) ;
2000-01-16 21:30:57 +08:00
return 0 ;
}
2001-09-26 05:58:48 +08:00
return Z_LVAL_PP ( desc ) ;
2000-01-16 21:30:57 +08:00
}
/* }}} */
/* {{{ _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 ) ;
2002-09-12 17:48:03 +08:00
if ( ( ! statement - > has_data ) | | ( column - > indicator = = - 1 ) ) { /* column is NULL or statment has no current data */
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 ) ;
2002-11-16 01:59:19 +08:00
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 ) ;
2002-11-16 01:59:19 +08:00
if ( ! descr ) {
2003-11-06 22:29:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " unable to find my descriptor %p " , column - > data ) ;
2002-11-16 01:59:19 +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 ) ;
2002-11-16 01:59:19 +08:00
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 ;
2001-08-16 00:00:56 +08:00
sword error ;
TSRMLS_FETCH ( ) ;
1999-07-08 22:12:07 +08:00
prefetch = size * 1024 ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrSet (
statement - > pStmt ,
OCI_HTYPE_STMT ,
& prefetch ,
0 ,
OCI_ATTR_PREFETCH_MEMORY ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrSet OCI_ATTR_PREFETCH_MEMORY " , error ) ;
2001-02-12 22:36:28 +08:00
if ( statement - > error ) {
2002-11-16 01:59:19 +08:00
oci_handle_error ( statement - > conn , statement - > error ) ;
2001-02-12 22:36:28 +08:00
}
2001-08-16 00:00:56 +08:00
1999-07-08 22:12:07 +08:00
prefetch = size ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrSet (
statement - > pStmt ,
OCI_HTYPE_STMT ,
& prefetch ,
0 ,
OCI_ATTR_PREFETCH_ROWS ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrSet OCI_ATTR_PREFETCH_MEMORY " , error ) ;
2002-11-16 01:59:19 +08:00
if ( statement - > error ) {
2001-02-12 22:36:28 +08:00
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-08-16 00:00:56 +08:00
sword error ;
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
2002-11-16 01:59:19 +08:00
CALL_OCI ( OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
( dvoid * * ) & statement - > pStmt ,
2001-08-16 00:00:56 +08:00
OCI_HTYPE_STMT ,
0 ,
NULL ) ) ;
2002-11-16 01:59:19 +08:00
CALL_OCI ( OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
( dvoid * * ) & statement - > pError ,
OCI_HTYPE_ERROR ,
0 ,
NULL ) ) ;
1999-05-12 22:28:01 +08:00
if ( len > 0 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIStmtPrepare (
statement - > pStmt ,
connection - > pError ,
( text * ) query ,
len ,
OCI_NTV_SYNTAX ,
OCI_DEFAULT ) ) ;
connection - > error = oci_error ( connection - > pError , " OCIParse " , error ) ;
1999-05-12 22:28:01 +08:00
if ( connection - > error ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
statement - > pStmt ,
OCI_HTYPE_STMT ) ) ;
2002-11-16 01:59:19 +08:00
CALL_OCI ( OCIHandleFree (
2001-08-16 00:00:56 +08:00
statement - > pError ,
OCI_HTYPE_ERROR ) ) ;
2000-05-30 17:25:02 +08:00
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 ) ;
}
2002-09-12 17:48:03 +08:00
1999-04-22 06:49:16 +08:00
statement - > conn = connection ;
2002-09-12 17:48:03 +08:00
statement - > has_data = 0 ;
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 " ,
2002-11-16 01:59:19 +08:00
SAFE_STRING ( query ) ,
statement - > id ,
statement - > conn - > id ) ;
1999-04-22 06:49:16 +08:00
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 ;
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-08-16 00:00:56 +08:00
sword error ;
2001-07-31 12:53:54 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
2002-02-09 02:50:12 +08:00
if ( ! statement - > stmttype ) {
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) statement - > pStmt ,
OCI_HTYPE_STMT ,
( ub2 * ) & statement - > stmttype ,
( ub4 * ) 0 ,
OCI_ATTR_STMT_TYPE ,
statement - > pError ) ) ;
1999-05-12 22:28:01 +08:00
2002-02-09 02:50:12 +08:00
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_STMT_TYPE " , error ) ;
if ( statement - > error ) {
oci_handle_error ( statement - > conn , statement - > error ) ;
return 0 ;
}
1999-04-22 06:49:16 +08:00
}
2002-02-09 02:50:12 +08:00
if ( statement - > stmttype = = OCI_STMT_SELECT ) {
1999-04-22 06:49:16 +08:00
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
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIStmtExecute (
statement - > conn - > pServiceContext ,
statement - > pStmt ,
statement - > pError ,
iters ,
0 ,
NULL ,
NULL ,
mode ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIStmtExecute " , error ) ;
2002-02-10 20:41:52 +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_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 ;
}
2002-02-10 20:41:52 +08:00
if ( mode & OCI_COMMIT_ON_SUCCESS ) {
statement - > conn - > needs_commit = 0 ;
} else {
statement - > conn - > needs_commit = 1 ;
}
1999-04-22 06:49:16 +08:00
}
2002-02-09 02:50:12 +08:00
if ( ( statement - > stmttype = = OCI_STMT_SELECT ) & & ( statement - > executed = = 0 ) ) {
1999-04-22 06:49:16 +08:00
/* we only need to do the define step is this very statement is executed the first time! */
2002-02-09 02:50:12 +08:00
statement - > executed = 1 ;
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 ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) statement - > pStmt ,
OCI_HTYPE_STMT ,
( dvoid * ) & colcount ,
( ub4 * ) 0 ,
OCI_ATTR_PARAM_COUNT ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_HTYPE_STMT/OCI_ATTR_PARAM_COUNT " , error ) ;
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 ,
2002-11-16 01:59:19 +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 ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIParamGet (
( dvoid * ) statement - > pStmt ,
OCI_HTYPE_STMT ,
statement - > pError ,
( dvoid * * ) & param ,
counter ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIParamGet OCI_HTYPE_STMT " , error ) ;
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!!! */
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) param ,
OCI_DTYPE_PARAM ,
( dvoid * ) & outcol - > data_type ,
( ub4 * ) 0 ,
OCI_ATTR_DATA_TYPE ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_TYPE " , error ) ;
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!!! */
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) param ,
OCI_DTYPE_PARAM ,
( dvoid * ) & outcol - > data_size ,
( dvoid * ) 0 ,
OCI_ATTR_DATA_SIZE ,
statement - > pError ) ) ;
1999-06-09 18:40:08 +08:00
2001-08-16 00:00:56 +08:00
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_DATA_SIZE " , error ) ;
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
outcol - > storage_size4 = outcol - > data_size ;
outcol - > retlen = outcol - > data_size ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) param ,
OCI_DTYPE_PARAM ,
( dvoid * ) & outcol - > scale ,
( dvoid * ) 0 ,
OCI_ATTR_SCALE ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_SCALE " , error ) ;
2000-03-03 09:28:27 +08:00
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!!! */
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIAttrGet (
( dvoid * ) param ,
OCI_DTYPE_PARAM ,
( dvoid * ) & outcol - > precision ,
( dvoid * ) 0 ,
OCI_ATTR_PRECISION ,
statement - > pError ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_PRECISION " , error ) ;
2000-03-03 09:28:27 +08:00
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!!! */
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , 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 ) ) ;
statement - > error = oci_error ( statement - > pError , " OCIAttrGet OCI_DTYPE_PARAM/OCI_ATTR_NAME " , error ) ;
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-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 ) ;
2003-05-02 16:43:28 +08:00
if ( ! descr ) {
/* need better error checking XXX */
}
2000-01-16 21:30:57 +08:00
outcol - > descid = descr - > id ;
2002-11-16 01:59:19 +08:00
buf = & ( descr - > ocidescr ) ;
1999-04-22 06:49:16 +08:00
break ;
1999-06-09 18:40:08 +08:00
case SQLT_LNG :
2002-11-16 01:59:19 +08:00
case SQLT_LBI :
1999-07-08 22:12:07 +08:00
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 ;
2002-10-17 16:09:31 +08:00
if ( ( outcol - > data_type = = SQLT_DAT ) | | ( outcol - > data_type = = SQLT_NUM )
# ifdef SQLT_TIMESTAMP
| | ( outcol - > data_type = = SQLT_TIMESTAMP )
# endif
# ifdef SQLT_TIMESTAMP_TZ
| | ( outcol - > data_type = = SQLT_TIMESTAMP_TZ )
# endif
2002-11-16 01:59:19 +08:00
) {
1999-07-08 22:12:07 +08:00
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 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIDefineByPos (
2002-11-16 01:59:19 +08:00
statement - > pStmt , /* IN/OUT handle to the requested SQL query */
( OCIDefine * * ) & outcol - > pDefine , /* IN/OUT pointer to a pointer to a define handle */
statement - > pError , /* IN/OUT An error handle */
counter , /* IN position in the select list */
( dvoid * ) NULL , /* IN/OUT pointer to a buffer */
outcol - > storage_size4 , /* IN The size of each valuep buffer in bytes */
define_type , /* IN The data type */
( dvoid * ) & outcol - > indicator , /* IN pointer to an indicator variable or arr */
( ub2 * ) NULL , /* IN/OUT Pointer to array of length of data fetched */
( ub2 * ) NULL , /* OUT Pointer to array of column-level return codes */
OCI_DYNAMIC_FETCH ) ) ; /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */
2001-08-16 00:00:56 +08:00
statement - > error = oci_error ( statement - > pError , " OCIDefineByPos " , error ) ;
1999-07-08 22:12:07 +08:00
} else {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( error , OCIDefineByPos (
2002-11-16 01:59:19 +08:00
statement - > pStmt , /* IN/OUT handle to the requested SQL query */
( OCIDefine * * ) & outcol - > pDefine , /* IN/OUT pointer to a pointer to a define handle */
statement - > pError , /* IN/OUT An error handle */
counter , /* IN position in the select list */
( dvoid * ) buf , /* IN/OUT pointer to a buffer */
outcol - > storage_size4 , /* IN The size of each valuep buffer in bytes */
define_type , /* IN The data type */
( dvoid * ) & outcol - > indicator , /* IN pointer to an indicator variable or arr */
( ub2 * ) & outcol - > retlen , /* IN/OUT Pointer to array of length of data fetched */
( ub2 * ) & outcol - > retcode , /* OUT Pointer to array of column-level return codes */
OCI_DEFAULT ) ) ; /* IN mode (OCI_DEFAULT, OCI_DYNAMIC_FETCH) */
2001-08-16 00:00:56 +08:00
statement - > error = oci_error ( statement - > pError , " OCIDefineByPos " , error ) ;
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 ;
2002-11-16 01:59:19 +08:00
if ( col - > piecewise ) {
2000-01-16 21:30:57 +08:00
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
2002-02-09 02:50:12 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( statement - > error , OCIStmtFetch (
statement - > pStmt ,
statement - > pError ,
nrows ,
OCI_FETCH_NEXT ,
OCI_DEFAULT ) ) ;
1999-05-12 22:28:01 +08:00
if ( ( statement - > error = = OCI_NO_DATA ) | | ( nrows = = 0 ) ) {
2002-02-09 02:50:12 +08:00
if ( statement - > last_query = = 0 ) {
2002-10-20 00:11:16 +08:00
/* reset define-list for refcursors */
2002-02-09 02:50:12 +08:00
if ( statement - > columns ) {
zend_hash_destroy ( statement - > columns ) ;
efree ( statement - > columns ) ;
statement - > columns = 0 ;
statement - > ncolumns = 0 ;
}
statement - > executed = 0 ;
1999-05-12 22:28:01 +08:00
}
statement - > error = 0 ; /* OCI_NO_DATA is NO error for us!!! */
2002-09-12 17:48:03 +08:00
statement - > has_data = 0 ;
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 ;
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIStmtSetPieceInfo (
( void * ) column - > pDefine ,
OCI_HTYPE_DEFINE ,
statement - > pError ,
( ( char * ) column - > data ) + column - > retlen4 ,
& ( column - > cb_retlen ) ,
OCI_NEXT_PIECE ,
& column - > indicator ,
& column - > retcode ) ) ;
1999-09-13 23:19:29 +08:00
}
2002-11-16 01:59:19 +08:00
}
1999-09-13 23:19:29 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( statement - > error , OCIStmtFetch (
statement - > pStmt ,
statement - > pError ,
nrows ,
OCI_FETCH_NEXT ,
OCI_DEFAULT ) ) ;
1999-09-13 23:19:29 +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 ) ;
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 ) {
2002-10-21 19:00:40 +08:00
statement - > has_data = 1 ;
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
2002-09-12 17:48:03 +08:00
statement - > has_data = 0 ;
1999-04-22 06:49:16 +08:00
return 0 ;
}
2003-12-15 21:53:01 +08:00
/* }}} */
/* {{{ oci_lobgetlen() */
static int
oci_lobgetlen ( oci_connection * connection , oci_descriptor * mydescr , ub4 * loblen )
{
TSRMLS_FETCH ( ) ;
* loblen = 0 ;
/* do we need to ask oracle about LOB's length, if we do already know it? I think no. */
if ( mydescr - > lob_size > = 0 ) {
* loblen = mydescr - > lob_size ;
}
else {
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
CALL_OCI_RETURN ( connection - > error , OCILobFileOpen (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
OCI_FILE_READONLY ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFileOpen " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
return - 1 ;
}
}
CALL_OCI_RETURN ( connection - > error , OCILobGetLength (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
loblen ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobGetLength " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
return - 1 ;
}
mydescr - > lob_size = * loblen ;
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
CALL_OCI_RETURN ( connection - > error , OCILobFileClose (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFileClose " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
return - 1 ;
}
}
}
oci_debug ( " OCILobGetLen: len=%d " , loblen ) ;
return 0 ;
}
1999-04-22 06:49:16 +08:00
/* }}} */
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 */
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 ;
2001-08-16 00:00:56 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
2000-08-07 19:34:48 +08:00
* loblen = 0 ;
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobFileOpen (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
OCI_FILE_READONLY ) ) ;
1999-05-12 22:28:01 +08:00
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
}
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobGetLength (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
& readlen ) ) ;
2000-08-07 19:34:48 +08:00
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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobRead (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
& readlen , /* IN/OUT bytes toread/read */
siz + 1 , /* offset (starts with 1) */
( dvoid * ) ( ( char * ) buf + siz ) ,
readlen , /* size of buffer */
( dvoid * ) 0 ,
( OCICallbackLobRead ) 0 , /* callback... */
2002-12-06 21:44:35 +08:00
( ub2 ) connection - > session - > charsetId , /* The character set ID of the buffer data. */
2001-08-16 00:00:56 +08:00
( ub1 ) SQLCS_IMPLICIT ) ) ; /* The character set form of the buffer data. */
2000-08-07 19:34:48 +08:00
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
}
2003-12-15 21:53:01 +08:00
mydescr - > lob_size = * loblen ;
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobFileClose (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ) ) ;
1999-05-12 22:28:01 +08:00
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
/* }}} */
2003-12-15 21:53:01 +08:00
/* {{{ oci_readlob() */
static int
oci_readlob ( oci_connection * connection , oci_descriptor * mydescr , char * * buffer , ub4 * len )
{
ub4 siz = 0 ;
ub4 readlen = 0 ;
ub4 loblen = 0 ;
2003-12-16 18:29:11 +08:00
ub4 bytes = 0 ;
2003-12-15 21:53:01 +08:00
char * buf ;
TSRMLS_FETCH ( ) ;
/* we're not going to read LOB, if length is not known */
if ( ! len | | ( int ) * len < = 0 ) {
return - 1 ;
}
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
CALL_OCI_RETURN ( connection - > error , OCILobFileOpen (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
OCI_FILE_READONLY ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFileOpen " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
return - 1 ;
}
}
if ( oci_lobgetlen ( connection , mydescr , & loblen ) ! = 0 ) {
* len = 0 ;
return - 1 ;
}
/* check if we're in LOB's borders */
if ( ( mydescr - > lob_current_position + * len ) > loblen ) {
* len = loblen - mydescr - > lob_current_position ;
}
if ( ( int ) * len > 0 ) {
buf = emalloc ( * len + 1 ) ;
/* set offset to current LOB's position */
siz = mydescr - > lob_current_position ;
/* check if len is smaller, if not - using LOBREADSIZE' sized buffer */
if ( * len > LOBREADSIZE ) {
readlen = LOBREADSIZE ;
}
else {
readlen = * len ;
}
}
else {
* len = 0 ;
return - 1 ;
}
2003-12-16 18:29:11 +08:00
while ( readlen > 0 & & bytes < * len & & siz < loblen ) { /* paranoia */
2003-12-15 21:53:01 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobRead (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ,
& readlen , /* IN/OUT bytes toread/read */
siz + 1 , /* offset (starts with 1) */
( dvoid * ) ( ( char * ) buf + bytes ) ,
readlen , /* size of buffer */
( dvoid * ) 0 ,
( OCICallbackLobRead ) 0 , /* callback... */
( ub2 ) connection - > session - > charsetId , /* The character set ID of the buffer data. */
( ub1 ) SQLCS_IMPLICIT ) ) ; /* The character set form of the buffer data. */
siz + = readlen ;
bytes + = readlen ;
if ( ( * len - bytes ) > LOBREADSIZE ) {
readlen = LOBREADSIZE ;
}
else {
readlen = * len - bytes ;
}
if ( connection - > error = = OCI_NEED_DATA ) {
buf = erealloc ( buf , bytes + LOBREADSIZE + 1 ) ;
continue ;
} else {
break ;
}
}
/* moving current position */
mydescr - > lob_current_position = siz ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobRead " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
efree ( buf ) ;
return - 1 ;
}
if ( Z_TYPE_P ( mydescr ) = = OCI_DTYPE_FILE ) {
CALL_OCI_RETURN ( connection - > error , OCILobFileClose (
connection - > pServiceContext ,
connection - > pError ,
mydescr - > ocidescr ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFileClose " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
efree ( buf ) ;
return - 1 ;
}
}
buf = erealloc ( buf , bytes + 1 ) ;
buf [ bytes ] = 0 ;
* buffer = buf ;
* len = bytes ;
oci_debug ( " OCIreadlob: size=%d " , bytes ) ;
return 0 ;
}
/* }}} */
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 ,
2002-11-16 01:59:19 +08:00
dvoid * envhp ,
dvoid * fo_ctx ,
ub4 fo_type ,
ub4 fo_event )
1999-04-25 02:54:02 +08:00
{
/*
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 " ,
2002-11-16 01:59:19 +08:00
( ( fo_type = = OCI_FO_NONE ) ? " NONE "
1999-04-25 02:54:02 +08:00
: ( fo_type = = OCI_FO_SESSION ) ? " SESSION "
: ( fo_type = = OCI_FO_SELECT ) ? " SELECT "
: " UNKNOWN! " ) ) ;
printf ( " Failover Context is :%s \n " ,
2002-11-16 01:59:19 +08:00
( fo_ctx ? ( char * ) fo_ctx : " NULL POINTER! " ) ) ;
1999-04-25 02:54:02 +08:00
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 ;
2003-01-19 08:45:53 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
2000-01-16 21:30:57 +08:00
if ( ! ( phpbind = ( oci_bind * ) ictxp ) | | ! ( val = phpbind - > zval ) ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , 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 ) ;
2001-09-26 05:58:48 +08:00
* bufpp = Z_STRVAL_P ( val ) ;
* alenp = Z_STRLEN_P ( val ) ;
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 */
2002-11-16 01:59:19 +08:00
* bufpp = phpbind - > pStmt ;
1999-05-12 22:28:01 +08:00
* 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 ;
2003-01-19 08:45:53 +08:00
TSRMLS_FETCH ( ) ;
1999-04-22 06:49:16 +08:00
2000-01-16 21:30:57 +08:00
if ( ! ( phpbind = ( oci_bind * ) octxp ) | | ! ( val = phpbind - > zval ) ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " !phpbind || !phpbind->val " ) ;
2000-01-16 21:30:57 +08:00
return retval ;
1999-04-22 06:49:16 +08:00
}
2001-09-26 05:58:48 +08:00
if ( ( Z_TYPE_P ( val ) = = IS_OBJECT ) | | ( Z_TYPE_P ( val ) = = 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
2001-09-26 05:58:48 +08:00
Z_STRLEN_P ( val ) = OCI_PIECE_SIZE ; /* 64K-1 is max XXX */
2001-09-26 16:35:48 +08:00
Z_STRVAL_P ( val ) = emalloc ( Z_STRLEN_P ( phpbind - > zval ) ) ;
2000-01-16 21:30:57 +08:00
/* XXX we assume that zend-zval len has 4 bytes */
2001-09-26 16:35:48 +08:00
* alenpp = ( ub4 * ) & Z_STRLEN_P ( phpbind - > zval ) ;
* bufpp = Z_STRVAL_P ( phpbind - > zval ) ;
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
*/
2003-11-06 22:29:09 +08:00
# include "ext/standard/php_smart_str.h"
2002-12-06 21:44:35 +08:00
static oci_session * _oci_open_session ( oci_server * server , char * username , char * password , int persistent , int exclusive , char * charset )
1999-04-22 06:49:16 +08:00
{
2003-12-16 18:29:11 +08:00
zend_llist * session_list ;
oci_session * session = NULL ;
OCISvcCtx * svchp = NULL ;
2003-11-06 22:29:09 +08:00
smart_str hashed_details = { 0 } ;
2003-04-30 18:17:25 +08:00
# ifdef HAVE_OCI_9_2
2003-04-22 01:53:37 +08:00
ub2 charsetid = 0 ;
2003-01-28 04:05:48 +08:00
# endif
2002-11-16 01:59:19 +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 !
2003-11-06 22:29:09 +08:00
but only as persistent requested connections will be kept between requests !
1999-04-22 06:49:16 +08:00
*/
2003-11-06 22:29:09 +08:00
# if defined(HAVE_OCI_9_2)
if ( * charset ) {
smart_str_appends_ex ( & hashed_details , charset , 1 ) ;
} else {
size_t rsize ;
/* Safe, charsetid is initialized to 0 */
CALL_OCI ( OCINlsEnvironmentVariableGet ( & charsetid ,
2 ,
OCI_NLS_CHARSET_ID ,
2003-11-06 22:31:33 +08:00
0 ,
2003-11-06 22:29:09 +08:00
& rsize ) ) ;
smart_str_append_long_ex ( & hashed_details , charsetid , 1 ) ;
2003-11-06 22:31:33 +08:00
charsetid = 0 ;
2003-11-06 22:29:09 +08:00
}
# else
{
char * nls_lang = getenv ( " NLS_LANG " ) ;
/* extract charset from NLS_LANG=LANUAGE_TERRITORY.CHARSET */
if ( nls_lang ) {
char * p = strchr ( nls_lang , ' . ' ) ;
if ( p ) {
smart_str_appends_ex ( & hashed_details , p + 1 , 1 ) ;
}
}
}
# endif
smart_str_appends_ex ( & hashed_details , SAFE_STRING ( username ) , 1 ) ;
smart_str_appends_ex ( & hashed_details , SAFE_STRING ( password ) , 1 ) ;
smart_str_appends_ex ( & hashed_details , SAFE_STRING ( server - > dbname ) , 1 ) ;
smart_str_0 ( & hashed_details ) ;
1999-04-22 06:49:16 +08:00
1999-05-12 22:28:01 +08:00
if ( ! exclusive ) {
2003-12-16 19:15:55 +08:00
if ( zend_ts_hash_find ( persistent_sessions , hashed_details . c , hashed_details . len + 1 , ( void * * ) & session_list ) ! = SUCCESS ) {
2003-12-16 18:29:11 +08:00
zend_llist tmp ;
/* first session, set up a session list */
zend_llist_init ( & tmp , sizeof ( oci_session ) , ( llist_dtor_func_t ) _session_pcleanup , 1 ) ;
2003-12-16 19:15:55 +08:00
zend_ts_hash_update ( persistent_sessions , hashed_details . c , hashed_details . len + 1 , & tmp , sizeof ( zend_llist ) , ( void * * ) & session_list ) ;
2003-12-16 18:29:11 +08:00
} else {
mutex_lock ( mx_lock ) ;
/* session list found, search for an idle session or an already opened session by the current thread */
session = zend_llist_get_first ( session_list ) ;
while ( ( session ! = NULL ) & & session - > thread & & ( session - > thread ! = thread_id ( ) ) ) {
session = zend_llist_get_next ( session_list ) ;
}
if ( session ! = NULL ) {
/* mark session as busy */
session - > thread = thread_id ( ) ;
}
mutex_unlock ( mx_lock ) ;
}
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 ;
}
2003-11-06 22:29:09 +08:00
smart_str_free_ex ( & hashed_details , 1 ) ;
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
}
2003-12-16 18:29:11 +08:00
session = ecalloc ( 1 , sizeof ( oci_session ) ) ;
1999-04-22 06:49:16 +08:00
if ( ! session ) {
goto CLEANUP ;
}
session - > persistent = persistent ;
session - > server = server ;
2000-03-06 16:02:15 +08:00
session - > exclusive = exclusive ;
2003-12-16 18:29:11 +08:00
session - > sessions_list = session_list ;
session - > thread = thread_id ( ) ;
1999-04-22 06:49:16 +08:00
2003-04-30 18:17:25 +08:00
# ifdef HAVE_OCI_9_2
2002-12-11 23:25:39 +08:00
/* following chunk is Oracle 9i+ ONLY */
2002-12-11 22:18:40 +08:00
if ( * charset ) {
2002-12-11 23:25:39 +08:00
/*
get ub2 charset id based on charset
this is pretty secure , since if we don ' t have a valid character set name ,
0 comes back and we can still use the 0 in all further statements - > OCI uses NLS_LANG
setting in that case
*/
2002-12-06 21:44:35 +08:00
CALL_OCI_RETURN ( charsetid , OCINlsCharSetNameToId (
OCI ( pEnv ) ,
charset ) ) ;
oci_debug ( " oci_do_connect: using charset id=%d " , charsetid ) ;
}
2003-04-22 01:53:37 +08:00
session - > charsetId = charsetid ;
2002-12-06 21:44:35 +08:00
2002-12-11 23:25:39 +08:00
/* create an environment using the character set id, Oracle 9i+ ONLY */
2002-12-06 21:44:35 +08:00
CALL_OCI ( OCIEnvNlsCreate (
& session - > pEnv ,
OCI_DEFAULT ,
0 ,
NULL ,
NULL ,
NULL ,
0 ,
NULL ,
charsetid ,
charsetid ) ) ;
2002-12-11 23:25:39 +08:00
# else
/* fallback solution (simply use global env and charset, same behaviour as always been) */
2002-12-06 21:44:35 +08:00
session - > pEnv = OCI ( pEnv ) ;
session - > charsetId = 0 ;
2003-04-30 18:17:25 +08:00
# endif /* HAVE_OCI_9_2 */
2002-12-06 21:44:35 +08:00
1999-04-22 06:49:16 +08:00
/* allocate temporary Service Context */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
session - > pEnv ,
2001-08-16 00:00:56 +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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
session - > pEnv ,
2001-08-16 00:00:56 +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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIAttrSet (
svchp ,
OCI_HTYPE_SVCCTX ,
server - > pServer ,
0 ,
OCI_ATTR_SERVER ,
OCI ( pError ) ) ) ;
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: OCIAttrSet OCI_ATTR_SERVER " , OCI ( error ) ) ;
1999-04-22 06:49:16 +08:00
goto CLEANUP ;
}
/* set the username in user handle */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIAttrSet (
( dvoid * ) session - > pSession ,
( ub4 ) OCI_HTYPE_SESSION ,
( dvoid * ) username ,
( ub4 ) strlen ( username ) ,
( ub4 ) OCI_ATTR_USERNAME ,
OCI ( pError ) ) ) ;
1999-08-17 21:54:25 +08:00
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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIAttrSet (
( dvoid * ) session - > pSession ,
( ub4 ) OCI_HTYPE_SESSION ,
( dvoid * ) password ,
( ub4 ) strlen ( password ) ,
( ub4 ) OCI_ATTR_PASSWORD ,
OCI ( pError ) ) ) ;
1999-08-17 21:54:25 +08:00
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 ;
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCISessionBegin (
svchp ,
OCI ( pError ) ,
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 */
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) svchp ,
( ub4 ) OCI_HTYPE_SVCCTX ) ) ;
1999-04-22 06:49:16 +08:00
2003-12-16 18:29:11 +08:00
session - > num = zend_list_insert ( session , le_session ) ;
session - > is_open = 1 ;
1999-04-22 06:49:16 +08:00
2003-12-16 18:29:11 +08:00
mutex_lock ( mx_lock ) ;
num_links + + ;
if ( ! exclusive ) {
zend_llist_add_element ( session_list , session ) ;
efree ( session ) ;
session = ( oci_session * ) session_list - > tail - > data ;
num_persistent + + ;
}
mutex_unlock ( mx_lock ) ;
1999-04-22 06:49:16 +08:00
2003-12-16 18:29:11 +08:00
oci_debug ( " _oci_open_session new sess=%d user=%s " , session - > num , username ) ;
1999-04-22 06:49:16 +08:00
2003-12-16 18:29:11 +08:00
return session ;
2000-02-01 22:39:59 +08:00
2003-04-30 18:19:21 +08:00
CLEANUP :
2000-02-01 22:39:59 +08:00
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
*/
2003-12-16 19:15:55 +08:00
static int _session_compare ( void * a , void * b )
2003-12-16 18:29:11 +08:00
{
2003-12-16 19:15:55 +08:00
oci_session * sess1 = ( oci_session * ) a ;
oci_session * sess2 = ( oci_session * ) b ;
2003-12-16 18:29:11 +08:00
return sess1 - > num = sess2 - > num ;
}
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 ;
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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
session - > pEnv ,
2001-08-16 00:00:56 +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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIAttrSet (
svchp ,
OCI_HTYPE_SVCCTX ,
session - > server - > pServer ,
0 ,
OCI_ATTR_SERVER ,
OCI ( pError ) ) ) ;
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: OCIAttrSet OCI_ATTR_SERVER " , OCI ( error ) ) ;
1999-04-25 02:54:02 +08:00
}
/* Set the Authentication handle in the service handle */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIAttrSet (
svchp ,
OCI_HTYPE_SVCCTX ,
session - > pSession ,
0 ,
OCI_ATTR_SESSION ,
OCI ( pError ) ) ) ;
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: OCIAttrSet OCI_ATTR_SESSION " , OCI ( error ) ) ;
1999-04-25 02:54:02 +08:00
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCISessionEnd (
svchp ,
OCI ( pError ) ,
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
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) svchp ,
( ub4 ) OCI_HTYPE_SVCCTX ) ) ;
2000-07-03 23:05:46 +08:00
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 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleFree (
( dvoid * ) session - > pSession ,
( ub4 ) OCI_HTYPE_SESSION ) ) ;
1999-04-25 02:54:02 +08:00
}
2000-02-01 22:39:59 +08:00
2003-12-16 18:29:11 +08:00
mutex_lock ( mx_lock ) ;
num_links - - ;
if ( ! OCI ( shutdown ) & & session - > persistent ) {
zend_llist_del_element ( session - > sessions_list , session , _session_compare ) ;
num_persistent - - ;
}
mutex_unlock ( mx_lock ) ;
2000-02-01 22:39:59 +08:00
2003-12-16 18:29:11 +08:00
if ( session - > exclusive ) {
efree ( session ) ;
2000-02-01 22:39:59 +08:00
}
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
{
2003-12-16 18:29:11 +08:00
oci_server * server , * pserver = NULL ;
2002-11-16 01:59:19 +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 !
*/
2003-12-16 18:29:11 +08:00
/* TODO either keep servers global or don't reuse them at all */
zend_ts_hash_find ( persistent_servers , 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
2003-12-16 18:29:11 +08:00
server = ecalloc ( 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 ) ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIHandleAlloc (
OCI ( pEnv ) ,
( dvoid * * ) & server - > pServer ,
OCI_HTYPE_SERVER ,
0 ,
NULL ) ) ;
1999-04-22 06:49:16 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIServerAttach (
server - > pServer ,
OCI ( pError ) ,
( text * ) server - > dbname ,
strlen ( server - > dbname ) ,
( 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 ;
}
2003-12-16 18:29:11 +08:00
zend_ts_hash_update ( persistent_servers ,
2000-02-01 22:39:59 +08:00
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
2003-12-16 18:29:11 +08:00
efree ( server ) ;
2000-02-01 22:39:59 +08:00
return pserver ;
1999-05-12 22:28:01 +08:00
2003-04-30 18:19:21 +08:00
CLEANUP :
2000-02-01 22:39:59 +08:00
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 ,
2002-11-16 01:59:19 +08:00
( ub4 ) OCI_HTYPE_SERVER ,
( dvoid * ) & server - > failover ,
( ub4 ) 0 ,
( ub4 ) OCI_ATTR_FOCBK ,
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 ;
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( le ) = = le_session ) {
2000-02-01 22:39:59 +08:00
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 ) ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN (
OCI ( error ) ,
OCIServerDetach ( server - > pServer ,
OCI ( pError ) ,
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 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI ( 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 ) ) {
2003-12-16 18:29:11 +08:00
zend_ts_hash_del ( persistent_servers , 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
{
2002-12-06 21:44:35 +08:00
char * username , * password , * dbname , * charset ;
zval * * userParam , * * passParam , * * dbParam , * * charParam ;
2002-11-16 01:59:19 +08:00
oci_server * server = 0 ;
oci_session * session = 0 ;
oci_connection * connection = 0 ;
1999-04-25 02:54:02 +08:00
2002-12-11 23:25:39 +08:00
/* if a forth parameter is handed over, it is the charset identifier (but is only used in Oracle 9i+) */
if ( zend_get_parameters_ex ( 4 , & userParam , & passParam , & dbParam , & charParam ) = = SUCCESS ) {
2002-12-06 21:44:35 +08:00
convert_to_string_ex ( userParam ) ;
convert_to_string_ex ( passParam ) ;
convert_to_string_ex ( dbParam ) ;
convert_to_string_ex ( charParam ) ;
username = Z_STRVAL_PP ( userParam ) ;
password = Z_STRVAL_PP ( passParam ) ;
dbname = Z_STRVAL_PP ( dbParam ) ;
charset = Z_STRVAL_PP ( charParam ) ;
oci_debug ( " oci_do_connect: using charset=%s " , charset ) ;
} else 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 ) ;
2001-09-26 06:49:04 +08:00
username = Z_STRVAL_PP ( userParam ) ;
password = Z_STRVAL_PP ( passParam ) ;
dbname = Z_STRVAL_PP ( dbParam ) ;
2003-04-22 01:53:37 +08:00
charset = " " ;
2002-11-16 01:59:19 +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 ) ;
2001-09-26 06:49:04 +08:00
username = Z_STRVAL_PP ( userParam ) ;
password = Z_STRVAL_PP ( passParam ) ;
1999-06-09 18:40:08 +08:00
dbname = " " ;
2003-04-22 01:53:37 +08:00
charset = " " ;
2002-11-16 01:59:19 +08:00
} else {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT ;
2002-11-16 01:59:19 +08:00
}
1999-04-22 06:49:16 +08:00
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 ;
}
2002-04-13 20:10:03 +08:00
if ( exclusive ) {
/* exlusive session can never be persistent!*/
persistent = 0 ;
} else {
/* if our server-context is not persistent we can't */
2003-12-16 18:29:11 +08:00
persistent = ( server - > persistent ) ? persistent : 0 ;
2002-04-13 20:10:03 +08:00
}
1999-04-22 06:49:16 +08:00
2002-12-06 21:44:35 +08:00
session = _oci_open_session ( server , username , password , persistent , exclusive , charset ) ;
1999-04-22 06:49:16 +08:00
if ( ! session ) {
goto CLEANUP ;
}
/* set our session */
connection - > session = session ;
/* allocate our private error-handle */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( OCI ( error ) , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIAttrSet (
connection - > pServiceContext ,
OCI_HTYPE_SVCCTX ,
server - > pServer ,
0 ,
OCI_ATTR_SERVER ,
connection - > pError ) ) ;
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 , " 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 */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIAttrSet (
connection - > pServiceContext ,
OCI_HTYPE_SVCCTX ,
session - > pSession ,
0 ,
OCI_ATTR_SESSION ,
connection - > pError ) ) ;
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 , " 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 ,
2002-11-16 01:59:19 +08:00
OCI_HTYPE_SERVER ,
( dvoid * ) " demo " ,
0 ,
OCI_ATTR_EXTERNAL_NAME ,
connection - > pError ) ;
1999-04-25 02:54:02 +08:00
OCIAttrSet ( ( dvoid * ) session - > server - > pServer ,
2002-11-16 01:59:19 +08:00
OCI_HTYPE_SERVER ,
( dvoid * ) " txn demo2 " ,
0 ,
OCI_ATTR_INTERNAL_NAME ,
connection - > pError ) ;
1999-04-25 02:54:02 +08:00
*/
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
2003-04-30 18:19:21 +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 *************************/
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_define_by_name(resource 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
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_define_by_name )
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
2002-11-16 01:59:19 +08:00
if ( ac < 3 | | ac > 4 | | zend_get_parameters_ex ( ac , & stmt , & name , & var , & type ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
switch ( ac ) {
1999-09-30 16:41:45 +08:00
case 4 :
convert_to_long_ex ( type ) ;
2001-09-26 05:58:48 +08:00
ocitype = ( ub2 ) Z_LVAL_PP ( type ) ;
1999-09-30 16:41:45 +08:00
/* 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 ,
2001-09-26 05:58:48 +08:00
Z_STRVAL_PP ( name ) ,
Z_STRLEN_PP ( name ) ,
1999-09-30 16:41:45 +08:00
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 ;
}
2001-09-26 05:58:48 +08:00
define - > name = ( text * ) estrndup ( Z_STRVAL_PP ( name ) , Z_STRLEN_PP ( name ) ) ;
define - > name_len = Z_STRLEN_PP ( name ) ;
Z_TYPE_P ( define ) = 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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_bind_by_name(resource 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
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_bind_by_name )
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 ;
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
oci_collection * coll ;
dvoid * mycoll = 0 ;
2001-04-13 22:43:39 +08:00
# endif
2001-08-16 00:00:56 +08:00
int mode = OCI_DATA_AT_EXEC ;
2000-01-16 21:30:57 +08:00
ub2 ocitype = SQLT_CHR ; /* unterminated string */
2002-11-16 01:59:19 +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
2002-11-16 01:59:19 +08:00
if ( ac < 3 | | ac > 5 | | zend_get_parameters_ex ( ac , & stmt , & name , & var , & maxlen , & type ) = = FAILURE ) {
2000-10-23 03:33:59 +08:00
WRONG_PARAM_COUNT ;
2002-11-16 01:59:19 +08:00
}
1999-04-22 06:49:16 +08:00
2002-11-16 01:59:19 +08:00
switch ( ac ) {
1999-09-30 16:41:45 +08:00
case 5 :
convert_to_long_ex ( type ) ;
2001-09-26 05:58:48 +08:00
ocitype = ( ub2 ) Z_LVAL_PP ( type ) ;
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 ) ;
2001-09-26 05:58:48 +08:00
value_sz = Z_LVAL_PP ( maxlen ) ;
2000-01-16 21:30:57 +08:00
/* 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 ) {
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2002-11-16 01:59:19 +08:00
case SQLT_NTY :
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_PP ( var ) ! = IS_OBJECT ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Variable must be allocated using OCINewCollection() " ) ;
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
}
if ( ( inx = _oci_get_ocicoll ( * var , & coll TSRMLS_CC ) ) = = 0 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Variable must be allocated using OCINewCollection() " ) ;
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
2001-04-13 22:43:39 +08:00
}
2002-11-16 01:59:19 +08:00
if ( ! ( mycoll = ( dvoid * ) coll - > coll ) ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Collection empty " ) ;
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
}
value_sz = sizeof ( void * ) ;
mode = OCI_DEFAULT ;
break ;
2001-04-13 22:43:39 +08:00
# 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 :
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_PP ( var ) ! = IS_OBJECT ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Variable must be allocated using OCINewDescriptor() " ) ;
2000-10-23 03:33:59 +08:00
RETURN_FALSE ;
}
2001-08-01 07:47:35 +08:00
if ( ( inx = _oci_get_ocidesc ( * var , & descr TSRMLS_CC ) ) = = 0 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Variable must be allocated using OCINewDescriptor() " ) ;
2000-10-23 03:33:59 +08:00
RETURN_FALSE ;
}
2000-01-16 21:30:57 +08:00
2000-10-23 03:33:59 +08:00
if ( ! ( mydescr = ( dvoid * ) descr - > ocidescr ) ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Descriptor empty " ) ;
2000-10-23 03:33:59 +08:00
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 ) ;
2001-09-26 05:58:48 +08:00
value_sz = Z_STRLEN_PP ( var ) ;
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 ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( statement - > error , OCIBindByName (
statement - > pStmt , /* statement handle */
2002-11-16 01:59:19 +08:00
( OCIBind * * ) & bindp - > pBind , /* bind hdl (will alloc) */
statement - > pError , /* error handle */
( text * ) Z_STRVAL_PP ( name ) , /* placeholder name */
Z_STRLEN_PP ( name ) , /* placeholder length */
( dvoid * ) 0 , /* in/out data */
value_sz , /* OCI_MAX_DATA_SIZE, */ /* max size of input/output data */
( 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?) */
mode /* mode */
2001-08-16 00:00:56 +08:00
) ) ;
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-08-16 00:00:56 +08:00
if ( mode = = OCI_DATA_AT_EXEC ) {
CALL_OCI_RETURN ( statement - > error , OCIBindDynamic (
bindp - > pBind ,
statement - > pError ,
( dvoid * ) bindp ,
oci_bind_in_callback ,
( dvoid * ) bindp ,
oci_bind_out_callback ) ) ;
2000-01-16 21:30:57 +08:00
2001-08-16 00:00:56 +08:00
if ( statement - > error ! = OCI_SUCCESS ) {
oci_error ( statement - > pError , " OCIBindDynamic " , statement - > error ) ;
oci_handle_error ( statement - > conn , statement - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
}
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-08-16 00:00:56 +08:00
if ( ocitype = = SQLT_NTY ) {
2001-04-13 22:43:39 +08:00
/* Bind object */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( statement - > error , OCIBindObject (
bindp - > pBind ,
statement - > pError ,
coll - > tdo ,
( dvoid * * ) & ( coll - > coll ) ,
( ub4 * ) 0 ,
( dvoid * * ) 0 ,
( ub4 * ) 0 ) ) ;
2001-04-13 22:43:39 +08:00
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_free_descriptor()
2000-02-23 23:54:23 +08:00
Deletes large object description */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_free_descriptor )
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
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_free_descriptor() should not be called like this. Use $somelob->free() to free a LOB " ) ;
2001-02-14 21:06:03 +08:00
RETURN_FALSE ;
1999-04-22 06:49:16 +08:00
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_save()
2000-02-23 23:54:23 +08:00
Saves a large object */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_save )
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 ;
2002-11-16 01:59:19 +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 ;
2002-11-16 01:59:19 +08:00
if ( zend_get_parameters_ex ( 2 , & arg , & oarg ) = = SUCCESS ) {
1999-09-30 16:41:45 +08:00
convert_to_long_ex ( oarg ) ;
2001-09-26 05:58:48 +08:00
offparam = Z_LVAL_PP ( oarg ) ;
1999-09-14 20:41:00 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobGetLength (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
& curloblen ) ) ;
1999-09-14 20:41:00 +08:00
oci_debug ( " OCIsavedesc: curloblen=%d " , curloblen ) ;
if ( offparam = = - 1 ) {
offset = curloblen ;
2001-05-31 01:49:33 +08:00
} else if ( ( ub4 ) offparam > = curloblen ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Offset smaller than current LOB-Size - appending " ) ;
1999-09-14 20:41:00 +08:00
offset = curloblen ;
} else {
offset = offparam ;
}
2002-11-16 01:59:19 +08:00
} else if ( zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
1999-04-22 06:49:16 +08:00
1999-09-14 20:41:00 +08:00
offset + + ;
1999-09-30 16:41:45 +08:00
convert_to_string_ex ( arg ) ;
2001-09-26 05:58:48 +08:00
loblen = Z_STRLEN_PP ( arg ) ;
1999-04-22 06:49:16 +08:00
if ( loblen < 1 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot save a lob which size is less than 1 byte " ) ;
1999-04-22 06:49:16 +08:00
RETURN_FALSE ;
}
1999-09-14 20:41:00 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobWrite (
connection - > pServiceContext ,
1999-09-14 20:41:00 +08:00
connection - > pError ,
mylob ,
& loblen ,
( ub4 ) offset ,
2001-09-26 05:58:48 +08:00
( dvoid * ) Z_STRVAL_PP ( arg ) ,
1999-09-14 20:41:00 +08:00
( ub4 ) loblen ,
OCI_ONE_PIECE ,
( dvoid * ) 0 ,
( OCICallbackLobWrite ) 0 ,
( ub2 ) 0 ,
2001-08-16 00:00:56 +08:00
( ub1 ) SQLCS_IMPLICIT ) ) ;
1999-09-14 20:41:00 +08:00
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_import()
Saves a large object to file */
1999-09-13 19:49:07 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_import )
1999-09-13 19:49:07 +08:00
{
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 ;
2002-11-16 01:59:19 +08:00
if ( zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
1999-09-13 19:49:07 +08:00
1999-09-30 16:41:45 +08:00
convert_to_string_ex ( arg ) ;
1999-09-13 19:49:07 +08:00
2001-09-26 05:58:48 +08:00
if ( php_check_open_basedir ( Z_STRVAL_PP ( arg ) TSRMLS_CC ) ) {
1999-09-13 19:49:07 +08:00
RETURN_FALSE ;
}
2001-09-26 05:58:48 +08:00
filename = Z_STRVAL_PP ( arg ) ;
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 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Can't open file %s " , filename ) ;
1999-09-13 19:49:07 +08:00
RETURN_FALSE ;
2002-11-16 01:59:19 +08:00
}
1999-09-13 19:49:07 +08:00
while ( ( loblen = read ( fp , & buf , sizeof ( buf ) ) ) > 0 ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( 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 ) ) ;
1999-09-13 19:49:07 +08:00
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
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_lob_load()
2000-02-23 23:54:23 +08:00
Loads a large object */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_load )
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 ;
}
2003-12-15 21:53:01 +08:00
2001-02-18 19:10:30 +08:00
if ( ! oci_loadlob ( descr - > conn , descr , & buffer , & loblen ) ) {
2003-12-15 21:53:01 +08:00
RETURN_STRINGL ( buffer , loblen , 0 ) ;
}
else {
RETURN_FALSE ;
1999-04-22 06:49:16 +08:00
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_load() should not be called like this. Use $somelob->load() to load a LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_lob_read()
2003-12-15 21:53:01 +08:00
Reads particular part of a large object */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_read )
2003-12-15 21:53:01 +08:00
{
zval * id ;
zval * * len ;
oci_descriptor * descr ;
char * buffer ;
int inx ;
ub4 loblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 1 , & len ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
loblen = Z_LVAL_PP ( len ) ;
if ( oci_readlob ( descr - > conn , descr , & buffer , & loblen ) = = 0 ) {
RETURN_STRINGL ( buffer , loblen , 0 ) ;
}
else {
RETURN_FALSE ;
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_read() should not be called like this. Use $somelob->read($len) to read a LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_eof()
2003-12-15 21:53:01 +08:00
Checks if EOF is reached */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_eof )
2003-12-15 21:53:01 +08:00
{
zval * id ;
oci_descriptor * descr ;
int inx ;
int len ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
if ( oci_lobgetlen ( descr - > conn , descr , & len ) = = 0 & & descr - > lob_size > = 0 ) {
if ( descr - > lob_size = = descr - > lob_current_position ) {
RETURN_TRUE ;
}
else {
RETURN_FALSE ;
}
}
RETURN_FALSE ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_eof() should not be called like this. Use $somelob->eof() to check if end of LOB is reached " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_lob_tell()
2003-12-15 21:53:01 +08:00
Tells LOB pointer position */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_tell )
2003-12-15 21:53:01 +08:00
{
zval * id ;
oci_descriptor * descr ;
int inx ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
RETURN_LONG ( descr - > lob_current_position ) ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_tell() should not be called like this. Use $somelob->tell() to get current position of LOB pointer " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_rewind()
2003-12-15 21:53:01 +08:00
Rewind pointer of a LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_rewind )
2003-12-15 21:53:01 +08:00
{
zval * id ;
oci_descriptor * descr ;
int inx ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
descr - > lob_current_position = 0 ;
RETURN_TRUE ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_rewind() should not be called like this. Use $somelob->rewind() to set current position of LOB pointer to beginning " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_seek()
2003-12-15 21:53:01 +08:00
Moves the pointer of a LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_seek )
2003-12-15 21:53:01 +08:00
{
zval * id ;
zval * * arg1 , * * arg2 ;
int argcount = ZEND_NUM_ARGS ( ) , whence = OCI_SEEK_SET ;
oci_descriptor * descr ;
int inx , len ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
if ( argcount < 1 | | argcount > 2 | | zend_get_parameters_ex ( argcount , & arg1 , & arg2 ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
convert_to_long_ex ( arg1 ) ;
if ( oci_lobgetlen ( descr - > conn , descr , & len ) = = 0 & & descr - > lob_size > = 0 ) {
if ( argcount > 1 ) {
convert_to_long_ex ( arg2 ) ;
whence = Z_LVAL_PP ( arg2 ) ;
switch ( whence ) {
case OCI_SEEK_CUR :
descr - > lob_current_position + = Z_LVAL_PP ( arg1 ) ;
break ;
case OCI_SEEK_END :
if ( descr - > lob_size + Z_LVAL_PP ( arg1 ) > = 0 ) {
descr - > lob_current_position = descr - > lob_size + Z_LVAL_PP ( arg1 ) ;
}
else {
descr - > lob_current_position = 0 ;
}
break ;
case OCI_SEEK_SET :
default :
descr - > lob_current_position = Z_LVAL_PP ( arg1 ) ;
break ;
}
}
else {
2003-12-16 18:29:11 +08:00
/* OCI_SEEK_SET by default */
2003-12-15 21:53:01 +08:00
descr - > lob_current_position = Z_LVAL_PP ( arg1 ) ;
}
RETURN_TRUE ;
}
else {
RETURN_FALSE ;
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_seek() should not be called like this. Use $somelob->seek($offset) to move pointer " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
1999-04-22 06:49:16 +08:00
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_lob_size()
2003-12-15 21:53:01 +08:00
Returns size of a large object */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_size )
2003-12-15 21:53:01 +08:00
{
zval * id ;
oci_descriptor * descr ;
int inx ;
ub4 loblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
if ( ! oci_lobgetlen ( descr - > conn , descr , & loblen ) ) {
RETURN_LONG ( loblen ) ;
}
else {
RETURN_FALSE ;
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_size() should not be called like this. Use $somelob->size() to get size of a LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_lob_write()
2003-12-15 21:53:01 +08:00
Writes data to current position of a LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_write )
2003-12-15 21:53:01 +08:00
{
zval * id , * * data , * * length ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
int write_length , inx ;
ub4 loblen ;
ub4 curloblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 2 , & data , & length ) = = SUCCESS ) {
convert_to_long_ex ( length ) ;
write_length = Z_LVAL_PP ( length ) ;
}
else if ( zend_get_parameters_ex ( 1 , & data ) = = SUCCESS ) {
convert_to_string_ex ( data ) ;
write_length = Z_STRLEN_PP ( data ) ;
}
else {
WRONG_PARAM_COUNT ;
}
if ( write_length < 1 ) {
RETURN_LONG ( 0 ) ;
}
loblen = write_length ;
CALL_OCI_RETURN ( connection - > error , OCILobWrite (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
& loblen ,
( ub4 ) descr - > lob_current_position + 1 ,
( dvoid * ) Z_STRVAL_PP ( data ) ,
( ub4 ) loblen ,
OCI_ONE_PIECE ,
( dvoid * ) 0 ,
( OCICallbackLobWrite ) 0 ,
( ub2 ) 0 ,
( ub1 ) SQLCS_IMPLICIT ) ) ;
2003-12-23 23:45:36 +08:00
oci_debug ( " OCILobWrite: size=%d offset=%d " , loblen , descr - > lob_current_position ) ;
2003-12-15 21:53:01 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobWrite " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
descr - > lob_current_position + = loblen ;
if ( descr - > lob_current_position > descr - > lob_size ) {
descr - > lob_size = descr - > lob_current_position ;
}
2003-12-16 18:29:11 +08:00
/* marking buffer as used */
2003-12-15 21:53:01 +08:00
if ( descr - > buffering = = 1 ) {
descr - > buffering = 2 ;
}
RETURN_LONG ( loblen ) ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_write() should not be called like this. Use $somelob->write($data,$len) to write to a LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_append()
2003-12-15 21:53:01 +08:00
Appends data from a LOB to another LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_append )
2003-12-15 21:53:01 +08:00
{
zval * id , * * arg ;
OCILobLocator * mylob , * my_fromlob ;
oci_connection * connection ;
oci_descriptor * descr , * from_descr ;
int inx ;
ub4 curloblen , from_curloblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 1 , & arg ) = = SUCCESS ) {
if ( ( inx = _oci_get_ocidesc ( * arg , & from_descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
my_fromlob = ( OCILobLocator * ) from_descr - > ocidescr ;
if ( ! my_fromlob ) {
RETURN_FALSE ;
}
if ( oci_lobgetlen ( from_descr - > conn , from_descr , & from_curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
}
else {
WRONG_PARAM_COUNT ;
}
if ( from_descr - > lob_size = = 0 ) {
RETURN_LONG ( 0 ) ;
}
CALL_OCI_RETURN ( connection - > error , OCILobAppend (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
my_fromlob ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobAppend " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_append() should not be called like this. Use $somelob->append($LOB_from) to append data from a LOB to another LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_truncate()
2003-12-15 21:53:01 +08:00
Truncates a LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_truncate )
2003-12-15 21:53:01 +08:00
{
zval * id , * * length ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
int inx ;
ub4 trim_length ;
ub4 curloblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 1 , & length ) = = SUCCESS ) {
convert_to_long_ex ( length ) ;
trim_length = Z_LVAL_PP ( length ) ;
}
else {
WRONG_PARAM_COUNT ;
}
if ( trim_length < 0 ) {
2003-12-16 18:29:11 +08:00
/* negative length is not allowed */
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCILobTrim (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
trim_length ) ) ;
2003-12-23 23:45:36 +08:00
oci_debug ( " OCILobTrim: trim_length=%d " , trim_length ) ;
2003-12-15 21:53:01 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobTrim " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
descr - > lob_size = trim_length ;
RETURN_TRUE ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_truncate() should not be called like this. Use $somelob->truncate($length) to truncate a LOB to a specified length " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_lob_erase()
2003-12-15 21:53:01 +08:00
Erases a specified portion of the internal LOB , starting at a specified offset */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_erase )
2003-12-15 21:53:01 +08:00
{
zval * id , * * length , * * offset ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
int inx ;
ub4 erase_length , erase_offset ;
ub4 curloblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 2 , & offset , & length ) = = SUCCESS ) {
convert_to_long_ex ( offset ) ;
convert_to_long_ex ( length ) ;
erase_offset = Z_LVAL_PP ( offset ) ;
erase_length = Z_LVAL_PP ( length ) ;
}
else if ( zend_get_parameters_ex ( 1 , & offset ) = = SUCCESS ) {
convert_to_long_ex ( offset ) ;
erase_offset = Z_LVAL_PP ( offset ) ;
erase_length = descr - > lob_size - erase_offset ;
}
else {
erase_offset = 0 ;
erase_length = descr - > lob_size ;
}
if ( erase_length < 1 ) {
RETURN_LONG ( 0 ) ;
}
CALL_OCI_RETURN ( connection - > error , OCILobErase (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
& erase_length ,
erase_offset + 1 ) ) ;
2003-12-23 23:45:36 +08:00
oci_debug ( " OCILobErase: erase_length=%d, erase_offset=%d " , erase_length , erase_offset ) ;
2003-12-15 21:53:01 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobErase " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_LONG ( erase_length ) ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_erase() should not be called like this. Use $somelob->erase($offset, $length) to erase specified part of LOB " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_flush()
2003-12-15 21:53:01 +08:00
Flushes the LOB buffer */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_flush )
2003-12-15 21:53:01 +08:00
{
zval * id , * * flag ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
int inx , flush_flag ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( zend_get_parameters_ex ( 1 , & flag ) = = SUCCESS ) {
convert_to_long_ex ( flag ) ;
flush_flag = Z_LVAL_PP ( flag ) ;
}
else {
flush_flag = 0 ;
}
if ( descr - > buffering = = 0 ) {
2003-12-16 18:29:11 +08:00
/* buffering wasn't enabled, there is nothing to flush */
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
else if ( descr - > buffering = = 1 ) {
2003-12-16 18:29:11 +08:00
/* buffering is enabled, but not used yet
dunno why , but OCI returns error in this case , so I think we should suppress it */
2003-12-15 21:53:01 +08:00
RETURN_TRUE ;
}
CALL_OCI_RETURN ( connection - > error , OCILobFlushBuffer (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
flush_flag ) ) ;
2003-12-23 23:45:36 +08:00
oci_debug ( " OCILobFlushBuffer: flush_flag=%d " , flush_flag ) ;
2003-12-15 21:53:01 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFlushBuffer " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_flush() should not be called like this. Use $somelob->flush() to flush LOB buffer " ) ;
2003-12-15 21:53:01 +08:00
RETURN_FALSE ;
}
/* }}} */
/* {{{ proto bool ocisetbufferinglob()
Enables / disables buffering for a LOB */
PHP_FUNCTION ( ocisetbufferinglob )
{
zval * id , * * flag ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
int inx , buffering_flag ;
ub4 curloblen ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( zend_get_parameters_ex ( 1 , & flag ) = = SUCCESS ) {
convert_to_boolean_ex ( flag ) ;
buffering_flag = Z_LVAL_PP ( flag ) ;
}
else {
WRONG_PARAM_COUNT ;
}
/* we'll return true if function was called twice with the same parameter */
if ( buffering_flag = = 0 & & descr - > buffering = = 0 ) {
RETURN_TRUE ;
}
else if ( buffering_flag = = 1 & & descr - > buffering > 0 ) {
RETURN_TRUE ;
}
switch ( buffering_flag ) {
case 0 :
CALL_OCI_RETURN ( connection - > error , OCILobDisableBuffering (
connection - > pServiceContext ,
connection - > pError ,
mylob ) ) ;
break ;
case 1 :
CALL_OCI_RETURN ( connection - > error , OCILobEnableBuffering (
connection - > pServiceContext ,
connection - > pError ,
mylob ) ) ;
break ;
}
oci_debug ( " OCIsavedesc: buffering_flag=%d " , buffering_flag ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFlushBuffer " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
descr - > buffering = buffering_flag ;
RETURN_TRUE ;
}
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " OCISetBufferingLob() should not be called like this. Use $somelob->setBuffering($flag) to set buffering on/off for a LOB " ) ;
RETURN_FALSE ;
}
/* }}} */
/* {{{ proto bool ocigetbufferinglob()
Returns current state of buffering for a LOB */
PHP_FUNCTION ( ocigetbufferinglob )
{
2003-12-16 18:29:11 +08:00
zval * id ;
2003-12-15 21:53:01 +08:00
OCILobLocator * mylob ;
oci_descriptor * descr ;
int inx ;
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocidesc ( id , & descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
if ( ! mylob ) {
RETURN_FALSE ;
}
switch ( descr - > buffering ) {
case 1 :
case 2 :
RETURN_TRUE ;
break ;
case 0 :
default :
RETURN_FALSE ;
break ;
}
}
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " OCIGetBufferingLob() should not be called like this. Use $somelob->getBuffering() to get current state of buffering for a LOB " ) ;
RETURN_FALSE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_copy()
2003-12-15 21:53:01 +08:00
Copies data from a LOB to another LOB */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_copy )
2003-12-15 21:53:01 +08:00
{
zval * * arg1 , * * arg2 , * * arg3 ;
OCILobLocator * mylob , * my_fromlob ;
oci_connection * connection ;
oci_descriptor * descr , * from_descr ;
int inx , ac = ZEND_NUM_ARGS ( ) ;
ub4 curloblen , from_curloblen , copylen ;
if ( ac < 2 | | ac > 3 | | zend_get_parameters_ex ( ac , & arg1 , & arg2 , & arg3 ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
if ( ( * arg1 ) - > type ! = IS_OBJECT | | ( * arg2 ) - > type ! = IS_OBJECT ) {
RETURN_FALSE ;
}
if ( ( inx = _oci_get_ocidesc ( * arg1 , & descr TSRMLS_CC ) ) = = 0 | | ( inx = _oci_get_ocidesc ( * arg2 , & from_descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
IS_LOB_INTERNAL ( descr ) ;
IS_LOB_INTERNAL ( from_descr ) ;
mylob = ( OCILobLocator * ) descr - > ocidescr ;
my_fromlob = ( OCILobLocator * ) from_descr - > ocidescr ;
if ( ! mylob | | ! my_fromlob ) {
RETURN_FALSE ;
}
if ( oci_lobgetlen ( descr - > conn , descr , & curloblen ) ! = 0 | | oci_lobgetlen ( from_descr - > conn , from_descr , & from_curloblen ) ! = 0 ) {
RETURN_FALSE ;
}
if ( ac = = 3 ) {
convert_to_long_ex ( arg3 ) ;
copylen = Z_LVAL_PP ( arg3 ) ;
}
else {
copylen = from_descr - > lob_size - from_descr - > lob_current_position ;
}
if ( ( int ) copylen < = 0 ) {
RETURN_FALSE ;
}
connection = descr - > conn ;
CALL_OCI_RETURN ( connection - > error , OCILobCopy (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
my_fromlob ,
copylen ,
descr - > lob_current_position + 1 ,
from_descr - > lob_current_position + 1
) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobCopy " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_is_equal()
2003-12-15 21:53:01 +08:00
Tests to see if two LOB / FILE locators are equal */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_is_equal )
2003-12-15 21:53:01 +08:00
{
zval * * arg1 , * * arg2 ;
OCILobLocator * first_lob , * second_lob ;
oci_connection * connection ;
oci_descriptor * first_descr , * second_descr ;
int inx ;
boolean is_equal ;
if ( zend_get_parameters_ex ( 2 , & arg1 , & arg2 ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
if ( ( * arg1 ) - > type ! = IS_OBJECT | | ( * arg2 ) - > type ! = IS_OBJECT ) {
RETURN_FALSE ;
}
if ( ( inx = _oci_get_ocidesc ( * arg1 , & first_descr TSRMLS_CC ) ) = = 0 | | ( inx = _oci_get_ocidesc ( * arg2 , & second_descr TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
first_lob = ( OCILobLocator * ) first_descr - > ocidescr ;
second_lob = ( OCILobLocator * ) second_descr - > ocidescr ;
if ( ! first_lob | | ! second_lob ) {
RETURN_FALSE ;
}
connection = first_descr - > conn ;
CALL_OCI_RETURN ( connection - > error , OCILobIsEqual (
connection - > session - > pEnv ,
first_lob ,
second_lob ,
& is_equal
) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobIsEqual " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
if ( is_equal = = TRUE ) {
RETURN_TRUE ;
}
else {
RETURN_FALSE ;
}
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_export([string filename [, int start [, int length]]])
2000-02-23 23:54:23 +08:00
Writes a large object into a file */
1999-10-28 01:51:22 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_export )
1999-10-28 01:51:22 +08:00
{
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 ;
2002-11-16 01:59:19 +08:00
if ( ac < 0 | | ac > 3 | | zend_get_parameters_ex ( ac , & zfilename , & zstart , & zlength ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
1999-10-28 01:51:22 +08:00
switch ( ac ) {
case 3 :
convert_to_long_ex ( zlength ) ;
2001-09-26 05:58:48 +08:00
length = Z_LVAL_PP ( zlength ) ;
1999-10-28 01:51:22 +08:00
case 2 :
convert_to_long_ex ( zstart ) ;
2001-09-26 05:58:48 +08:00
start = Z_LVAL_PP ( zstart ) ;
1999-10-28 01:51:22 +08:00
case 1 :
convert_to_string_ex ( zfilename ) ;
2001-09-26 05:58:48 +08:00
filename = Z_STRVAL_PP ( zfilename ) ;
1999-10-28 01:51:22 +08:00
}
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 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Can't create file %s " , filename ) ;
1999-10-28 01:51:22 +08:00
goto bail ;
}
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobGetLength (
connection - > pServiceContext ,
connection - > pError ,
descr - > ocidescr ,
& loblen ) ) ;
1999-10-28 01:51:22 +08:00
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 ;
}
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( descr ) = = OCI_DTYPE_FILE ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobFileOpen (
connection - > pServiceContext ,
connection - > pError ,
descr - > ocidescr ,
OCI_FILE_READONLY ) ) ;
1999-10-28 01:51:22 +08:00
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 ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobRead (
connection - > pServiceContext ,
2002-11-16 01:59:19 +08:00
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. */
1999-10-28 01:51:22 +08:00
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 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " cannot write file! " ) ;
1999-10-28 01:51:22 +08:00
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 ;
}
2001-09-26 05:58:48 +08:00
if ( Z_TYPE_P ( descr ) = = OCI_DTYPE_FILE ) {
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobFileClose (
connection - > pServiceContext ,
connection - > pError ,
descr - > ocidescr ) ) ;
1999-10-28 01:51:22 +08:00
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 ;
}
2003-04-30 18:19:21 +08:00
bail :
1999-10-28 01:51:22 +08:00
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_write_temporary(string var [, int lob_type])
2003-06-22 22:33:09 +08:00
Writes temporary blob */
2001-04-14 16:38:46 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_write_temporary )
2001-04-14 16:38:46 +08:00
{
2003-07-22 18:38:34 +08:00
zval * id , * var ;
2001-04-14 16:38:46 +08:00
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descr ;
ub4 offset = 1 ;
ub4 loblen ;
2003-07-22 18:38:34 +08:00
int lob_type = OCI_TEMP_CLOB ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
oci_debug ( " oci_write_temporary_lob " ) ;
2001-04-14 16:38:46 +08:00
if ( ( id = getThis ( ) ) = = 0 ) {
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( _oci_get_ocidesc ( id , & descr TSRMLS_CC ) = = 0 ) {
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
mylob = ( OCILobLocator * ) descr - > ocidescr ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( ! mylob ) {
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
connection = descr - > conn ;
2001-04-14 16:38:46 +08:00
2003-07-22 18:38:34 +08:00
if ( ZEND_NUM_ARGS ( ) < 1 ) WRONG_PARAM_COUNT ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|l " , & var , & lob_type ) = = FAILURE ) {
RETURN_FALSE ;
2002-11-16 01:59:19 +08:00
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobCreateTemporary (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
OCI_DEFAULT ,
OCI_DEFAULT ,
2003-07-22 18:38:34 +08:00
lob_type ,
2002-11-16 01:59:19 +08:00
OCI_ATTR_NOCACHE ,
2002-11-26 02:14:45 +08:00
OCI_DURATION_SESSION ) ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobCreateTemporary " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobOpen (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
OCI_LOB_READWRITE ) ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobOpen " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2003-07-22 18:38:34 +08:00
convert_to_string_ex ( & var ) ;
loblen = Z_STRLEN_P ( var ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( loblen < 1 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot save a lob that is less than 1 byte " ) ;
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobWrite (
connection - > pServiceContext ,
connection - > pError ,
mylob ,
( ub4 * ) & loblen ,
( ub4 ) offset ,
2003-07-22 18:38:34 +08:00
( dvoid * ) Z_STRVAL_P ( var ) ,
2001-08-16 00:00:56 +08:00
( ub4 ) loblen ,
OCI_ONE_PIECE ,
( dvoid * ) 0 ,
( sb4 ( * ) ( dvoid * , dvoid * , ub4 * , ub1 * ) ) 0 ,
( ub2 ) 0 ,
( ub1 ) SQLCS_IMPLICIT ) ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobWrite " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
RETURN_TRUE ;
2001-04-14 16:38:46 +08:00
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_lob_close()
2001-04-14 16:38:46 +08:00
Closes lob descriptor */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_lob_close )
2001-04-14 16:38:46 +08:00
{
zval * id ;
int inx ;
OCILobLocator * mylob ;
oci_connection * connection ;
oci_descriptor * descriptor ;
2002-11-16 01:59:19 +08:00
int is_temporary ;
2001-04-14 16:38:46 +08:00
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 ) {
2002-11-16 01:59:19 +08:00
mylob = ( OCILobLocator * ) descriptor - > ocidescr ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( ! mylob ) {
RETURN_FALSE ;
}
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
connection = descriptor - > conn ;
2001-04-14 16:38:46 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCILobClose (
connection - > pServiceContext ,
connection - > pError ,
mylob ) ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobClose " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
connection - > error =
2002-12-06 21:44:35 +08:00
OCILobIsTemporary ( connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
mylob ,
& is_temporary ) ;
if ( is_temporary ) {
connection - > error =
OCILobFreeTemporary ( connection - > pServiceContext ,
connection - > pError ,
mylob ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCILobFreeTemporary " ,
connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
oci_debug ( " oci_lob_free_temporary: descr=%d " , inx ) ;
}
2001-09-18 04:52:31 +08:00
2001-04-14 16:38:46 +08:00
oci_debug ( " oci_close_lob: descr=%d " , inx ) ;
RETURN_TRUE ;
}
}
2003-12-23 23:45:36 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " oci_lob_close() should not be called like this. Use $somelob->close() to close a LOB " ) ;
2001-04-14 16:38:46 +08:00
2002-11-16 01:59:19 +08:00
RETURN_FALSE ;
2001-04-14 16:38:46 +08:00
}
/* }}} */
# endif
2003-12-23 23:45:36 +08:00
/* {{{ proto object oci_new_descriptor(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_new_descriptor )
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
2002-11-16 01:59:19 +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 ) ;
2001-09-26 05:58:48 +08:00
dtype = Z_LVAL_PP ( type ) ;
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
2003-05-02 16:43:28 +08:00
if ( ! descr ) {
RETURN_NULL ( ) ;
}
2002-11-16 01:59:19 +08:00
object_init_ex ( return_value , oci_lob_class_entry_ptr ) ;
2000-01-16 21:30:57 +08:00
add_property_resource ( return_value , " descriptor " , descr - > id ) ;
1999-04-22 06:49:16 +08:00
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_rollback(resource conn)
2000-02-23 23:54:23 +08:00
Rollback the current context */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_rollback )
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
2002-11-16 01:59:19 +08:00
oci_debug ( " <OCITransRollback " ) ;
2002-02-10 20:41:52 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCITransRollback (
connection - > pServiceContext ,
connection - > pError ,
( ub4 ) 0 ) ) ;
1999-04-25 02:54:02 +08:00
2002-02-10 20:41:52 +08:00
connection - > needs_commit = 0 ;
2002-11-16 01:59:19 +08:00
oci_debug ( " >OCITransRollback " ) ;
2002-02-10 20:41:52 +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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_commit(resource conn)
2000-02-23 23:54:23 +08:00
Commit the current context */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_commit )
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
2002-11-16 01:59:19 +08:00
oci_debug ( " <OCITransCommit " ) ;
2000-01-16 21:30:57 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCITransCommit (
connection - > pServiceContext ,
connection - > pError ,
( ub4 ) 0 ) ) ;
1999-04-22 06:49:16 +08:00
2002-02-10 20:41:52 +08:00
connection - > needs_commit = 0 ;
2002-11-16 01:59:19 +08:00
oci_debug ( " >OCITransCommit " ) ;
2000-01-16 21:30:57 +08:00
1999-05-12 22:28:01 +08:00
if ( connection - > error ) {
1999-08-17 21:54:25 +08:00
oci_error ( connection - > pError , " OCICommit " , connection - > error ) ;
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
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_field_name(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_name )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_field_size(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_size )
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 */
2001-08-16 00:00:56 +08:00
if ( outcol - > data_type = = SQLT_LNG ) {
2000-03-03 09:28:27 +08:00
RETURN_LONG ( outcol - > storage_size4 ) ;
2001-08-16 00:00:56 +08:00
} else {
2000-03-03 09:28:27 +08:00
RETURN_LONG ( outcol - > data_size ) ;
}
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_field_scale(resource stmt, int col)
2000-03-03 09:28:27 +08:00
Tell the scale of a column */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_scale )
2000-03-03 09:28:27 +08:00
{
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
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_field_precision(resource stmt, int col)
2000-03-03 09:28:27 +08:00
Tell the precision of a column */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_precision )
2000-03-03 09:28:27 +08:00
{
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
2003-12-23 23:45:36 +08:00
/* {{{ proto mixed oci_field_type(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_type )
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 ) {
2002-10-17 16:09:31 +08:00
# ifdef SQLT_TIMESTAMP
case SQLT_TIMESTAMP :
RETVAL_STRING ( " TIMESTAMP " , 1 ) ;
break ;
# endif
# ifdef SQLT_TIMESTAMP_TZ
case SQLT_TIMESTAMP_TZ :
RETVAL_STRING ( " TIMESTAMP_TZ " , 1 ) ;
break ;
# endif
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
2003-12-23 23:45:36 +08:00
/* {{{ proto mixed oci_field_type_raw(resource stmt, int col)
2000-03-03 09:28:27 +08:00
Tell the raw oracle data type of a column */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_type_raw )
2000-03-03 09:28:27 +08:00
{
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_field_is_null(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_field_is_null )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto void oci_internal_debug(int onoff)
2000-05-24 06:30:21 +08:00
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 .
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_internal_debug )
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 ) ;
2001-09-26 05:58:48 +08:00
OCI ( debug_mode ) = Z_LVAL_PP ( arg ) ;
1999-04-22 06:49:16 +08:00
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_execute(resource stmt [, int mode])
2000-02-23 23:54:23 +08:00
Execute a parsed statement */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_execute )
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 ) ;
2001-09-26 05:58:48 +08:00
execmode = Z_LVAL_PP ( mode ) ;
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_cancel(resource stmt)
2003-08-12 19:37:40 +08:00
Cancel reading from a cursor */
1999-05-12 22:28:01 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_cancel )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_fetch(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_fetch )
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
2003-06-22 22:33:09 +08:00
/* {{{ proto int ocifetchinto(resource 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
2002-11-16 01:59:19 +08:00
if ( ac < 2 | | ac > 3 | | zend_get_parameters_ex ( ac , & stmt , & array , & fmode ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
1999-09-30 16:41:45 +08:00
2002-11-16 01:59:19 +08:00
switch ( ac ) {
1999-09-30 16:41:45 +08:00
case 3 :
convert_to_long_ex ( fmode ) ;
2001-09-26 05:58:48 +08:00
mode = Z_LVAL_PP ( fmode ) ;
1999-09-30 16:41:45 +08:00
/* 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 ) ;
2003-01-19 03:41:56 +08:00
array_init ( * array ) ;
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 ) ) ) {
2001-09-26 05:58:48 +08:00
zend_hash_index_update ( Z_ARRVAL_PP ( array ) , i , ( void * ) & element , sizeof ( zval * ) , NULL ) ;
2000-01-16 21:30:57 +08:00
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 + + ;
}
2001-09-26 05:58:48 +08:00
zend_hash_update ( Z_ARRVAL_PP ( array ) , 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
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_fetch_all(resource stmt, array &output[, int skip[, int maxrows[, int flags]]])
2000-02-23 23:54:23 +08:00
Fetch all rows of result data into an array */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_fetch_all )
1999-04-22 06:49:16 +08:00
{
2002-01-18 02:40:59 +08:00
zval * * stmt , * * array , * element , * * zskip , * * zmaxrows , * * zflags , * 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 ;
2002-01-18 02:40:59 +08:00
int skip = 0 , maxrows = - 1 ;
int flags = 0 ;
1999-04-22 06:49:16 +08:00
int rows = 0 ;
2000-06-06 03:47:54 +08:00
int ac = ZEND_NUM_ARGS ( ) ;
1999-04-22 06:49:16 +08:00
2002-01-18 02:40:59 +08:00
if ( ac < 2 | | ac > 5 | | zend_get_parameters_ex ( ac , & stmt , & array , & zskip , & zmaxrows , & zflags ) = = FAILURE ) {
1999-04-22 06:49:16 +08:00
WRONG_PARAM_COUNT ;
}
1999-09-30 16:41:45 +08:00
2002-11-16 01:59:19 +08:00
switch ( ac ) {
2002-01-18 02:40:59 +08:00
case 5 :
convert_to_long_ex ( zflags ) ;
flags = Z_LVAL_PP ( zflags ) ;
case 4 :
convert_to_long_ex ( zmaxrows ) ;
maxrows = Z_LVAL_PP ( zmaxrows ) ;
1999-09-30 16:41:45 +08:00
case 3 :
2002-01-18 02:40:59 +08:00
convert_to_long_ex ( zskip ) ;
skip = Z_LVAL_PP ( zskip ) ;
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
2002-01-18 02:40:59 +08:00
while ( skip - - ) {
if ( ! oci_fetch ( statement , nrows , " OCIFetchStatement " TSRMLS_CC ) )
RETURN_LONG ( 0 ) ;
1999-04-22 06:49:16 +08:00
}
2002-01-18 02:40:59 +08:00
if ( flags & OCI_FETCHSTATEMENT_BY_ROW ) {
2003-08-12 08:58:52 +08:00
columns = safe_emalloc ( statement - > ncolumns , sizeof ( oci_out_column * ) , 0 ) ;
2002-01-18 02:40:59 +08:00
1999-04-22 06:49:16 +08:00
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
2002-01-18 02:40:59 +08:00
columns [ i ] = oci_get_col ( statement , i + 1 , 0 ) ;
}
while ( oci_fetch ( statement , nrows , " OCIFetchStatement " TSRMLS_CC ) ) {
zval * row ;
MAKE_STD_ZVAL ( row ) ;
array_init ( row ) ;
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
MAKE_STD_ZVAL ( element ) ;
_oci_make_zval ( element , statement , columns [ i ] , " OCIFetchStatement " , OCI_RETURN_LOBS TSRMLS_CC ) ;
if ( flags & OCI_NUM ) {
zend_hash_next_index_insert ( Z_ARRVAL_P ( row ) , & element , sizeof ( zval * ) , NULL ) ;
} else { /* default to ASSOC */
zend_hash_update ( Z_ARRVAL_P ( row ) ,
columns [ i ] - > name , columns [ i ] - > name_len + 1 ,
& element , sizeof ( zval * ) , NULL ) ;
}
}
zend_hash_next_index_insert ( Z_ARRVAL_PP ( array ) , & row , sizeof ( zval * ) , NULL ) ,
rows + + ;
1999-09-13 19:13:53 +08:00
2002-01-18 02:40:59 +08:00
if ( ( maxrows ! = - 1 ) & & ( rows = = maxrows ) ) {
oci_fetch ( statement , 0 , " OCIFetchStatement " TSRMLS_CC ) ;
break ;
}
}
1999-06-09 18:40:08 +08:00
2002-01-18 02:40:59 +08:00
efree ( columns ) ;
} else { /* default to BY_COLUMN */
2003-08-12 08:58:52 +08:00
columns = safe_emalloc ( statement - > ncolumns , sizeof ( oci_out_column * ) , 0 ) ;
outarrs = safe_emalloc ( statement - > ncolumns , sizeof ( zval * ) , 0 ) ;
2002-01-18 02:40:59 +08:00
if ( flags & OCI_NUM ) {
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
columns [ i ] = oci_get_col ( statement , i + 1 , 0 ) ;
MAKE_STD_ZVAL ( tmp ) ;
array_init ( tmp ) ;
zend_hash_next_index_insert ( Z_ARRVAL_PP ( array ) ,
& tmp , sizeof ( zval * ) , ( void * * ) & ( outarrs [ i ] ) ) ;
}
} else { /* default to ASSOC */
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
columns [ i ] = oci_get_col ( statement , i + 1 , 0 ) ;
MAKE_STD_ZVAL ( tmp ) ;
array_init ( tmp ) ;
zend_hash_update ( Z_ARRVAL_PP ( array ) ,
columns [ i ] - > name , columns [ i ] - > name_len + 1 ,
( void * ) & tmp , sizeof ( zval * ) , ( void * * ) & ( outarrs [ i ] ) ) ;
}
1999-04-22 06:49:16 +08:00
}
2002-01-18 02:40:59 +08:00
while ( oci_fetch ( statement , nrows , " OCIFetchStatement " TSRMLS_CC ) ) {
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
MAKE_STD_ZVAL ( element ) ;
_oci_make_zval ( element , statement , columns [ i ] , " OCIFetchStatement " , OCI_RETURN_LOBS TSRMLS_CC ) ;
zend_hash_index_update ( ( * ( outarrs [ i ] ) ) - > value . ht , rows , ( void * ) & element , sizeof ( zval * ) , NULL ) ;
}
rows + + ;
if ( ( maxrows ! = - 1 ) & & ( rows = = maxrows ) ) {
oci_fetch ( statement , 0 , " OCIFetchStatement " TSRMLS_CC ) ;
break ;
}
}
efree ( columns ) ;
efree ( outarrs ) ;
}
1999-04-22 06:49:16 +08:00
RETURN_LONG ( rows ) ;
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_free_statement(resource stmt)
2000-02-23 23:54:23 +08:00
Free all resources associated with a statement */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_free_statement )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_close(resource conn)
2000-02-23 23:54:23 +08:00
Disconnect from database */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_close )
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
2002-11-16 01:59:19 +08:00
has outstanding transactions . this way we have a nice - clean approach .
( 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
2003-12-23 23:45:36 +08:00
/* {{{ proto resource oci_new_connect(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
2003-06-22 22:33:09 +08:00
/* Connects to an Oracle 8/9 database and logs on. If the
1999-05-12 22:28:01 +08:00
* optional third parameter is not specified , PHP uses the environment
* variable ORACLE_SID to determine which database to connect to .
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_new_connect )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto resource oci_connect(string user, string pass [, string db])
2000-03-15 05:17:07 +08:00
Connect to an Oracle database and log on . Returns a new session .
1999-04-22 06:49:16 +08:00
*/
2003-06-22 22:33:09 +08:00
/* Connects to an Oracle 8/9 database and logs on. If the
1999-04-22 06:49:16 +08:00
* optional third parameter is not specified , PHP uses the environment
* variable ORACLE_SID to determine which database to connect to .
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_connect )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto resource oci_pconnect(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
2003-06-22 22:33:09 +08:00
/* Connects to an Oracle 8/9 database and logs on. If the
1999-04-22 06:49:16 +08:00
* optional third parameter is not specified , PHP uses the environment
* variable ORACLE_SID to determine which database to connect to .
*/
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_pconnect )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto array oci_error([resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_error )
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 ;
2002-03-19 05:01:29 +08:00
text errbuf [ 512 ] ;
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 ;
2002-08-20 15:26:50 +08:00
# ifdef HAVE_OCI8_ATTR_STATEMENT
2002-03-19 05:01:29 +08:00
ub2 errorofs = 0 ;
text * sqltext = NULL ;
2002-08-20 15:26:50 +08:00
# endif
1999-04-22 06:49:16 +08:00
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 ;
2002-03-19 05:01:29 +08:00
2002-08-20 15:26:50 +08:00
# ifdef HAVE_OCI8_ATTR_STATEMENT
2002-03-19 05:01:29 +08:00
CALL_OCI_RETURN ( statement - > error , OCIAttrGet (
( dvoid * ) statement - > pStmt ,
OCI_HTYPE_STMT ,
( text * ) & sqltext ,
( ub4 * ) 0 ,
OCI_ATTR_STATEMENT ,
statement - > pError ) ) ;
CALL_OCI_RETURN ( statement - > error , OCIAttrGet (
( dvoid * ) statement - > pStmt ,
OCI_HTYPE_STMT ,
( ub2 * ) & errorofs ,
( ub4 * ) 0 ,
OCI_ATTR_PARSE_ERROR_OFFSET ,
statement - > pError ) ) ;
2002-08-20 15:26:50 +08:00
# endif
2002-03-19 05:01:29 +08:00
1999-05-12 22:28:01 +08:00
} 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 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OCIError: unable to find Error handle " ) ;
1999-04-22 06:49:16 +08:00
RETURN_FALSE ;
}
2001-08-16 00:00:56 +08:00
CALL_OCI ( OCIErrorGet (
errh ,
1 ,
NULL ,
& errcode ,
errbuf ,
( ub4 ) sizeof ( errbuf ) ,
( ub4 ) OCI_HTYPE_ERROR ) ) ;
1999-04-22 06:49:16 +08:00
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 ) ;
2002-08-20 15:26:50 +08:00
# ifdef HAVE_OCI8_ATTR_STATEMENT
2002-03-19 05:01:29 +08:00
add_assoc_long ( return_value , " offset " , errorofs ) ;
add_assoc_string ( return_value , " sqltext " , sqltext ? ( char * ) sqltext : " " , 1 ) ;
2002-08-20 15:26:50 +08:00
# endif
1999-04-22 06:49:16 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2000-03-15 05:17:07 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_num_fields(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_num_fields )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto resource oci_parse(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_parse )
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 ) ;
2001-09-26 05:58:48 +08:00
statement = oci_parse ( connection , Z_STRVAL_PP ( query ) , Z_STRLEN_PP ( query ) ) ;
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_set_prefetch(resource stmt, int prefetch_rows)
2001-07-14 20:45:42 +08:00
sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
1999-07-08 22:12:07 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_set_prefetch )
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
2001-09-26 05:58:48 +08:00
oci_setprefetch ( statement , Z_LVAL_PP ( size ) ) ;
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_password_change(resource conn, string username, string old_password, string new_password)
2003-06-22 22:33:09 +08:00
Changes the password of an account */
2002-11-15 05:26:57 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_password_change )
2002-11-15 05:26:57 +08:00
{
zval * * conn , * * user_param , * * pass_old_param , * * pass_new_param ;
text * user , * pass_old , * pass_new ;
oci_connection * connection ;
2002-11-22 04:32:56 +08:00
/* Disable in Safe Mode */
2002-11-22 04:28:11 +08:00
if ( PG ( safe_mode ) ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " is disabled in Safe Mode " ) ;
2002-11-22 04:28:11 +08:00
RETURN_FALSE ;
}
2002-11-15 05:26:57 +08:00
if ( zend_get_parameters_ex ( 4 , & conn , & user_param , & pass_old_param , & pass_new_param ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
user = Z_STRVAL_PP ( user_param ) ;
pass_old = Z_STRVAL_PP ( pass_old_param ) ;
pass_new = Z_STRVAL_PP ( pass_new_param ) ;
OCI_GET_CONN ( connection , conn ) ;
CALL_OCI_RETURN (
connection - > error
, OCIPasswordChange (
connection - > pServiceContext
, connection - > pError
, user
, strlen ( user ) + 1
, pass_old
, strlen ( pass_old ) + 1
, pass_new
, strlen ( pass_new ) + 1
, OCI_DEFAULT
)
) ;
if ( connection - > error = = OCI_SUCCESS ) {
RETURN_TRUE ;
}
else {
oci_error ( connection - > pError , " OCIPasswordChange " , connection - > error ) ;
oci_handle_error ( connection , connection - > error ) ;
RETURN_FALSE ;
}
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto resource oci_new_cursor(resource conn)
2000-02-23 23:54:23 +08:00
Return a new cursor ( Statement - Handle ) - use this to bind ref - cursors ! */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_new_cursor )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_result(resource 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
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_result )
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
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_server_version(resource conn)
2000-02-23 23:54:23 +08:00
Return a string containing server version information */
1999-04-22 06:49:16 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_server_version )
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 ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIServerVersion (
connection - > pServiceContext ,
connection - > pError ,
( text * ) version ,
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
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_statement_type(resource 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() */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_statement_type )
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
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( statement - > error , 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 ! = 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
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_num_rows(resource stmt)
2000-03-15 05:17:07 +08:00
Return the row count of an OCI statement */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_num_rows )
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
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( 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 ) ;
}
/* }}} */
2003-12-16 23:58:10 +08:00
# ifdef PHP_OCI8_HAVE_COLLECTIONS
2001-04-13 22:43:39 +08:00
/* {{{ 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
{
2002-11-16 01:59:19 +08:00
oci_collection * collection ;
int actual_resource_type ;
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
collection = ( oci_collection * ) zend_list_find ( ind , & actual_resource_type ) ;
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
if ( collection & & ( actual_resource_type = = le_coll ) ) {
return collection ;
} else {
return ( oci_collection * ) NULL ;
}
2001-04-13 22:43:39 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
2001-04-13 22:43:39 +08:00
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_free_collection()
2001-04-26 01:48:30 +08:00
Deletes collection object */
2001-04-13 22:43:39 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_free_collection )
2001-04-13 22:43:39 +08:00
{
2002-11-16 01:59:19 +08:00
zval * id ;
int inx ;
oci_collection * coll ;
oci_connection * connection ;
2001-05-31 01:43:32 +08:00
2002-11-16 01:59:19 +08:00
if ( ( id = getThis ( ) ) ! = 0 ) {
inx = _oci_get_ocicoll ( id , & coll TSRMLS_CC ) ;
if ( inx ) {
2001-04-13 22:43:39 +08:00
/*
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 ;
2002-11-16 01:59:19 +08:00
oci_debug ( " OCIfreecollection: coll=%d " , inx ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIObjectFree (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
connection - > pError ,
( dvoid * ) coll - > coll ,
( ub2 ) ( OCI_OBJECTFREE_FORCE ) ) ) ;
2001-05-23 07:16:03 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIObjectFree " , connection - > error ) ;
RETURN_FALSE ;
}
2002-11-16 01:59:19 +08:00
zend_list_delete ( inx ) ;
RETURN_TRUE ;
}
}
2001-04-13 22:43:39 +08:00
2001-04-26 01:48:30 +08:00
RETURN_FALSE ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_collection_append(string value)
2001-04-13 22:43:39 +08:00
Append an object to the collection */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_append )
2001-04-13 22:43:39 +08:00
{
2002-11-16 01:59:19 +08:00
zval * id , * * arg ;
oci_connection * connection ;
oci_collection * coll ;
OCINumber num ;
2001-04-13 22:43:39 +08:00
OCIString * ocistr = ( OCIString * ) 0 ;
OCIInd new_ind = OCI_IND_NOTNULL ;
2001-09-12 05:03:58 +08:00
OCIInd null_ind = OCI_IND_NULL ;
2001-04-13 22:43:39 +08:00
OCIDate dt ;
2002-11-16 01:59:19 +08:00
int inx ;
2001-04-13 22:43:39 +08:00
double ndx ;
2001-04-26 01:48:30 +08:00
2002-11-16 01:59:19 +08:00
if ( ( id = getThis ( ) ) ! = 0 ) {
if ( ( inx = _oci_get_ocicoll ( id , & coll TSRMLS_CC ) ) = = 0 ) {
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
connection = coll - > conn ;
if ( zend_get_parameters_ex ( 1 , & arg ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
2001-04-13 22:43:39 +08:00
2001-09-12 05:03:58 +08:00
/*
* Handle NULLS . For consistency with the rest of the OCI8 library , when
* a value passed in is a 0 length string , consider it a null
*/
convert_to_string_ex ( arg ) ;
2001-09-26 05:58:48 +08:00
if ( Z_STRLEN_PP ( arg ) = = 0 ) {
2001-09-12 05:03:58 +08:00
CALL_OCI_RETURN ( connection - > error , OCICollAppend (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-09-12 05:03:58 +08:00
connection - > pError ,
( dword * ) 0 ,
& null_ind ,
coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAppend - NULL " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
2001-04-13 22:43:39 +08:00
switch ( coll - > element_typecode ) {
2002-11-16 01:59:19 +08:00
case OCI_TYPECODE_DATE :
convert_to_string_ex ( arg ) ;
CALL_OCI_RETURN ( connection - > error , OCIDateFromText (
connection - > pError ,
Z_STRVAL_PP ( arg ) ,
Z_STRLEN_PP ( arg ) ,
0 ,
0 ,
0 ,
0 ,
& dt ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIDateFromText " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAppend (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
( dvoid * ) & dt ,
( dvoid * ) & new_ind ,
( OCIColl * ) coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAppend " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
break ;
case OCI_TYPECODE_VARCHAR2 :
convert_to_string_ex ( arg ) ;
CALL_OCI_RETURN ( connection - > error , OCIStringAssignText (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
Z_STRVAL_PP ( arg ) ,
Z_STRLEN_PP ( arg ) ,
& ocistr ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIStringAssignText " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAppend (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
( dvoid * ) ocistr ,
( dvoid * ) & new_ind ,
( OCIColl * ) coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAppend " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
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 ) Z_DVAL_PP ( arg ) ;
CALL_OCI_RETURN ( connection - > error , OCINumberFromReal (
connection - > pError ,
& ndx ,
sizeof ( double ) , & num ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCINumberFromReal " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAppend (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
( dvoid * ) & num ,
( dvoid * ) & new_ind ,
( OCIColl * ) coll - > coll ) ) ;
RETURN_TRUE ;
break ;
2001-04-13 22:43:39 +08:00
}
}
2001-04-26 01:48:30 +08:00
RETURN_FALSE ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto string oci_collection_element_get(int ndx)
2001-04-13 22:43:39 +08:00
Retrieve the value at collection index ndx */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_element_get )
2001-04-13 22:43:39 +08:00
{
2002-11-16 01:59:19 +08:00
zval * id , * * arg ;
2001-04-26 01:48:30 +08:00
oci_connection * connection ;
oci_collection * coll ;
ub4 ndx ;
int inx ;
dvoid * elem ;
2001-09-20 03:25:43 +08:00
OCIInd * elemind ;
2001-04-26 01:48:30 +08:00
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-09-26 05:58:48 +08:00
ndx = Z_LVAL_PP ( arg ) ;
2001-04-13 22:43:39 +08:00
2001-04-26 01:48:30 +08:00
connection = coll - > conn ;
2001-04-13 22:43:39 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCICollGetElem (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
connection - > pError ,
coll - > coll ,
ndx ,
& exists ,
& elem ,
2001-09-17 05:53:58 +08:00
( dvoid * * ) & elemind ) ) ;
2001-08-16 00:00:56 +08:00
2001-04-13 22:43:39 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollGetElem " , connection - > error ) ;
2001-09-17 05:53:58 +08:00
RETURN_NULL ( ) ;
2001-04-13 22:43:39 +08:00
}
2001-09-12 07:15:18 +08:00
2001-09-12 07:16:32 +08:00
/* Return false if value does not exist at that location */
2001-09-12 07:15:18 +08:00
if ( exists = = 0 ) {
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OCICollGetElem - Invalid index %d " , ndx ) ;
2001-09-12 07:15:18 +08:00
RETURN_FALSE ;
}
2001-08-16 00:00:56 +08:00
2001-09-17 05:53:58 +08:00
/* Return null if the value is null */
2001-09-20 03:25:43 +08:00
if ( * elemind = = OCI_IND_NULL ) {
2001-09-17 05:53:58 +08:00
RETURN_FALSE ;
}
2001-08-16 00:00:56 +08:00
switch ( coll - > element_typecode ) {
2002-11-16 01:59:19 +08:00
case OCI_TYPECODE_DATE :
len = 1024 ;
CALL_OCI ( 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 ;
2002-12-06 21:44:35 +08:00
str = OCIStringPtr ( connection - > session - > pEnv , ocistr ) ; /* XXX not protected against recursion! */
2002-11-16 01:59:19 +08:00
RETURN_STRINGL ( str , strlen ( str ) , 1 ) ;
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 */
CALL_OCI_RETURN ( connection - > error , OCINumberToReal (
connection - > pError ,
( CONST OCINumber * ) elem ,
( uword ) sizeof ( dnum ) ,
( dvoid * ) & dnum ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCINumberToReal " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_DOUBLE ( dnum ) ;
break ;
2001-04-13 22:43:39 +08:00
}
}
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
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_collection_assign(object from)
2001-04-13 22:43:39 +08:00
Assign a collection from another existing collection */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_assign )
2001-04-13 22:43:39 +08:00
{
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-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCICollAssign (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
connection - > pError ,
from_coll - > coll ,
coll - > coll ) ) ;
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
}
RETURN_TRUE ;
}
2001-04-26 01:48:30 +08:00
RETURN_FALSE ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_collection_element_assign(int index, string val)
2001-04-13 22:43:39 +08:00
Assign element val to collection at index ndx */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_element_assign )
2001-04-13 22:43:39 +08:00
{
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-09-12 05:03:58 +08:00
OCIInd null_ind = OCI_IND_NULL ;
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-09-26 05:58:48 +08:00
ndx = Z_LVAL_PP ( index ) ;
2001-04-13 22:43:39 +08:00
2001-04-26 01:48:30 +08:00
connection = coll - > conn ;
2002-11-16 02:20:59 +08:00
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
}
2001-09-12 05:03:58 +08:00
/*
2003-06-22 22:33:09 +08:00
* Handle NULLs . For consistency with the rest of the OCI8 library , when
2001-09-12 05:03:58 +08:00
* a value passed in is a 0 length string , consider it a null
*/
convert_to_string_ex ( val ) ;
2001-09-26 05:58:48 +08:00
if ( Z_STRLEN_PP ( val ) = = 0 ) {
2001-09-12 05:03:58 +08:00
CALL_OCI_RETURN ( connection - > error , OCICollAssignElem (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-09-12 05:03:58 +08:00
connection - > pError ,
ndx ,
( dword * ) 0 ,
& null_ind ,
coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAssignElem - NULL " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
2001-04-13 22:43:39 +08:00
switch ( coll - > element_typecode ) {
2002-11-16 01:59:19 +08:00
case OCI_TYPECODE_DATE :
convert_to_string_ex ( val ) ;
CALL_OCI_RETURN ( connection - > error , OCIDateFromText (
connection - > pError ,
Z_STRVAL_PP ( val ) ,
Z_STRLEN_PP ( val ) ,
0 ,
0 ,
0 ,
0 ,
& dt ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIDateFromText " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAssignElem (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
ndx ,
( dword * ) & dt ,
& new_ind ,
coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAssignElem " , connection - > error ) ;
RETURN_FALSE ;
}
break ;
case OCI_TYPECODE_VARCHAR2 :
convert_to_string_ex ( val ) ;
CALL_OCI_RETURN ( connection - > error , OCIStringAssignText (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
Z_STRVAL_PP ( val ) ,
Z_STRLEN_PP ( val ) ,
& ocistr ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIStringAssignText " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAssignElem (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
ndx ,
( dword * ) ocistr ,
& new_ind ,
coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAssignElem " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
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 ( val ) ;
dnum = ( double ) Z_DVAL_PP ( val ) ;
CALL_OCI_RETURN ( connection - > error , OCINumberFromReal (
connection - > pError ,
& dnum ,
sizeof ( double ) ,
& num ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCINumberFromReal " , connection - > error ) ;
RETURN_FALSE ;
}
CALL_OCI_RETURN ( connection - > error , OCICollAssignElem (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
connection - > pError ,
ndx ,
( dword * ) & num ,
& new_ind ,
coll - > coll ) ) ;
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollAssignElem " , connection - > error ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
break ;
2001-04-13 22:43:39 +08:00
}
}
2001-04-26 01:48:30 +08:00
RETURN_FALSE ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_collection_size()
2001-04-13 22:43:39 +08:00
Return the size of a collection */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_size )
2001-04-13 22:43:39 +08:00
{
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 ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCICollSize (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
coll - > conn - > pError ,
coll - > coll ,
& sz ) ) ;
2001-04-26 01:48:30 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCICollSize " , connection - > error ) ;
RETURN_FALSE ;
}
2002-11-10 13:31:12 +08:00
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
2003-12-23 23:45:36 +08:00
/* {{{ proto int oci_collection_max()
2002-08-13 13:00:11 +08:00
Return the max value of a collection . For a varray this is the maximum length of the array */
2001-04-13 22:43:39 +08:00
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_max )
2001-04-13 22:43:39 +08:00
{
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-08-16 00:00:56 +08:00
sz = OCICollMax ( OCI ( pEnv ) , coll - > coll ) ; /* XXX not protected against recursion */
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
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto bool oci_collection_trim(int num)
2001-04-13 22:43:39 +08:00
Trim num elements from the end of a collection */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_collection_trim )
2001-04-13 22:43:39 +08:00
{
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-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( coll - > conn - > error , OCICollTrim (
OCI ( pEnv ) ,
coll - > conn - > pError ,
2001-09-26 05:58:48 +08:00
Z_LVAL_PP ( arg ) ,
2001-08-16 00:00:56 +08:00
coll - > coll ) ) ;
2001-04-13 22:43:39 +08:00
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
}
/* }}} */
2003-12-23 23:45:36 +08:00
/* {{{ proto object oci_new_collection(resource connection, string tdo [, string schema])
2001-04-13 22:43:39 +08:00
Initialize a new collection */
2003-12-23 23:45:36 +08:00
PHP_FUNCTION ( oci_new_collection )
2001-04-13 22:43:39 +08:00
{
2002-11-16 01:59:19 +08:00
dvoid * dschp1 ;
dvoid * parmp1 ;
dvoid * parmp2 ;
zval * * conn , * * tdo , * * schema ;
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
2002-11-16 01:59:19 +08:00
if ( ac < 2 | | ac > 3 | | zend_get_parameters_ex ( ac , & conn , & tdo , & schema ) = = FAILURE ) {
WRONG_PARAM_COUNT ;
}
2001-05-23 07:16:03 +08:00
2002-11-16 01:59:19 +08:00
convert_to_string_ex ( tdo ) ;
2001-04-13 22:43:39 +08:00
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 ) ;
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCITypeByName (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
connection - > pError ,
connection - > pServiceContext ,
2001-09-26 05:58:48 +08:00
ac = = 3 ? ( text * ) Z_STRVAL_PP ( schema ) : ( text * ) 0 ,
ac = = 3 ? ( ub4 ) Z_STRLEN_PP ( schema ) : ( ub4 ) 0 ,
( text * ) Z_STRVAL_PP ( tdo ) ,
( ub4 ) Z_STRLEN_PP ( tdo ) ,
2001-08-16 00:00:56 +08:00
( CONST text * ) 0 ,
( ub4 ) 0 ,
OCI_DURATION_SESSION ,
OCI_TYPEGET_ALL ,
& ( coll - > tdo ) ) ) ;
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCITypeByName " , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIHandleAlloc (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
( dvoid * * ) & dschp1 ,
( ub4 ) OCI_HTYPE_DESCRIBE ,
( size_t ) 0 ,
( dvoid * * ) 0 ) ) ;
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCI_HTYPE_DESCRIBE " , connection - > error ) ;
RETURN_FALSE ;
}
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIDescribeAny (
connection - > pServiceContext ,
connection - > pError ,
( dvoid * ) coll - > tdo ,
( ub4 ) 0 ,
OCI_OTYPE_PTR ,
( ub1 ) 1 ,
( ub1 ) OCI_PTYPE_TYPE ,
dschp1 ) ) ;
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCI_OTYPE_PTR " , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIAttrGet (
( dvoid * ) dschp1 ,
( ub4 ) OCI_HTYPE_DESCRIBE ,
( dvoid * ) & parmp1 ,
( ub4 * ) 0 ,
( ub4 ) OCI_ATTR_PARAM ,
connection - > pError ) ) ;
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCI_ATTR_PARAM " , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2001-04-26 01:48:30 +08:00
/* get the collection type code of the attribute */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIAttrGet (
( dvoid * ) parmp1 ,
( ub4 ) OCI_DTYPE_PARAM ,
( dvoid * ) & ( coll - > coll_typecode ) ,
( ub4 * ) 0 ,
( ub4 ) OCI_ATTR_COLLECTION_TYPECODE ,
connection - > pError ) ) ;
2002-11-16 01:59:19 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCI_ATTR_COLLECTION_TYPECODE " , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2001-04-26 01:48:30 +08:00
switch ( coll - > coll_typecode ) {
2002-11-16 01:59:19 +08:00
case OCI_TYPECODE_TABLE :
case OCI_TYPECODE_VARRAY :
CALL_OCI_RETURN ( 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 ;
}
CALL_OCI_RETURN ( 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 ;
}
CALL_OCI_RETURN ( connection - > error , OCITypeByRef (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2002-11-16 01:59:19 +08:00
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 ;
}
CALL_OCI_RETURN ( 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 :
2003-01-19 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OCINewCollection - Unknown Type %d " , coll - > coll_typecode ) ;
2002-11-16 01:59:19 +08:00
break ;
}
2001-04-26 01:48:30 +08:00
/* Create object to hold return table */
2001-08-16 00:00:56 +08:00
CALL_OCI_RETURN ( connection - > error , OCIObjectNew (
2002-12-06 21:44:35 +08:00
connection - > session - > pEnv ,
2001-08-16 00:00:56 +08:00
connection - > pError ,
connection - > pServiceContext ,
OCI_TYPECODE_TABLE ,
coll - > tdo ,
( dvoid * ) 0 ,
OCI_DURATION_DEFAULT ,
TRUE ,
( dvoid * * ) & ( coll - > coll ) ) ) ;
2001-04-26 01:48:30 +08:00
if ( connection - > error ) {
oci_error ( connection - > pError , " OCIObjectNew " , connection - > error ) ;
RETURN_FALSE ;
}
2001-04-13 22:43:39 +08:00
2002-11-16 01:59:19 +08:00
object_init_ex ( return_value , oci_coll_class_entry_ptr ) ;
add_property_resource ( return_value , " collection " , coll - > id ) ;
2001-04-13 22:43:39 +08:00
}
/* }}} */
# endif
1999-04-22 06:49:16 +08:00
# endif /* HAVE_OCI8 */
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 21:29:31 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-22 06:49:16 +08:00
*/