#if HAVE_OCI8
# ifndef PHP_OCI8_INT_H
# define PHP_OCI8_INT_H
# if (defined(__osf__) && defined(__alpha))
# ifndef A_OSF
# define A_OSF
# endif
# ifndef OSF1
# define OSF1
# endif
# ifndef _INTRINSICS
# define _INTRINSICS
# endif
# endif
#ifdef HAVE_OCI8_DTRACE
#include "oci8_dtrace_gen.h"
#endif
#if defined(min)
#undef min
#endif
#if defined(max)
#undef max
#endif
#include "ext/standard/php_string.h"
#include <oci.h>
extern int le_connection;
extern int le_pconnection;
extern int le_statement;
extern int le_descriptor;
extern int le_collection;
extern int le_server;
extern int le_session;
extern zend_class_entry *oci_lob_class_entry_ptr;
extern zend_class_entry *oci_coll_class_entry_ptr;
#define PHP_OCI_SEEK_SET 0
#define PHP_OCI_SEEK_CUR 1
#define PHP_OCI_SEEK_END 2
#define PHP_OCI_MAX_NAME_LEN 64
#define PHP_OCI_MAX_DATA_SIZE INT_MAX
#define PHP_OCI_PIECE_SIZE ((64*1024)-1)
#define PHP_OCI_LOB_BUFFER_SIZE 1048576l
#define PHP_OCI_ASSOC (1<<0)
#define PHP_OCI_NUM (1<<1)
#define PHP_OCI_BOTH (PHP_OCI_ASSOC|PHP_OCI_NUM)
#define PHP_OCI_RETURN_NULLS (1<<2)
#define PHP_OCI_RETURN_LOBS (1<<3)
#define PHP_OCI_FETCHSTATEMENT_BY_COLUMN (1<<4)
#define PHP_OCI_FETCHSTATEMENT_BY_ROW (1<<5)
#define PHP_OCI_FETCHSTATEMENT_BY (PHP_OCI_FETCHSTATEMENT_BY_COLUMN | PHP_OCI_FETCHSTATEMENT_BY_ROW)
#define PHP_OCI_LOB_BUFFER_DISABLED 0
#define PHP_OCI_LOB_BUFFER_ENABLED 1
#define PHP_OCI_LOB_BUFFER_USED 2
#define PHP_OCI_CRED_EXT (1<<31)
#if ((PHP_OCI_CRED_EXT == OCI_DEFAULT) || (PHP_OCI_CRED_EXT & (OCI_SYSOPER | OCI_SYSDBA)))
#error Invalid value for PHP_OCI_CRED_EXT
#endif
#define PHP_OCI_IMPRES_UNKNOWN 0
#define PHP_OCI_IMPRES_NO_CHILDREN 1
#define PHP_OCI_IMPRES_HAS_CHILDREN 2
#define PHP_OCI_IMPRES_IS_CHILD 3
#define PHP_OCI8_DRIVER_NAME "PHP OCI8 " PHP_OCI8_VERSION
typedef struct {
int id;
OCIEnv *env;
OCIError *err;
OCISPool *poolh;
void *poolname;
unsigned int poolname_len;
char *spool_hash_key;
} php_oci_spool;
typedef struct {
int id;
OCIEnv *env;
ub2 charset;
OCIServer *server;
OCISvcCtx *svc;
OCISession *session;
OCIAuthInfo *authinfo;
OCIError *err;
php_oci_spool *private_spool;
sb4 errcode;
HashTable *descriptors;
ulong descriptor_count;
unsigned is_open:1;
unsigned is_attached:1;
unsigned is_persistent:1;
unsigned used_this_request:1;
unsigned rb_on_disconnect:1;
unsigned passwd_changed:1;
unsigned is_stub:1;
unsigned using_spool:1;
time_t idle_expiry;
time_t *next_pingp;
char *hash_key;
#ifdef HAVE_OCI8_DTRACE
char *client_id;
#endif
} php_oci_connection;
typedef struct {
int id;
ulong index;
php_oci_connection *connection;
dvoid *descriptor;
ub4 type;
int lob_current_position;
int lob_size;
int buffering;
ub4 chunk_size;
ub1 charset_form;
ub2 charset_id;
unsigned is_open:1;
} php_oci_descriptor;
typedef struct {
char **lob_data;
ub4 *lob_len;
ub4 alloc_len;
} php_oci_lob_ctx;
typedef struct {
int id;
php_oci_connection *connection;
OCIType *tdo;
OCITypeCode coll_typecode;
OCIRef *elem_ref;
OCIType *element_type;
OCITypeCode element_typecode;
OCIColl *collection;
} php_oci_collection;
typedef struct {
zval *zval;
text *name;
ub4 name_len;
ub4 type;
} php_oci_define;
typedef struct {
int id;
int parent_stmtid;
struct php_oci_statement *impres_child_stmt;
ub4 impres_count;
php_oci_connection *connection;
sb4 errcode;
OCIError *err;
OCIStmt *stmt;
char *last_query;
char impres_flag;
long last_query_len;
HashTable *columns;
HashTable *binds;
HashTable *defines;
int ncolumns;
unsigned executed:1;
unsigned has_data:1;
unsigned has_descr:1;
ub2 stmttype;
ub4 prefetch_count;
} php_oci_statement;
typedef struct {
OCIBind *bind;
zval *zval;
dvoid *descriptor;
OCIStmt *statement;
php_oci_statement *parent_statement;
ub2 type;
struct {
void *elements;
sb2 *indicators;
ub2 *element_lengths;
ub4 current_length;
ub4 old_length;
ub4 max_length;
long type;
} array;
sb2 indicator;
ub2 retcode;
ub4 dummy_len;
} php_oci_bind;
typedef struct {
php_oci_statement *statement;
php_oci_statement *nested_statement;
OCIDefine *oci_define;
char *name;
ub4 name_len;
ub2 data_type;
ub2 data_size;
ub4 storage_size4;
sb2 indicator;
ub2 retcode;
ub2 retlen;
ub4 retlen4;
ub2 is_descr;
ub2 is_cursor;
int stmtid;
int descid;
void *data;
php_oci_define *define;
int piecewise;
ub4 cb_retlen;
sb1 scale;
sb2 precision;
ub1 charset_form;
ub2 charset_id;
ub4 chunk_size;
} php_oci_out_column;
#define PHP_OCI_CALL(func, params) \
do { \
OCI_G(in_call) = 1; \
func params; \
OCI_G(in_call) = 0; \
} while (0)
#define PHP_OCI_CALL_RETURN(__retval, func, params) \
do { \
OCI_G(in_call) = 1; \
__retval = func params; \
OCI_G(in_call) = 0; \
} while (0)
#define PHP_OCI_HANDLE_ERROR(connection, errcode) \
do { \
ub4 serverStatus = OCI_SERVER_NORMAL; \
switch (errcode) { \
case 1013: \
zend_bailout(); \
break; \
case 22: \
case 28: \
case 378: \
case 602: \
case 603: \
case 604: \
case 609: \
case 1012: \
case 1033: \
case 1041: \
case 1043: \
case 1089: \
case 1090: \
case 1092: \
case 3113: \
case 3114: \
case 3122: \
case 3135: \
case 12153: \
case 27146: \
case 28511: \
(connection)->is_open = 0; \
break; \
default: \
{ \
PHP_OCI_CALL(OCIAttrGet, ((dvoid *)(connection)->server, OCI_HTYPE_SERVER, (dvoid *)&serverStatus, \
(ub4 *)0, OCI_ATTR_SERVER_STATUS, (connection)->err)); \
if (serverStatus != OCI_SERVER_NORMAL) { \
(connection)->is_open = 0; \
} \
} \
break; \
} \
php_oci_dtrace_check_connection(connection, errcode, serverStatus); \
} while (0)
#define PHP_OCI_REGISTER_RESOURCE(resource, le_resource) \
do { \
resource->id = ZEND_REGISTER_RESOURCE(NULL, resource, le_resource); \
} while (0)
#define PHP_OCI_ZVAL_TO_CONNECTION(zval, connection) \
ZEND_FETCH_RESOURCE2(connection, php_oci_connection *, &zval, -1, "oci8 connection", le_connection, le_pconnection)
#define PHP_OCI_ZVAL_TO_STATEMENT(zval, statement) \
ZEND_FETCH_RESOURCE(statement, php_oci_statement *, &zval, -1, "oci8 statement", le_statement)
#define PHP_OCI_ZVAL_TO_DESCRIPTOR(zval, descriptor) \
ZEND_FETCH_RESOURCE(descriptor, php_oci_descriptor *, &zval, -1, "oci8 descriptor", le_descriptor)
#define PHP_OCI_ZVAL_TO_COLLECTION(zval, collection) \
ZEND_FETCH_RESOURCE(collection, php_oci_collection *, &zval, -1, "oci8 collection", le_collection)
#define PHP_OCI_FETCH_RESOURCE_EX(zval, var, type, name, resource_type) \
do { \
var = (type) zend_fetch_resource(&zval TSRMLS_CC, -1, name, NULL, 1, resource_type); \
if (!var) { \
return 1; \
} \
} while (0)
#define PHP_OCI_ZVAL_TO_CONNECTION_EX(zval, connection) \
PHP_OCI_FETCH_RESOURCE_EX(zval, connection, php_oci_connection *, "oci8 connection", le_connection)
#define PHP_OCI_ZVAL_TO_STATEMENT_EX(zval, statement) \
PHP_OCI_FETCH_RESOURCE_EX(zval, statement, php_oci_statement *, "oci8 statement", le_statement)
#define PHP_OCI_ZVAL_TO_DESCRIPTOR_EX(zval, descriptor) \
PHP_OCI_FETCH_RESOURCE_EX(zval, descriptor, php_oci_descriptor *, "oci8 descriptor", le_descriptor)
#define PHP_OCI_ZVAL_TO_COLLECTION_EX(zval, collection) \
PHP_OCI_FETCH_RESOURCE_EX(zval, collection, php_oci_collection *, "oci8 collection", le_collection)
void php_oci_column_hash_dtor(void *data);
void php_oci_define_hash_dtor(void *data);
void php_oci_bind_hash_dtor(void *data);
void php_oci_descriptor_flush_hash_dtor(void *data);
void php_oci_connection_descriptors_free(php_oci_connection *connection TSRMLS_DC);
sb4 php_oci_error(OCIError *err_p, sword status TSRMLS_DC);
sb4 php_oci_fetch_errmsg(OCIError *error_handle, text **error_buf TSRMLS_DC);
int php_oci_fetch_sqltext_offset(php_oci_statement *statement, text **sqltext, ub2 *error_offset TSRMLS_DC);
void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclusive);
php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char *password, int password_len, char *new_password, int new_password_len, char *dbname, int dbname_len, char *charset, long session_mode, int persistent, int exclusive TSRMLS_DC);
int php_oci_connection_rollback(php_oci_connection *connection TSRMLS_DC);
int php_oci_connection_commit(php_oci_connection *connection TSRMLS_DC);
int php_oci_connection_release(php_oci_connection *connection TSRMLS_DC);
int php_oci_password_change(php_oci_connection *connection, char *user, int user_len, char *pass_old, int pass_old_len, char *pass_new, int pass_new_len TSRMLS_DC);
void php_oci_client_get_version(char **version TSRMLS_DC);
int php_oci_server_get_version(php_oci_connection *connection, char **version TSRMLS_DC);
void php_oci_fetch_row(INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_args);
int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode TSRMLS_DC);
void php_oci_dtrace_check_connection(php_oci_connection *connection, sb4 errcode, ub4 serverStatus);
php_oci_descriptor *php_oci_lob_create(php_oci_connection *connection, long type TSRMLS_DC);
int php_oci_lob_get_length(php_oci_descriptor *descriptor, ub4 *length TSRMLS_DC);
int php_oci_lob_read(php_oci_descriptor *descriptor, long read_length, long inital_offset, char **data, ub4 *data_len TSRMLS_DC);
int php_oci_lob_write(php_oci_descriptor *descriptor, ub4 offset, char *data, int data_len, ub4 *bytes_written TSRMLS_DC);
int php_oci_lob_flush(php_oci_descriptor *descriptor, long flush_flag TSRMLS_DC);
int php_oci_lob_set_buffering(php_oci_descriptor *descriptor, int on_off TSRMLS_DC);
int php_oci_lob_get_buffering(php_oci_descriptor *descriptor);
int php_oci_lob_copy(php_oci_descriptor *descriptor, php_oci_descriptor *descriptor_from, long length TSRMLS_DC);
int php_oci_lob_close(php_oci_descriptor *descriptor TSRMLS_DC);
int php_oci_temp_lob_close(php_oci_descriptor *descriptor TSRMLS_DC);
int php_oci_lob_write_tmp(php_oci_descriptor *descriptor, long type, char *data, int data_len TSRMLS_DC);
void php_oci_lob_free(php_oci_descriptor *descriptor TSRMLS_DC);
int php_oci_lob_import(php_oci_descriptor *descriptor, char *filename TSRMLS_DC);
int php_oci_lob_append(php_oci_descriptor *descriptor_dest, php_oci_descriptor *descriptor_from TSRMLS_DC);
int php_oci_lob_truncate(php_oci_descriptor *descriptor, long new_lob_length TSRMLS_DC);
int php_oci_lob_erase(php_oci_descriptor *descriptor, long offset, ub4 length, ub4 *bytes_erased TSRMLS_DC);
int php_oci_lob_is_equal(php_oci_descriptor *descriptor_first, php_oci_descriptor *descriptor_second, boolean *result TSRMLS_DC);
sb4 php_oci_lob_callback(dvoid *ctxp, CONST dvoid *bufxp, oraub8 len, ub1 piece, dvoid **changed_bufpp, oraub8 *changed_lenp);
php_oci_collection *php_oci_collection_create(php_oci_connection *connection, char *tdo, int tdo_len, char *schema, int schema_len TSRMLS_DC);
int php_oci_collection_size(php_oci_collection *collection, sb4 *size TSRMLS_DC);
int php_oci_collection_max(php_oci_collection *collection, long *max TSRMLS_DC);
int php_oci_collection_trim(php_oci_collection *collection, long trim_size TSRMLS_DC);
int php_oci_collection_append(php_oci_collection *collection, char *element, int element_len TSRMLS_DC);
int php_oci_collection_element_get(php_oci_collection *collection, long index, zval **result_element TSRMLS_DC);
int php_oci_collection_element_set(php_oci_collection *collection, long index, char *value, int value_len TSRMLS_DC);
int php_oci_collection_element_set_null(php_oci_collection *collection, long index TSRMLS_DC);
int php_oci_collection_element_set_date(php_oci_collection *collection, long index, char *date, int date_len TSRMLS_DC);
int php_oci_collection_element_set_number(php_oci_collection *collection, long index, char *number, int number_len TSRMLS_DC);
int php_oci_collection_element_set_string(php_oci_collection *collection, long index, char *element, int element_len TSRMLS_DC);
int php_oci_collection_assign(php_oci_collection *collection_dest, php_oci_collection *collection_from TSRMLS_DC);
void php_oci_collection_close(php_oci_collection *collection TSRMLS_DC);
int php_oci_collection_append_null(php_oci_collection *collection TSRMLS_DC);
int php_oci_collection_append_date(php_oci_collection *collection, char *date, int date_len TSRMLS_DC);
int php_oci_collection_append_number(php_oci_collection *collection, char *number, int number_len TSRMLS_DC);
int php_oci_collection_append_string(php_oci_collection *collection, char *element, int element_len TSRMLS_DC);
php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char *query, int query_len TSRMLS_DC);
php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement TSRMLS_DC);
int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 prefetch TSRMLS_DC);
int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC);
php_oci_out_column *php_oci_statement_get_column(php_oci_statement *statement, long column_index, char *column_name, int column_name_len TSRMLS_DC);
int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC);
int php_oci_statement_cancel(php_oci_statement *statement TSRMLS_DC);
void php_oci_statement_free(php_oci_statement *statement TSRMLS_DC);
int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC);
int php_oci_bind_post_exec(void *data TSRMLS_DC);
int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, zval *var, long maxlength, ub2 type TSRMLS_DC);
sb4 php_oci_bind_in_callback(dvoid *ictxp, OCIBind *bindp, ub4 iter, ub4 index, dvoid **bufpp, ub4 *alenp, ub1 *piecep, dvoid **indpp);
sb4 php_oci_bind_out_callback(dvoid *octxp, OCIBind *bindp, ub4 iter, ub4 index, dvoid **bufpp, ub4 **alenpp, ub1 *piecep, dvoid **indpp, ub2 **rcodepp);
php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAMETERS, int need_data);
int php_oci_cleanup_pre_fetch(void *data TSRMLS_DC);
int php_oci_statement_get_type(php_oci_statement *statement, ub2 *type TSRMLS_DC);
int php_oci_statement_get_numrows(php_oci_statement *statement, ub4 *numrows TSRMLS_DC);
int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, int name_len, zval *var, long max_table_length, long maxlength, long type TSRMLS_DC);
php_oci_bind *php_oci_bind_array_helper_number(zval *var, long max_table_length TSRMLS_DC);
php_oci_bind *php_oci_bind_array_helper_double(zval *var, long max_table_length TSRMLS_DC);
php_oci_bind *php_oci_bind_array_helper_string(zval *var, long max_table_length, long maxlength TSRMLS_DC);
php_oci_bind *php_oci_bind_array_helper_date(zval *var, long max_table_length, php_oci_connection *connection TSRMLS_DC);
ZEND_BEGIN_MODULE_GLOBALS(oci)
sb4 errcode;
OCIError *err;
long max_persistent;
long num_persistent;
long num_links;
long num_statements;
long ping_interval;
long persistent_timeout;
long statement_cache_size;
long default_prefetch;
zend_bool privileged_connect;
zend_bool old_oci_close_semantics;
int shutdown;
OCIEnv *env;
zend_bool in_call;
char *connection_class;
zend_bool events;
char *edition;
ZEND_END_MODULE_GLOBALS(oci)
#ifdef ZTS
#define OCI_G(v) TSRMG(oci_globals_id, zend_oci_globals *, v)
#else
#define OCI_G(v) (oci_globals.v)
#endif
ZEND_EXTERN_MODULE_GLOBALS(oci)
# endif
#else
# define oci8_module_ptr NULL
#endif