xref: /PHP-8.3/ext/oci8/php_oci8_int.h (revision 80b4c730)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Stig Sæther Bakken <ssb@php.net>                            |
14    |          Thies C. Arntzen <thies@thieso.net>                         |
15    |                                                                      |
16    | Collection support by Andy Sautins <asautins@veripost.net>           |
17    | Temporary LOB support by David Benson <dbenson@mancala.com>          |
18    | ZTS per process OCIPLogon by Harald Radi <harald.radi@nme.at>        |
19    |                                                                      |
20    | Redesigned by: Antony Dovgal <antony@zend.com>                       |
21    |                Andi Gutmans <andi@php.net>                           |
22    |                Wez Furlong <wez@omniti.com>                          |
23    +----------------------------------------------------------------------+
24 */
25 
26 #ifdef HAVE_OCI8
27 # ifndef PHP_OCI8_INT_H
28 #  define PHP_OCI8_INT_H
29 
30 /* {{{ misc defines */
31 # if (defined(__osf__) && defined(__alpha))
32 #  ifndef A_OSF
33 #	define A_OSF
34 #  endif
35 #  ifndef OSF1
36 #	define OSF1
37 #  endif
38 #  ifndef _INTRINSICS
39 #	define _INTRINSICS
40 #  endif
41 # endif /* osf alpha */
42 
43 #ifdef HAVE_OCI8_DTRACE
44 #include "oci8_dtrace_gen.h"
45 #endif
46 
47 #if defined(min)
48 #undef min
49 #endif
50 #if defined(max)
51 #undef max
52 #endif
53 /* }}} */
54 
55 #include "ext/standard/php_string.h"
56 ZEND_DIAGNOSTIC_IGNORED_START("-Wstrict-prototypes")
57 #include <oci.h>
58 ZEND_DIAGNOSTIC_IGNORED_END
59 
60 #if !defined(OCI_MAJOR_VERSION) || OCI_MAJOR_VERSION < 11 || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION < 2))
61 #error This version of PHP OCI8 requires Oracle Client libraries from 11.2 or later.
62 #endif
63 
64 extern int le_connection;
65 extern int le_pconnection;
66 extern int le_statement;
67 extern int le_descriptor;
68 extern int le_collection;
69 extern int le_server;
70 extern int le_session;
71 
72 extern zend_class_entry *oci_lob_class_entry_ptr;
73 extern zend_class_entry *oci_coll_class_entry_ptr;
74 
75 /* {{{ constants */
76 #define PHP_OCI_SEEK_SET 0
77 #define PHP_OCI_SEEK_CUR 1
78 #define PHP_OCI_SEEK_END 2
79 
80 #define PHP_OCI_MAX_NAME_LEN  64
81 #define PHP_OCI_MAX_DATA_SIZE INT_MAX
82 #define PHP_OCI_PIECE_SIZE	  ((64*1024)-1)
83 #define PHP_OCI_LOB_BUFFER_SIZE 1048576l  /* 1Mb seems to be the most reasonable buffer size for LOB reading */
84 
85 #define PHP_OCI_ASSOC				(1<<0)
86 #define PHP_OCI_NUM					(1<<1)
87 #define PHP_OCI_BOTH				(PHP_OCI_ASSOC|PHP_OCI_NUM)
88 
89 #define PHP_OCI_RETURN_NULLS		(1<<2)
90 #define PHP_OCI_RETURN_LOBS			(1<<3)
91 
92 #define PHP_OCI_FETCHSTATEMENT_BY_COLUMN	(1<<4)
93 #define PHP_OCI_FETCHSTATEMENT_BY_ROW		(1<<5)
94 #define PHP_OCI_FETCHSTATEMENT_BY			(PHP_OCI_FETCHSTATEMENT_BY_COLUMN | PHP_OCI_FETCHSTATEMENT_BY_ROW)
95 
96 #define PHP_OCI_LOB_BUFFER_DISABLED 0
97 #define PHP_OCI_LOB_BUFFER_ENABLED  1
98 #define PHP_OCI_LOB_BUFFER_USED     2
99 
100 #ifdef OCI_ERROR_MAXMSG_SIZE2
101 /* Bigger size is defined from 11.2.0.3 onwards */
102 #define PHP_OCI_ERRBUF_LEN OCI_ERROR_MAXMSG_SIZE2
103 #else
104 #define PHP_OCI_ERRBUF_LEN OCI_ERROR_MAXMSG_SIZE
105 #endif
106 
107 /* The mode parameter for oci_connect() is overloaded and accepts both
108  * privilege and external authentication flags OR'd together.
109  * PHP_OCI_CRED_EXT must be distinct from the OCI_xxx privilege
110  * values.
111  */
112 #define PHP_OCI_CRED_EXT                    (1u<<31)
113 #if ((PHP_OCI_CRED_EXT == OCI_DEFAULT) || (PHP_OCI_CRED_EXT & (OCI_SYSOPER | OCI_SYSDBA)))
114 #error Invalid value for PHP_OCI_CRED_EXT
115 #endif
116 
117 #define PHP_OCI_IMPRES_UNKNOWN			0
118 #define PHP_OCI_IMPRES_NO_CHILDREN		1
119 #define PHP_OCI_IMPRES_HAS_CHILDREN		2
120 #define PHP_OCI_IMPRES_IS_CHILD			3
121 
122 /*
123  * Name passed to Oracle for tracing.  Note some DB views only show
124  * the first nine characters of the driver name.
125  */
126 #define PHP_OCI8_DRIVER_NAME     "PHP OCI8 : " PHP_OCI8_VERSION
127 
128 /* }}} */
129 
130 /* {{{ php_oci_spool */
131 typedef struct {
132 	zend_resource *id;					/* resource id */
133 	OCIEnv		 *env;					/* env of this session pool */
134 	OCIError	 *err;					/* pool's error handle	*/
135 	OCISPool	 *poolh;				/* pool handle */
136 	void		 *poolname;				/* session pool name */
137 	unsigned int  poolname_len;			/* length of session pool name */
138 	zend_string	 *spool_hash_key;		/* Hash key for session pool in plist */
139 } php_oci_spool;
140 /* }}} */
141 
142 /* {{{ php_oci_connection */
143 typedef struct {
144 	zend_resource  *id;							/* resource ID */
145 	OCIEnv		   *env;						/* private env handle */
146 	ub2				charset;					/* charset ID */
147 	OCIServer	   *server;						/* private server handle */
148 	OCISvcCtx	   *svc;						/* private service context handle */
149 	OCISession	   *session;					/* private session handle */
150 	OCIAuthInfo	   *authinfo;					/* Cached authinfo handle for OCISessionGet */
151 	OCIError	   *err;						/* private error handle */
152 	php_oci_spool  *private_spool;				/* private session pool (for persistent) */
153 	sb4				errcode;					/* last ORA- error number */
154 
155 	HashTable	   *descriptors;				/* descriptors hash, used to flush all the LOBs using this connection on commit */
156 	zend_ulong		descriptor_count;			/* used to index the descriptors hash table.  Not an accurate count */
157 	unsigned		is_open:1;					/* hels to determine if the connection is dead or not */
158 	unsigned		is_attached:1;				/* hels to determine if we should detach from the server when closing/freeing the connection */
159 	unsigned		is_persistent:1;			/* self-descriptive */
160 	unsigned		used_this_request:1;		/* helps to determine if we should reset connection's next ping time and check its timeout */
161 	unsigned		rb_on_disconnect:1;			/* helps to determine if we should rollback this connection on close/shutdown */
162 	unsigned		passwd_changed:1;			/* helps determine if a persistent connection hash should be invalidated after a password change */
163 	unsigned		is_stub:1;					/* flag to keep track whether the connection structure has a real OCI connection associated */
164 	unsigned		using_spool:1;				/* Is this connection from session pool? */
165 	time_t			idle_expiry;				/* time when the connection will be considered as expired */
166 	time_t		   *next_pingp;					/* (pointer to) time of the next ping */
167 	zend_string	   *hash_key;					/* hashed details of the connection */
168 #ifdef HAVE_OCI8_DTRACE
169 	char		   *client_id;					/* The oci_set_client_identifier() value */
170 #endif
171 
172 	zval		    taf_callback;				/* The Oracle TAF callback function in the userspace */
173 } php_oci_connection;
174 /* }}} */
175 
176 /* {{{ php_oci_descriptor */
177 typedef struct {
178 	zend_resource		*id;
179 	zend_ulong				 index;		            /* descriptors hash table index */
180 	php_oci_connection	*connection;			/* parent connection handle */
181 	dvoid				*descriptor;			/* OCI descriptor handle */
182 	ub4					 type;					/* descriptor type (FILE/LOB) */
183 	ub4					 lob_current_position;	/* LOB internal pointer */
184 	int					 lob_size;				/* cached LOB size. -1 = Lob wasn't initialized yet */
185 	int					 buffering;				/* cached buffering flag. 0 - off, 1 - on, 2 - on and buffer was used */
186 	ub4					 chunk_size;			/* chunk size of the LOB. 0 - unknown */
187 	ub1					 charset_form;			/* charset form, required for NCLOBs */
188 	ub2					 charset_id;			/* charset ID */
189 	unsigned			 is_open:1;				/* helps to determine if lob is open or not */
190 } php_oci_descriptor;
191 /* }}} */
192 
193 /* {{{ php_oci_lob_ctx */
194 typedef struct {
195 	char			   **lob_data;				/* address of pointer to LOB data */
196 	ub4					*lob_len;				/* address of LOB length variable (bytes) */
197 	ub4					 alloc_len;
198 } php_oci_lob_ctx;
199 /* }}} */
200 
201 /* {{{ php_oci_collection */
202 typedef struct {
203 	zend_resource		*id;
204 	php_oci_connection	*connection;			/* parent connection handle */
205 	OCIType				*tdo;					/* collection's type handle */
206 	OCITypeCode			 coll_typecode;			/* collection's typecode handle */
207 	OCIRef				*elem_ref;				/* element's reference handle */
208 	OCIType				*element_type;			/* element's type handle */
209 	OCITypeCode			 element_typecode;		/* element's typecode handle */
210 	OCIColl				*collection;			/* collection handle */
211 } php_oci_collection;
212 /* }}} */
213 
214 /* {{{ php_oci_define */
215 typedef struct {
216 	zval		 val;			/* zval used in define */
217 	text		*name;			/* placeholder's name */
218 	ub4			 name_len;		/* placeholder's name length */
219 	ub4			 type;			/* define type */
220 } php_oci_define;
221 /* }}} */
222 
223 /* {{{ php_oci_statement */
224 typedef struct {
225 	zend_resource		*id;
226 	zend_resource	 	*parent_stmtid;			/* parent statement id */
227 	struct php_oci_statement *impres_child_stmt;/* child of current Implicit Result Set statement handle */
228 	ub4                  impres_count;          /* count of remaining Implicit Result children on parent statement handle */
229 	php_oci_connection	*connection;			/* parent connection handle */
230 	sb4					 errcode;				/* last ORA- error number */
231 	OCIError			*err;					/* private error handle */
232 	OCIStmt				*stmt;					/* statement handle */
233 	char				*last_query;			/* last query issued. also used to determine if this is a statement or a refcursor received from Oracle */
234 	char                 impres_flag;           /* PHP_OCI_IMPRES_*_ */
235 	zend_long			 last_query_len;		/* last query length */
236 	HashTable			*columns;				/* hash containing all the result columns */
237 	HashTable			*binds;					/* binds hash */
238 	HashTable			*defines;				/* defines hash */
239 	int					 ncolumns;				/* number of columns in the result */
240 	unsigned			 executed:1;			/* statement executed flag */
241 	unsigned			 has_data:1;			/* statement has more data flag */
242 	unsigned			 has_descr:1;			/* statement has at least one descriptor or cursor column */
243 	ub2					 stmttype;				/* statement type */
244 	ub4                  prefetch_count;        /* row prefetch count */
245 	ub4                  prefetch_lob_size;     /* LOB prefetch size */
246 } php_oci_statement;
247 /* }}} */
248 
249 /* {{{ php_oci_bind */
250 typedef struct {
251 	OCIBind				*bind;					/* bind handle */
252 	zval				val;					/* value */
253 	dvoid				*descriptor;			/* used for binding of LOBS etc */
254 	OCIStmt				*statement;				/* used for binding REFCURSORs */
255 	php_oci_statement	*parent_statement;		/* pointer to the parent statement */
256 	ub2 type;						/* bind type */
257 	struct {
258 		void	*elements;
259 		sb2		*indicators;
260 		ub2		*element_lengths;
261 		ub4		 current_length;
262 		ub4		 old_length;
263 		ub4		 max_length;
264 		zend_long	 type;
265 	} array;
266 	sb2					 indicator;				/* -1 means NULL */
267 	ub2					 retcode;
268 	ub4					 dummy_len;				/* a dummy var to store alenpp value in bind OUT callback */
269 } php_oci_bind;
270 /* }}} */
271 
272 /* {{{ php_oci_out_column */
273 typedef struct {
274 	php_oci_statement	*statement;				/* statement handle. used when fetching REFCURSORS */
275 	php_oci_statement	*nested_statement;		/* statement handle. used when fetching REFCURSORS */
276 	OCIDefine			*oci_define;			/* define handle */
277 	char				*name;					/* column name */
278 	ub4					 name_len;				/* column name length */
279 	ub2					 data_type;				/* column data type */
280 	ub2					 data_size;				/* data size */
281 	ub4					 storage_size4;			/* size used when allocating buffers */
282 	sb2					 indicator;
283 	ub2					 retcode;				/* code returned when fetching this particular column */
284 	ub2					 retlen;
285 	ub4					 retlen4;
286 	ub2					 is_descr;				/* column contains a descriptor */
287 	ub2					 is_cursor;				/* column contains a cursor */
288 	zend_resource		*stmtid;				/* statement id for cursors */
289 	zend_resource		*descid;				/* descriptor id for descriptors */
290 	void				*data;
291 	php_oci_define		*define;				/* define handle */
292 	int					 piecewise;				/* column is fetched piece-by-piece */
293 	ub4					 cb_retlen;
294 	sb1					 scale;					/* column scale */
295 	sb2					 precision;				/* column precision */
296 	ub1					 charset_form;			/* charset form, required for NCLOBs */
297 	ub2					 charset_id;			/* charset ID */
298 	ub4					 chunk_size;			/* LOB chunk size */
299 } php_oci_out_column;
300 /* }}} */
301 
302 /* {{{ macros */
303 
304 #define PHP_OCI_CALL(func, params)								\
305 	do {																\
306 		OCI_G(in_call) = 1;												\
307 		func params;													\
308 		OCI_G(in_call) = 0;												\
309 	} while (0)
310 
311 #define PHP_OCI_CALL_RETURN(__retval, func, params)			\
312 	do {																\
313 		OCI_G(in_call) = 1;												\
314 		__retval = func params;											\
315 		OCI_G(in_call) = 0;												\
316 	} while (0)
317 
318 /* Check for errors that indicate the connection to the DB is no
319  * longer valid.  If it isn't, then the PHP connection is marked to be
320  * reopened by the next PHP OCI8 connect command.  This is most useful
321  * for persistent connections.	The error number list is not
322  * exclusive.  The error number comparisons and the
323  * OCI_ATTR_SERVER_STATUS check are done for maximum cross-version
324  * compatibility. In the far future, only the attribute check will be
325  * needed.
326  */
327 #define PHP_OCI_HANDLE_ERROR(connection, errcode) \
328 	do {										  \
329 		ub4 serverStatus = OCI_SERVER_NORMAL;	  \
330 		switch (errcode) {						  \
331 			case  1013:							  \
332 				zend_bailout();					  \
333 				break;							  \
334 			case	22:							  \
335 			case	28:							  \
336 			case   378:							  \
337 			case   602:							  \
338 			case   603:							  \
339 			case   604:							  \
340 			case   609:							  \
341 			case  1012:							  \
342 			case  1033:							  \
343 			case  1041:							  \
344 			case  1043:							  \
345 			case  1089:							  \
346 			case  1090:							  \
347 			case  1092:							  \
348 			case  3113:							  \
349 			case  3114:							  \
350 			case  3122:							  \
351 			case  3135:							  \
352 			case  3136:							  \
353 			case 12153:							  \
354 			case 12161:							  \
355 			case 27146:							  \
356 			case 28511:							  \
357 				(connection)->is_open = 0;		  \
358 				break;							  \
359 			default:										\
360 			{												\
361 				PHP_OCI_CALL(OCIAttrGet, ((dvoid *)(connection)->server, OCI_HTYPE_SERVER, (dvoid *)&serverStatus, \
362 										  (ub4 *)0, OCI_ATTR_SERVER_STATUS, (connection)->err)); \
363 				if (serverStatus != OCI_SERVER_NORMAL) {	\
364 					(connection)->is_open = 0;				\
365 				}											\
366 			}												\
367 			break;											\
368 		}													\
369 		php_oci_dtrace_check_connection(connection, errcode, serverStatus); \
370 	} while (0)
371 
372 #define PHP_OCI_REGISTER_RESOURCE(resource, le_resource) \
373 	do { \
374 		resource->id = zend_register_resource(resource, le_resource); \
375 	} while (0)
376 
377 #define PHP_OCI_ZVAL_TO_CONNECTION(zval, connection) \
378 	if ((connection = (php_oci_connection *)zend_fetch_resource2(Z_RES_P(zval), "oci8 connection", le_connection, le_pconnection)) == NULL) { \
379 		RETURN_THROWS(); \
380 	}
381 
382 #define PHP_OCI_ZVAL_TO_STATEMENT(zval, statement) \
383 	if ((statement = (php_oci_statement *)zend_fetch_resource(Z_RES_P(zval), "oci8 statement", le_statement)) == NULL) { \
384 		RETURN_THROWS(); \
385 	}
386 
387 #define PHP_OCI_ZVAL_TO_DESCRIPTOR(zval, descriptor) \
388 	if ((descriptor = (php_oci_descriptor *)zend_fetch_resource(Z_RES_P(zval), "oci8 descriptor", le_descriptor)) == NULL) { \
389 		RETURN_THROWS(); \
390 	}
391 
392 #define PHP_OCI_ZVAL_TO_COLLECTION(zval, collection) \
393 	if ((collection = (php_oci_collection *)zend_fetch_resource(Z_RES_P(zval), "oci8 collection", le_collection)) == NULL) { \
394 		RETURN_THROWS(); \
395 	}
396 
397 #define PHP_OCI_FETCH_RESOURCE_EX(zval, var, type, name, resource_type)						 \
398 	do { \
399 		var = (type) zend_fetch_resource(Z_RES_P(zval), name, resource_type);                \
400 		if (!var) {																			 \
401 			return 1;																		 \
402 		} \
403 	} while (0)
404 
405 #define PHP_OCI_ZVAL_TO_CONNECTION_EX(zval, connection) \
406 	PHP_OCI_FETCH_RESOURCE_EX(zval, connection, php_oci_connection *, "oci8 connection", le_connection)
407 
408 #define PHP_OCI_ZVAL_TO_STATEMENT_EX(zval, statement) \
409 	PHP_OCI_FETCH_RESOURCE_EX(zval, statement, php_oci_statement *, "oci8 statement", le_statement)
410 
411 #define PHP_OCI_ZVAL_TO_DESCRIPTOR_EX(zval, descriptor) \
412 	PHP_OCI_FETCH_RESOURCE_EX(zval, descriptor, php_oci_descriptor *, "oci8 descriptor", le_descriptor)
413 
414 #define PHP_OCI_ZVAL_TO_COLLECTION_EX(zval, collection) \
415 	PHP_OCI_FETCH_RESOURCE_EX(zval, collection, php_oci_collection *, "oci8 collection", le_collection)
416 
417 /* }}} */
418 
419 /* PROTOS */
420 
421 /* {{{ main prototypes */
422 
423 void php_oci_column_hash_dtor(zval *data);
424 void php_oci_define_hash_dtor(zval *data);
425 void php_oci_bind_hash_dtor(zval *data);
426 void php_oci_descriptor_flush_hash_dtor(zval *data);
427 void php_oci_connection_descriptors_free(php_oci_connection *connection);
428 sb4 php_oci_error(OCIError *err_p, sword status);
429 sb4 php_oci_fetch_errmsg(OCIError *error_handle, text *error_buf, size_t error_buf_size);
430 int php_oci_fetch_sqltext_offset(php_oci_statement *statement, text **sqltext, ub2 *error_offset);
431 void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclusive);
432 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, zend_long session_mode, int persistent, int exclusive);
433 int php_oci_connection_rollback(php_oci_connection *connection);
434 int php_oci_connection_commit(php_oci_connection *connection);
435 int php_oci_connection_release(php_oci_connection *connection);
436 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);
437 void php_oci_client_get_version(char *version, size_t version_size);
438 int php_oci_server_get_version(php_oci_connection *connection, char *version, size_t version_size);
439 void php_oci_fetch_row(INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_args);
440 int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode);
441 void php_oci_dtrace_check_connection(php_oci_connection *connection, sb4 errcode, ub4 serverStatus);
442 
443 /* }}} */
444 
445 /* {{{ lob related prototypes */
446 
447 php_oci_descriptor *php_oci_lob_create(php_oci_connection *connection, zend_long type);
448 int php_oci_lob_get_length(php_oci_descriptor *descriptor, ub4 *length);
449 int php_oci_lob_read(php_oci_descriptor *descriptor, zend_long read_length, zend_long inital_offset, char **data, ub4 *data_len);
450 int php_oci_lob_write(php_oci_descriptor *descriptor, ub4 offset, char *data, int data_len, ub4 *bytes_written);
451 int php_oci_lob_flush(php_oci_descriptor *descriptor, zend_long flush_flag);
452 int php_oci_lob_set_buffering(php_oci_descriptor *descriptor, int on_off);
453 int php_oci_lob_get_buffering(php_oci_descriptor *descriptor);
454 int php_oci_lob_copy(php_oci_descriptor *descriptor, php_oci_descriptor *descriptor_from, zend_long length);
455 int php_oci_lob_close(php_oci_descriptor *descriptor);
456 int php_oci_temp_lob_close(php_oci_descriptor *descriptor);
457 int php_oci_lob_write_tmp(php_oci_descriptor *descriptor, zend_long type, char *data, int data_len);
458 void php_oci_lob_free(php_oci_descriptor *descriptor);
459 int php_oci_lob_import(php_oci_descriptor *descriptor, char *filename);
460 int php_oci_lob_append(php_oci_descriptor *descriptor_dest, php_oci_descriptor *descriptor_from);
461 int php_oci_lob_truncate(php_oci_descriptor *descriptor, zend_long new_lob_length);
462 int php_oci_lob_erase(php_oci_descriptor *descriptor, zend_long offset, ub4 length, ub4 *bytes_erased);
463 int php_oci_lob_is_equal(php_oci_descriptor *descriptor_first, php_oci_descriptor *descriptor_second, boolean *result);
464 sb4 php_oci_lob_callback(dvoid *ctxp, CONST dvoid *bufxp, oraub8 len, ub1 piece, dvoid **changed_bufpp, oraub8 *changed_lenp);
465 /* }}} */
466 
467 /* {{{ collection related prototypes */
468 
469 php_oci_collection *php_oci_collection_create(php_oci_connection *connection, char *tdo, int tdo_len, char *schema, int schema_len);
470 int php_oci_collection_size(php_oci_collection *collection, sb4 *size);
471 int php_oci_collection_max(php_oci_collection *collection, zend_long *max);
472 int php_oci_collection_trim(php_oci_collection *collection, zend_long trim_size);
473 int php_oci_collection_append(php_oci_collection *collection, char *element, int element_len);
474 int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval *result_element);
475 int php_oci_collection_element_set(php_oci_collection *collection, zend_long index, char *value, int value_len);
476 int php_oci_collection_element_set_null(php_oci_collection *collection, zend_long index);
477 int php_oci_collection_element_set_date(php_oci_collection *collection, zend_long index, char *date, int date_len);
478 int php_oci_collection_element_set_number(php_oci_collection *collection, zend_long index, char *number, int number_len);
479 int php_oci_collection_element_set_string(php_oci_collection *collection, zend_long index, char *element, int element_len);
480 int php_oci_collection_assign(php_oci_collection *collection_dest, php_oci_collection *collection_from);
481 void php_oci_collection_close(php_oci_collection *collection);
482 int php_oci_collection_append_null(php_oci_collection *collection);
483 int php_oci_collection_append_date(php_oci_collection *collection, char *date, int date_len);
484 int php_oci_collection_append_number(php_oci_collection *collection, char *number, int number_len);
485 int php_oci_collection_append_string(php_oci_collection *collection, char *element, int element_len);
486 
487 
488 /* }}} */
489 
490 /* {{{ statement related prototypes */
491 
492 php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char *query, int query_len);
493 php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement);
494 int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 prefetch);
495 int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows);
496 php_oci_out_column *php_oci_statement_get_column(php_oci_statement *statement, zend_long column_index, char *column_name, int column_name_len);
497 int php_oci_statement_execute(php_oci_statement *statement, ub4 mode);
498 int php_oci_statement_cancel(php_oci_statement *statement);
499 void php_oci_statement_free(php_oci_statement *statement);
500 int php_oci_bind_pre_exec(zval *data, void *result);
501 int php_oci_bind_post_exec(zval *data);
502 int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_len, zval *var, zend_long maxlength, ub2 type);
503 sb4 php_oci_bind_in_callback(dvoid *ictxp, OCIBind *bindp, ub4 iter, ub4 index, dvoid **bufpp, ub4 *alenp, ub1 *piecep, dvoid **indpp);
504 sb4 php_oci_bind_out_callback(dvoid *octxp, OCIBind *bindp, ub4 iter, ub4 index, dvoid **bufpp, ub4 **alenpp, ub1 *piecep, dvoid **indpp, ub2 **rcodepp);
505 php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAMETERS, int need_data);
506 int php_oci_cleanup_pre_fetch(zval *data);
507 int php_oci_statement_get_type(php_oci_statement *statement, ub2 *type);
508 int php_oci_statement_get_numrows(php_oci_statement *statement, ub4 *numrows);
509 int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t name_len, zval *var, zend_long max_table_length, zend_long maxlength, zend_long type);
510 php_oci_bind *php_oci_bind_array_helper_number(zval *var, zend_long max_table_length);
511 php_oci_bind *php_oci_bind_array_helper_double(zval *var, zend_long max_table_length);
512 php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_length, zend_long maxlength);
513 php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_length, php_oci_connection *connection);
514 
515 /* }}} */
516 
517 ZEND_BEGIN_MODULE_GLOBALS(oci) /* {{{ Module globals */
518 	sb4			 errcode;						/* global last ORA- error number. Used when connect fails, for example */
519 	OCIError	*err;							/* global error handle */
520 
521 	zend_long		 max_persistent;				/* maximum number of persistent connections per process */
522 	zend_long		 num_persistent;				/* number of existing persistent connections */
523 	zend_long		 num_links;						/* non-persistent + persistent connections */
524 	zend_long		 num_statements;				/* number of statements open */
525 	zend_long		 ping_interval;					/* time interval between pings */
526 	zend_long		 persistent_timeout;			/* time period after which idle persistent connection is considered expired */
527 	zend_long		 statement_cache_size;			/* statement cache size. used with 9i+ clients only*/
528 	zend_long		 default_prefetch;				/* default prefetch setting */
529 	zend_long	 	 prefetch_lob_size;				/* amount of LOB data to read when initially getting a LOB locator */
530 	bool	 privileged_connect;			/* privileged connect flag (On/Off) */
531 	bool	 old_oci_close_semantics;		/* old_oci_close_semantics flag (to determine the way oci_close() should behave) */
532 	int			 shutdown;						/* in shutdown flag */
533 
534 	OCIEnv		*env;							/* global environment handle */
535 
536 	bool	 in_call;
537 	char		*connection_class;
538 	bool	 events;
539 	char		*edition;
540 ZEND_END_MODULE_GLOBALS(oci) /* }}} */
541 
542 /* {{{ transparent failover related prototypes */
543 
544 int php_oci_register_taf_callback(php_oci_connection *connection, zval *callback);
545 int php_oci_unregister_taf_callback(php_oci_connection *connection);
546 
547 /* }}} */
548 
549 #ifdef ZTS
550 #define OCI_G(v) TSRMG(oci_globals_id, zend_oci_globals *, v)
551 #else
552 #define OCI_G(v) (oci_globals.v)
553 #endif
554 
555 /* Allow install from PECL on PHP < 7.3 */
556 #ifndef GC_ADDREF
557 # define GC_ADDREF(p) (++GC_REFCOUNT(p))
558 #endif
559 #ifndef GC_DELREF
560 # define GC_DELREF(p) (GC_REFCOUNT(p)--)
561 #endif
562 
563 ZEND_EXTERN_MODULE_GLOBALS(oci)
564 
565 # endif /* !PHP_OCI8_INT_H */
566 #else /* !HAVE_OCI8 */
567 
568 # define oci8_module_ptr NULL
569 
570 #endif /* HAVE_OCI8 */
571