1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Stig Sæther Bakken <ssb@php.net> |
16 : | Thies C. Arntzen <thies@thieso.net> |
17 : | |
18 : | Collection support by Andy Sautins <asautins@veripost.net> |
19 : | Temporary LOB support by David Benson <dbenson@mancala.com> |
20 : | ZTS per process OCIPLogon by Harald Radi <harald.radi@nme.at> |
21 : | |
22 : | Redesigned by: Antony Dovgal <antony@zend.com> |
23 : | Andi Gutmans <andi@zend.com> |
24 : | Wez Furlong <wez@omniti.com> |
25 : +----------------------------------------------------------------------+
26 : */
27 :
28 : /* $Id: oci8_interface.c 272374 2008-12-31 11:17:49Z sebastian $ */
29 :
30 : #ifdef HAVE_CONFIG_H
31 : #include "config.h"
32 : #endif
33 :
34 : #include "php.h"
35 : #include "ext/standard/info.h"
36 : #include "php_ini.h"
37 :
38 : #if HAVE_OCI8
39 :
40 : #include "php_oci8.h"
41 : #include "php_oci8_int.h"
42 :
43 : #ifndef OCI_STMT_CALL
44 : #define OCI_STMT_CALL 10
45 : #endif
46 :
47 : /* {{{ proto bool oci_define_by_name(resource stmt, string name, mixed &var [, int type])
48 : Define a PHP variable to an Oracle column by name */
49 : /* if you want to define a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE defining!!! */
50 : PHP_FUNCTION(oci_define_by_name)
51 30024 : {
52 : zval *stmt, *var;
53 : char *name;
54 : int name_len;
55 30024 : long type = 0;
56 : php_oci_statement *statement;
57 : php_oci_define *define, *tmp_define;
58 :
59 30024 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz/|l", &stmt, &name, &name_len, &var, &type) == FAILURE) {
60 2 : return;
61 : }
62 :
63 30022 : if (!name_len) {
64 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Column name cannot be empty");
65 1 : RETURN_FALSE;
66 : }
67 :
68 30021 : PHP_OCI_ZVAL_TO_STATEMENT(stmt, statement);
69 :
70 30021 : if (statement->defines == NULL) {
71 15020 : ALLOC_HASHTABLE(statement->defines);
72 15020 : zend_hash_init(statement->defines, 13, NULL, php_oci_define_hash_dtor, 0);
73 : }
74 :
75 30021 : define = ecalloc(1,sizeof(php_oci_define));
76 :
77 30021 : if (zend_hash_add(statement->defines, name, name_len, define, sizeof(php_oci_define), (void **)&tmp_define) == SUCCESS) {
78 30020 : efree(define);
79 30020 : define = tmp_define;
80 : } else {
81 1 : efree(define);
82 1 : RETURN_FALSE;
83 : }
84 :
85 30020 : define->name = (text*) estrndup(name, name_len);
86 30020 : define->name_len = name_len;
87 30020 : define->type = type;
88 30020 : define->zval = var;
89 30020 : zval_add_ref(&var);
90 :
91 30020 : RETURN_TRUE;
92 : }
93 : /* }}} */
94 :
95 : /* {{{ proto bool oci_bind_by_name(resource stmt, string name, mixed &var, [, int maxlength [, int type]])
96 : Bind a PHP variable to an Oracle placeholder by name */
97 : /* if you want to bind a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE binding!!! */
98 : PHP_FUNCTION(oci_bind_by_name)
99 314 : {
100 314 : ub2 bind_type = SQLT_CHR; /* unterminated string */
101 : int name_len;
102 314 : long maxlen = -1, type = 0;
103 : char *name;
104 : zval *z_statement;
105 314 : zval *bind_var = NULL;
106 : php_oci_statement *statement;
107 :
108 314 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz/|ll", &z_statement, &name, &name_len, &bind_var, &maxlen, &type) == FAILURE) {
109 5 : return;
110 : }
111 :
112 309 : if (type) {
113 189 : bind_type = (ub2) type;
114 : }
115 :
116 309 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
117 :
118 309 : if (php_oci_bind_by_name(statement, name, name_len, bind_var, maxlen, bind_type TSRMLS_CC)) {
119 1 : RETURN_FALSE;
120 : }
121 308 : RETURN_TRUE;
122 : }
123 : /* }}} */
124 :
125 : /* {{{ proto bool oci_bind_array_by_name(resource stmt, string name, array &var, int max_table_length [, int max_item_length [, int type ]])
126 : Bind a PHP array to an Oracle PL/SQL type by name */
127 : PHP_FUNCTION(oci_bind_array_by_name)
128 27 : {
129 : int name_len;
130 27 : long max_item_len = -1;
131 27 : long max_array_len = 0;
132 27 : long type = SQLT_AFC;
133 : char *name;
134 : zval *z_statement;
135 27 : zval *bind_var = NULL;
136 : php_oci_statement *statement;
137 :
138 27 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz/l|ll", &z_statement, &name, &name_len, &bind_var, &max_array_len, &max_item_len, &type) == FAILURE) {
139 1 : return;
140 : }
141 :
142 26 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
143 :
144 25 : if (ZEND_NUM_ARGS() == 5 && max_item_len <= 0) {
145 3 : max_item_len = -1;
146 : }
147 :
148 25 : if (max_array_len <= 0) {
149 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Maximum array length must be greater than zero");
150 1 : RETURN_FALSE;
151 : }
152 :
153 24 : if (php_oci_bind_array_by_name(statement, name, name_len, bind_var, max_array_len, max_item_len, type TSRMLS_CC)) {
154 8 : RETURN_FALSE;
155 : }
156 16 : RETURN_TRUE;
157 : }
158 : /* }}} */
159 :
160 : /* {{{ proto bool oci_free_descriptor()
161 : Deletes large object description */
162 : PHP_FUNCTION(oci_free_descriptor)
163 181110 : {
164 181110 : zval **tmp, *z_descriptor = getThis();
165 : php_oci_descriptor *descriptor;
166 :
167 181110 : if (!getThis()) {
168 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
169 3 : return;
170 : }
171 : }
172 :
173 181107 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
174 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
175 1 : RETURN_FALSE;
176 : }
177 :
178 181106 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
179 :
180 181105 : zend_list_delete(descriptor->id);
181 181105 : RETURN_TRUE;
182 : }
183 : /* }}} */
184 :
185 : /* {{{ proto bool oci_lob_save( string data [, int offset ])
186 : Saves a large object */
187 : PHP_FUNCTION(oci_lob_save)
188 28 : {
189 28 : zval **tmp, *z_descriptor = getThis();
190 : php_oci_descriptor *descriptor;
191 : char *data;
192 : int data_len;
193 28 : long offset = 0;
194 : ub4 bytes_written;
195 :
196 28 : if (getThis()) {
197 23 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &offset) == FAILURE) {
198 1 : return;
199 : }
200 : }
201 : else {
202 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &offset) == FAILURE) {
203 3 : return;
204 : }
205 : }
206 :
207 24 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
208 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
209 1 : RETURN_FALSE;
210 : }
211 :
212 23 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
213 :
214 23 : if (offset < 0) {
215 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset parameter must be greater than or equal to 0");
216 1 : RETURN_FALSE;
217 : }
218 :
219 22 : if (php_oci_lob_write(descriptor, offset, data, data_len, &bytes_written TSRMLS_CC)) {
220 1 : RETURN_FALSE;
221 : }
222 21 : RETURN_TRUE;
223 : }
224 : /* }}} */
225 :
226 : /* {{{ proto bool oci_lob_import( string filename )
227 : Loads file into a LOB */
228 : PHP_FUNCTION(oci_lob_import)
229 12 : {
230 12 : zval **tmp, *z_descriptor = getThis();
231 : php_oci_descriptor *descriptor;
232 : char *filename;
233 : int filename_len;
234 :
235 12 : if (getThis()) {
236 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
237 1 : return;
238 : }
239 : }
240 : else {
241 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len) == FAILURE) {
242 4 : return;
243 : }
244 : }
245 :
246 7 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
247 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
248 1 : RETURN_FALSE;
249 : }
250 :
251 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
252 :
253 6 : if (php_oci_lob_import(descriptor, filename TSRMLS_CC)) {
254 2 : RETURN_FALSE;
255 : }
256 4 : RETURN_TRUE;
257 : }
258 : /* }}} */
259 :
260 : /* {{{ proto string oci_lob_load()
261 : Loads a large object */
262 : PHP_FUNCTION(oci_lob_load)
263 69 : {
264 69 : zval **tmp, *z_descriptor = getThis();
265 : php_oci_descriptor *descriptor;
266 69 : char *buffer = NULL;
267 : ub4 buffer_len;
268 :
269 69 : if (!getThis()) {
270 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
271 3 : return;
272 : }
273 : }
274 :
275 66 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
276 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
277 1 : RETURN_FALSE;
278 : }
279 :
280 65 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
281 :
282 65 : if (php_oci_lob_read(descriptor, -1, 0, &buffer, &buffer_len TSRMLS_CC)) {
283 0 : RETURN_FALSE;
284 : }
285 65 : if (buffer_len > 0) {
286 51 : RETURN_STRINGL(buffer, buffer_len, 0);
287 : }
288 : else {
289 14 : RETURN_EMPTY_STRING();
290 : }
291 : }
292 : /* }}} */
293 :
294 : /* {{{ proto string oci_lob_read( int length )
295 : Reads particular part of a large object */
296 : PHP_FUNCTION(oci_lob_read)
297 445 : {
298 445 : zval **tmp, *z_descriptor = getThis();
299 : php_oci_descriptor *descriptor;
300 : long length;
301 : char *buffer;
302 : ub4 buffer_len;
303 :
304 445 : if (getThis()) {
305 437 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) {
306 0 : return;
307 : }
308 : }
309 : else {
310 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_descriptor, oci_lob_class_entry_ptr, &length) == FAILURE) {
311 4 : return;
312 : }
313 : }
314 :
315 441 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
316 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
317 1 : RETURN_FALSE;
318 : }
319 :
320 440 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
321 :
322 440 : if (length <= 0) {
323 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
324 1 : RETURN_FALSE;
325 : }
326 :
327 439 : if (php_oci_lob_read(descriptor, length, descriptor->lob_current_position, &buffer, &buffer_len TSRMLS_CC)) {
328 1 : RETURN_FALSE;
329 : }
330 438 : if (buffer_len > 0) {
331 437 : RETURN_STRINGL(buffer, buffer_len, 0);
332 : }
333 : else {
334 1 : RETURN_EMPTY_STRING();
335 : }
336 : }
337 : /* }}} */
338 :
339 : /* {{{ proto bool oci_lob_eof()
340 : Checks if EOF is reached */
341 : PHP_FUNCTION(oci_lob_eof)
342 18 : {
343 18 : zval **tmp, *z_descriptor = getThis();
344 : php_oci_descriptor *descriptor;
345 : ub4 lob_length;
346 :
347 18 : if (!getThis()) {
348 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
349 2 : return;
350 : }
351 : }
352 :
353 16 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
354 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
355 1 : RETURN_FALSE;
356 : }
357 :
358 15 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
359 :
360 15 : if (!php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC) && lob_length >= 0) {
361 15 : if (lob_length == descriptor->lob_current_position) {
362 4 : RETURN_TRUE;
363 : }
364 : }
365 11 : RETURN_FALSE;
366 : }
367 : /* }}} */
368 :
369 : /* {{{ proto int oci_lob_tell()
370 : Tells LOB pointer position */
371 : PHP_FUNCTION(oci_lob_tell)
372 420 : {
373 420 : zval **tmp, *z_descriptor = getThis();
374 : php_oci_descriptor *descriptor;
375 :
376 420 : if (!getThis()) {
377 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
378 1 : return;
379 : }
380 : }
381 :
382 419 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
383 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
384 0 : RETURN_FALSE;
385 : }
386 :
387 419 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
388 :
389 419 : RETURN_LONG(descriptor->lob_current_position);
390 : }
391 : /* }}} */
392 :
393 : /* {{{ proto bool oci_lob_rewind()
394 : Rewind pointer of a LOB */
395 : PHP_FUNCTION(oci_lob_rewind)
396 4 : {
397 4 : zval **tmp, *z_descriptor = getThis();
398 : php_oci_descriptor *descriptor;
399 :
400 4 : if (!getThis()) {
401 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
402 2 : return;
403 : }
404 : }
405 :
406 2 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
407 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
408 0 : RETURN_FALSE;
409 : }
410 :
411 2 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
412 :
413 2 : descriptor->lob_current_position = 0;
414 :
415 2 : RETURN_TRUE;
416 : }
417 : /* }}} */
418 :
419 : /* {{{ proto bool oci_lob_seek( int offset [, int whence ])
420 : Moves the pointer of a LOB */
421 : PHP_FUNCTION(oci_lob_seek)
422 21 : {
423 21 : zval **tmp, *z_descriptor = getThis();
424 : php_oci_descriptor *descriptor;
425 21 : long offset, whence = PHP_OCI_SEEK_SET;
426 : ub4 lob_length;
427 :
428 21 : if (getThis()) {
429 18 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &offset, &whence) == FAILURE) {
430 1 : return;
431 : }
432 : }
433 : else {
434 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol|l", &z_descriptor, oci_lob_class_entry_ptr, &offset, &whence) == FAILURE) {
435 2 : return;
436 : }
437 : }
438 :
439 18 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
440 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
441 0 : RETURN_FALSE;
442 : }
443 :
444 18 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
445 :
446 :
447 18 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
448 0 : RETURN_FALSE;
449 : }
450 :
451 18 : switch(whence) {
452 : case PHP_OCI_SEEK_CUR:
453 6 : descriptor->lob_current_position += offset;
454 6 : break;
455 : case PHP_OCI_SEEK_END:
456 2 : if (descriptor->lob_size + offset >= 0) {
457 2 : descriptor->lob_current_position = descriptor->lob_size + offset;
458 : }
459 : else {
460 0 : descriptor->lob_current_position = 0;
461 : }
462 2 : break;
463 : case PHP_OCI_SEEK_SET:
464 : default:
465 10 : descriptor->lob_current_position = (offset > 0) ? offset : 0;
466 : break;
467 : }
468 :
469 18 : RETURN_TRUE;
470 : }
471 : /* }}} */
472 :
473 : /* {{{ proto int oci_lob_size()
474 : Returns size of a large object */
475 : PHP_FUNCTION(oci_lob_size)
476 211 : {
477 211 : zval **tmp, *z_descriptor = getThis();
478 : php_oci_descriptor *descriptor;
479 : ub4 lob_length;
480 :
481 211 : if (!getThis()) {
482 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
483 2 : return;
484 : }
485 : }
486 :
487 209 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
488 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
489 1 : RETURN_FALSE;
490 : }
491 :
492 208 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
493 :
494 208 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
495 0 : RETURN_FALSE;
496 : }
497 208 : RETURN_LONG(lob_length);
498 : }
499 : /* }}} */
500 :
501 : /* {{{ proto int oci_lob_write( string string [, int length ])
502 : Writes data to current position of a LOB */
503 : PHP_FUNCTION(oci_lob_write)
504 71 : {
505 71 : zval **tmp, *z_descriptor = getThis();
506 : php_oci_descriptor *descriptor;
507 : int data_len;
508 71 : long write_len = 0;
509 : ub4 bytes_written;
510 : char *data;
511 :
512 71 : if (getThis()) {
513 68 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &write_len) == FAILURE) {
514 1 : return;
515 : }
516 :
517 67 : if (ZEND_NUM_ARGS() == 2) {
518 3 : data_len = MIN(data_len, write_len);
519 : }
520 : }
521 : else {
522 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &write_len) == FAILURE) {
523 1 : return;
524 : }
525 :
526 2 : if (ZEND_NUM_ARGS() == 3) {
527 0 : data_len = MIN(data_len, write_len);
528 : }
529 : }
530 :
531 69 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
532 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
533 0 : RETURN_FALSE;
534 : }
535 :
536 69 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
537 :
538 67 : if (data_len <= 0) {
539 1 : RETURN_LONG(0);
540 : }
541 :
542 66 : if (php_oci_lob_write(descriptor, descriptor->lob_current_position, data, data_len, &bytes_written TSRMLS_CC)) {
543 1 : RETURN_FALSE;
544 : }
545 65 : RETURN_LONG(bytes_written);
546 : }
547 : /* }}} */
548 :
549 : /* {{{ proto bool oci_lob_append( object lob )
550 : Appends data from a LOB to another LOB */
551 : PHP_FUNCTION(oci_lob_append)
552 5 : {
553 5 : zval **tmp_dest, **tmp_from, *z_descriptor_dest = getThis(), *z_descriptor_from;
554 : php_oci_descriptor *descriptor_dest, *descriptor_from;
555 :
556 5 : if (getThis()) {
557 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) {
558 0 : return;
559 : }
560 : }
561 : else {
562 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) {
563 3 : return;
564 : }
565 : }
566 :
567 2 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) {
568 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
569 0 : RETURN_FALSE;
570 : }
571 :
572 2 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) {
573 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
574 0 : RETURN_FALSE;
575 : }
576 :
577 2 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest);
578 2 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from);
579 :
580 2 : if (php_oci_lob_append(descriptor_dest, descriptor_from TSRMLS_CC)) {
581 0 : RETURN_FALSE;
582 : }
583 : /* XXX should we increase lob_size here ? */
584 2 : RETURN_TRUE;
585 : }
586 : /* }}} */
587 :
588 : /* {{{ proto bool oci_lob_truncate( [ int length ])
589 : Truncates a LOB */
590 : PHP_FUNCTION(oci_lob_truncate)
591 14 : {
592 14 : zval **tmp, *z_descriptor = getThis();
593 : php_oci_descriptor *descriptor;
594 14 : long trim_length = 0;
595 : ub4 ub_trim_length;
596 :
597 14 : if (getThis()) {
598 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &trim_length) == FAILURE) {
599 0 : return;
600 : }
601 : }
602 : else {
603 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &z_descriptor, oci_lob_class_entry_ptr, &trim_length) == FAILURE) {
604 1 : return;
605 : }
606 : }
607 :
608 13 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
609 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
610 0 : RETURN_FALSE;
611 : }
612 :
613 13 : if (trim_length < 0) {
614 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to zero");
615 3 : RETURN_FALSE;
616 : }
617 :
618 10 : ub_trim_length = (ub4) trim_length;
619 10 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
620 :
621 10 : if (php_oci_lob_truncate(descriptor, ub_trim_length TSRMLS_CC)) {
622 1 : RETURN_FALSE;
623 : }
624 9 : RETURN_TRUE;
625 : }
626 : /* }}} */
627 :
628 : /* {{{ proto int oci_lob_erase( [ int offset [, int length ] ] )
629 : Erases a specified portion of the internal LOB, starting at a specified offset */
630 : PHP_FUNCTION(oci_lob_erase)
631 15 : {
632 15 : zval **tmp, *z_descriptor = getThis();
633 : php_oci_descriptor *descriptor;
634 : ub4 bytes_erased;
635 15 : long offset = -1, length = -1;
636 :
637 15 : if (getThis()) {
638 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &offset, &length) == FAILURE) {
639 1 : return;
640 : }
641 :
642 7 : if (ZEND_NUM_ARGS() > 0 && offset < 0) {
643 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be greater than or equal to 0");
644 2 : RETURN_FALSE;
645 : }
646 :
647 5 : if (ZEND_NUM_ARGS() > 1 && length < 0) {
648 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to 0");
649 1 : RETURN_FALSE;
650 : }
651 : }
652 : else {
653 7 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) {
654 2 : return;
655 : }
656 :
657 5 : if (ZEND_NUM_ARGS() > 1 && offset < 0) {
658 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be greater than or equal to 0");
659 2 : RETURN_FALSE;
660 : }
661 :
662 3 : if (ZEND_NUM_ARGS() > 2 && length < 0) {
663 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to 0");
664 1 : RETURN_FALSE;
665 : }
666 : }
667 :
668 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
669 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
670 1 : RETURN_FALSE;
671 : }
672 :
673 5 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
674 :
675 5 : if (php_oci_lob_erase(descriptor, offset, length, &bytes_erased TSRMLS_CC)) {
676 2 : RETURN_FALSE;
677 : }
678 3 : RETURN_LONG(bytes_erased);
679 : }
680 : /* }}} */
681 :
682 : /* {{{ proto bool oci_lob_flush( [ int flag ] )
683 : Flushes the LOB buffer */
684 : PHP_FUNCTION(oci_lob_flush)
685 9 : {
686 9 : zval **tmp, *z_descriptor = getThis();
687 : php_oci_descriptor *descriptor;
688 9 : long flush_flag = 0;
689 :
690 9 : if (getThis()) {
691 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flush_flag) == FAILURE) {
692 0 : return;
693 : }
694 : }
695 : else {
696 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &z_descriptor, oci_lob_class_entry_ptr, &flush_flag) == FAILURE) {
697 1 : return;
698 : }
699 : }
700 :
701 8 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
702 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
703 0 : RETURN_FALSE;
704 : }
705 :
706 8 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
707 :
708 8 : if (descriptor->buffering == PHP_OCI_LOB_BUFFER_DISABLED) {
709 : /* buffering wasn't enabled, there is nothing to flush */
710 4 : RETURN_FALSE;
711 : }
712 :
713 4 : if (php_oci_lob_flush(descriptor, flush_flag TSRMLS_CC)) {
714 1 : RETURN_FALSE;
715 : }
716 3 : RETURN_TRUE;
717 : }
718 : /* }}} */
719 :
720 : /* {{{ proto bool ocisetbufferinglob( boolean flag )
721 : Enables/disables buffering for a LOB */
722 : PHP_FUNCTION(ocisetbufferinglob)
723 7 : {
724 7 : zval **tmp, *z_descriptor = getThis();
725 : php_oci_descriptor *descriptor;
726 : zend_bool flag;
727 :
728 7 : if (getThis()) {
729 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &flag) == FAILURE) {
730 0 : return;
731 : }
732 : }
733 : else {
734 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ob", &z_descriptor, oci_lob_class_entry_ptr, &flag) == FAILURE) {
735 1 : return;
736 : }
737 : }
738 :
739 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
740 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
741 0 : RETURN_FALSE;
742 : }
743 :
744 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
745 :
746 6 : if (php_oci_lob_set_buffering(descriptor, flag TSRMLS_CC)) {
747 0 : RETURN_FALSE;
748 : }
749 6 : RETURN_TRUE;
750 : }
751 : /* }}} */
752 :
753 : /* {{{ proto bool ocigetbufferinglob()
754 : Returns current state of buffering for a LOB */
755 : PHP_FUNCTION(ocigetbufferinglob)
756 4 : {
757 4 : zval **tmp, *z_descriptor = getThis();
758 : php_oci_descriptor *descriptor;
759 :
760 4 : if (!getThis()) {
761 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
762 1 : return;
763 : }
764 : }
765 :
766 3 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
767 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
768 0 : RETURN_FALSE;
769 : }
770 :
771 3 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
772 :
773 3 : if (descriptor->buffering != PHP_OCI_LOB_BUFFER_DISABLED) {
774 1 : RETURN_TRUE;
775 : }
776 2 : RETURN_FALSE;
777 : }
778 : /* }}} */
779 :
780 : /* {{{ proto bool oci_lob_copy( object lob_to, object lob_from [, int length ] )
781 : Copies data from a LOB to another LOB */
782 : PHP_FUNCTION(oci_lob_copy)
783 6 : {
784 : zval **tmp_dest, **tmp_from, *z_descriptor_dest, *z_descriptor_from;
785 : php_oci_descriptor *descriptor_dest, *descriptor_from;
786 6 : long length = 0;
787 :
788 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO|l", &z_descriptor_dest, oci_lob_class_entry_ptr, &z_descriptor_from, oci_lob_class_entry_ptr, &length) == FAILURE) {
789 0 : return;
790 : }
791 :
792 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) {
793 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
794 0 : RETURN_FALSE;
795 : }
796 :
797 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) {
798 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
799 0 : RETURN_FALSE;
800 : }
801 :
802 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest);
803 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from);
804 :
805 6 : if (ZEND_NUM_ARGS() == 3 && length < 0) {
806 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
807 1 : RETURN_FALSE;
808 : }
809 :
810 5 : if (ZEND_NUM_ARGS() == 2) {
811 : /* indicate that we want to copy from the current position to the end of the LOB */
812 3 : length = -1;
813 : }
814 :
815 5 : if (php_oci_lob_copy(descriptor_dest, descriptor_from, length TSRMLS_CC)) {
816 3 : RETURN_FALSE;
817 : }
818 2 : RETURN_TRUE;
819 : }
820 : /* }}} */
821 :
822 : /* {{{ proto bool oci_lob_is_equal( object lob1, object lob2 )
823 : Tests to see if two LOB/FILE locators are equal */
824 : PHP_FUNCTION(oci_lob_is_equal)
825 1 : {
826 : zval **tmp_first, **tmp_second, *z_descriptor_first, *z_descriptor_second;
827 : php_oci_descriptor *descriptor_first, *descriptor_second;
828 : boolean is_equal;
829 :
830 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_descriptor_first, oci_lob_class_entry_ptr, &z_descriptor_second, oci_lob_class_entry_ptr) == FAILURE) {
831 0 : return;
832 : }
833 :
834 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_first), "descriptor", sizeof("descriptor"), (void **)&tmp_first) == FAILURE) {
835 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
836 0 : RETURN_FALSE;
837 : }
838 :
839 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_second), "descriptor", sizeof("descriptor"), (void **)&tmp_second) == FAILURE) {
840 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
841 0 : RETURN_FALSE;
842 : }
843 :
844 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_first, descriptor_first);
845 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_second, descriptor_second);
846 :
847 1 : if (php_oci_lob_is_equal(descriptor_first, descriptor_second, &is_equal TSRMLS_CC)) {
848 0 : RETURN_FALSE;
849 : }
850 :
851 1 : if (is_equal == TRUE) {
852 1 : RETURN_TRUE;
853 : }
854 0 : RETURN_FALSE;
855 : }
856 : /* }}} */
857 :
858 : /* {{{ proto bool oci_lob_export([string filename [, int start [, int length]]])
859 : Writes a large object into a file */
860 : PHP_FUNCTION(oci_lob_export)
861 4 : {
862 4 : zval **tmp, *z_descriptor = getThis();
863 : php_oci_descriptor *descriptor;
864 : char *filename, *buffer;
865 : int filename_len;
866 4 : long start = -1, length = -1, block_length;
867 : php_stream *stream;
868 : ub4 lob_length;
869 :
870 4 : if (getThis()) {
871 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &filename, &filename_len, &start, &length) == FAILURE) {
872 0 : return;
873 : }
874 :
875 1 : if (ZEND_NUM_ARGS() > 1 && start < 0) {
876 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0");
877 0 : RETURN_FALSE;
878 : }
879 1 : if (ZEND_NUM_ARGS() > 2 && length < 0) {
880 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than or equal to 0");
881 0 : RETURN_FALSE;
882 : }
883 : }
884 : else {
885 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|ll", &z_descriptor, oci_lob_class_entry_ptr, &filename, &filename_len, &start, &length) == FAILURE) {
886 3 : return;
887 : }
888 :
889 0 : if (ZEND_NUM_ARGS() > 2 && start < 0) {
890 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0");
891 0 : RETURN_FALSE;
892 : }
893 0 : if (ZEND_NUM_ARGS() > 3 && length < 0) {
894 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than or equal to 0");
895 0 : RETURN_FALSE;
896 : }
897 : }
898 :
899 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
900 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
901 0 : RETURN_FALSE;
902 : }
903 :
904 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
905 :
906 1 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
907 0 : RETURN_FALSE;
908 : }
909 :
910 1 : if (start == -1) {
911 0 : start = 0;
912 : }
913 :
914 1 : if (length == -1) {
915 0 : length = lob_length - descriptor->lob_current_position;
916 : }
917 :
918 1 : if (length == 0) {
919 : /* nothing to write, fail silently */
920 0 : RETURN_FALSE;
921 : }
922 :
923 1 : if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
924 0 : RETURN_FALSE;
925 : }
926 :
927 1 : if (php_check_open_basedir(filename TSRMLS_CC)) {
928 0 : RETURN_FALSE;
929 : }
930 :
931 1 : stream = php_stream_open_wrapper_ex(filename, "w", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, NULL);
932 :
933 1 : block_length = PHP_OCI_LOB_BUFFER_SIZE;
934 1 : if (block_length > length) {
935 1 : block_length = length;
936 : }
937 :
938 3 : while(length > 0) {
939 1 : ub4 tmp_bytes_read = 0;
940 1 : if (php_oci_lob_read(descriptor, block_length, start, &buffer, &tmp_bytes_read TSRMLS_CC)) {
941 0 : php_stream_close(stream);
942 0 : RETURN_FALSE;
943 : }
944 1 : if (tmp_bytes_read && !php_stream_write(stream, buffer, tmp_bytes_read)) {
945 0 : php_stream_close(stream);
946 0 : efree(buffer);
947 0 : RETURN_FALSE;
948 : }
949 1 : if (buffer) {
950 1 : efree(buffer);
951 : }
952 :
953 1 : length -= tmp_bytes_read;
954 1 : descriptor->lob_current_position += tmp_bytes_read;
955 1 : start += tmp_bytes_read;
956 :
957 1 : if (block_length > length) {
958 1 : block_length = length;
959 : }
960 : }
961 :
962 1 : php_stream_close(stream);
963 1 : RETURN_TRUE;
964 : }
965 : /* }}} */
966 :
967 : #ifdef HAVE_OCI8_TEMP_LOB
968 : /* {{{ proto bool oci_lob_write_temporary(string var [, int lob_type])
969 : Writes temporary blob */
970 : PHP_FUNCTION(oci_lob_write_temporary)
971 113 : {
972 113 : zval **tmp, *z_descriptor = getThis();
973 : php_oci_descriptor *descriptor;
974 : char *data;
975 : int data_len;
976 113 : long type = OCI_TEMP_CLOB;
977 :
978 113 : if (getThis()) {
979 113 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &type) == FAILURE) {
980 0 : return;
981 : }
982 : }
983 : else {
984 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &type) == FAILURE) {
985 0 : return;
986 : }
987 : }
988 :
989 113 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
990 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
991 0 : RETURN_FALSE;
992 : }
993 :
994 113 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
995 :
996 113 : if (php_oci_lob_write_tmp(descriptor, type, data, data_len TSRMLS_CC)) {
997 1 : RETURN_FALSE;
998 : }
999 112 : RETURN_TRUE;
1000 : }
1001 : /* }}} */
1002 :
1003 : /* {{{ proto bool oci_lob_close()
1004 : Closes lob descriptor */
1005 : PHP_FUNCTION(oci_lob_close)
1006 113 : {
1007 113 : zval **tmp, *z_descriptor = getThis();
1008 : php_oci_descriptor *descriptor;
1009 :
1010 113 : if (!getThis()) {
1011 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
1012 0 : return;
1013 : }
1014 : }
1015 :
1016 113 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
1017 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
1018 0 : RETURN_FALSE;
1019 : }
1020 :
1021 113 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
1022 :
1023 113 : if (php_oci_lob_close(descriptor TSRMLS_CC)) {
1024 0 : RETURN_FALSE;
1025 : }
1026 113 : RETURN_TRUE;
1027 : }
1028 : /* }}} */
1029 : #endif
1030 :
1031 : /* {{{ proto object oci_new_descriptor(resource connection [, int type])
1032 : Initialize a new empty descriptor LOB/FILE (LOB is default) */
1033 : PHP_FUNCTION(oci_new_descriptor)
1034 196 : {
1035 : zval *z_connection;
1036 : php_oci_connection *connection;
1037 : php_oci_descriptor *descriptor;
1038 196 : long type = OCI_DTYPE_LOB;
1039 :
1040 196 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &z_connection, &type) == FAILURE) {
1041 2 : return;
1042 : }
1043 :
1044 194 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1045 :
1046 : /* php_oci_lob_create() checks type */
1047 194 : descriptor = php_oci_lob_create(connection, type TSRMLS_CC);
1048 :
1049 194 : if (!descriptor) {
1050 4 : RETURN_NULL();
1051 : }
1052 :
1053 190 : object_init_ex(return_value, oci_lob_class_entry_ptr);
1054 190 : add_property_resource(return_value, "descriptor", descriptor->id);
1055 : }
1056 : /* }}} */
1057 :
1058 : /* {{{ proto bool oci_rollback(resource connection)
1059 : Rollback the current context */
1060 : PHP_FUNCTION(oci_rollback)
1061 5 : {
1062 : zval *z_connection;
1063 : php_oci_connection *connection;
1064 :
1065 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1066 1 : return;
1067 : }
1068 :
1069 4 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1070 :
1071 4 : if (connection->descriptors) {
1072 1 : zend_hash_destroy(connection->descriptors);
1073 1 : efree(connection->descriptors);
1074 1 : connection->descriptors = NULL;
1075 : }
1076 :
1077 4 : if (php_oci_connection_rollback(connection TSRMLS_CC)) {
1078 0 : RETURN_FALSE;
1079 : }
1080 4 : RETURN_TRUE;
1081 : }
1082 : /* }}} */
1083 :
1084 : /* {{{ proto bool oci_commit(resource connection)
1085 : Commit the current context */
1086 : PHP_FUNCTION(oci_commit)
1087 98 : {
1088 : zval *z_connection;
1089 : php_oci_connection *connection;
1090 :
1091 98 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1092 1 : return;
1093 : }
1094 :
1095 97 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1096 :
1097 97 : if (connection->descriptors) {
1098 52 : zend_hash_destroy(connection->descriptors);
1099 52 : efree(connection->descriptors);
1100 52 : connection->descriptors = NULL;
1101 : }
1102 :
1103 97 : if (php_oci_connection_commit(connection TSRMLS_CC)) {
1104 0 : RETURN_FALSE;
1105 : }
1106 97 : RETURN_TRUE;
1107 : }
1108 : /* }}} */
1109 :
1110 : /* {{{ proto string oci_field_name(resource stmt, int col)
1111 : Tell the name of a column */
1112 : PHP_FUNCTION(oci_field_name)
1113 41 : {
1114 : php_oci_out_column *column;
1115 :
1116 41 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1117 36 : RETURN_STRINGL(column->name, column->name_len, 1);
1118 : }
1119 5 : RETURN_FALSE;
1120 : }
1121 : /* }}} */
1122 :
1123 : /* {{{ proto int oci_field_size(resource stmt, int col)
1124 : Tell the maximum data size of a column */
1125 : PHP_FUNCTION(oci_field_size)
1126 25 : {
1127 : php_oci_out_column *column;
1128 :
1129 25 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1130 : /* Handle data type of LONG */
1131 19 : if (column->data_type == SQLT_LNG){
1132 0 : RETURN_LONG(column->storage_size4);
1133 : }
1134 19 : RETURN_LONG(column->data_size);
1135 : }
1136 6 : RETURN_FALSE;
1137 : }
1138 : /* }}} */
1139 :
1140 : /* {{{ proto int oci_field_scale(resource stmt, int col)
1141 : Tell the scale of a column */
1142 : PHP_FUNCTION(oci_field_scale)
1143 40 : {
1144 : php_oci_out_column *column;
1145 :
1146 40 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1147 35 : RETURN_LONG(column->scale);
1148 : }
1149 5 : RETURN_FALSE;
1150 : }
1151 : /* }}} */
1152 :
1153 : /* {{{ proto int oci_field_precision(resource stmt, int col)
1154 : Tell the precision of a column */
1155 : PHP_FUNCTION(oci_field_precision)
1156 40 : {
1157 : php_oci_out_column *column;
1158 :
1159 40 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1160 35 : RETURN_LONG(column->precision);
1161 : }
1162 5 : RETURN_FALSE;
1163 : }
1164 : /* }}} */
1165 :
1166 : /* {{{ proto mixed oci_field_type(resource stmt, int col)
1167 : Tell the data type of a column */
1168 : PHP_FUNCTION(oci_field_type)
1169 25 : {
1170 : php_oci_out_column *column;
1171 :
1172 25 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
1173 :
1174 25 : if (!column) {
1175 5 : RETURN_FALSE;
1176 : }
1177 :
1178 20 : switch (column->data_type) {
1179 : #ifdef SQLT_TIMESTAMP
1180 : case SQLT_TIMESTAMP:
1181 2 : RETVAL_STRING("TIMESTAMP",1);
1182 2 : break;
1183 : #endif
1184 : #ifdef SQLT_TIMESTAMP_TZ
1185 : case SQLT_TIMESTAMP_TZ:
1186 2 : RETVAL_STRING("TIMESTAMP WITH TIMEZONE",1);
1187 2 : break;
1188 : #endif
1189 : #ifdef SQLT_TIMESTAMP_LTZ
1190 : case SQLT_TIMESTAMP_LTZ:
1191 1 : RETVAL_STRING("TIMESTAMP WITH LOCAL TIMEZONE",1);
1192 1 : break;
1193 : #endif
1194 : #ifdef SQLT_INTERVAL_YM
1195 : case SQLT_INTERVAL_YM:
1196 2 : RETVAL_STRING("INTERVAL YEAR TO MONTH",1);
1197 2 : break;
1198 : #endif
1199 : #ifdef SQLT_INTERVAL_DS
1200 : case SQLT_INTERVAL_DS:
1201 2 : RETVAL_STRING("INTERVAL DAY TO SECOND",1);
1202 2 : break;
1203 : #endif
1204 : case SQLT_DAT:
1205 0 : RETVAL_STRING("DATE",1);
1206 0 : break;
1207 : case SQLT_NUM:
1208 4 : RETVAL_STRING("NUMBER",1);
1209 4 : break;
1210 : case SQLT_LNG:
1211 0 : RETVAL_STRING("LONG",1);
1212 0 : break;
1213 : case SQLT_BIN:
1214 0 : RETVAL_STRING("RAW",1);
1215 0 : break;
1216 : case SQLT_LBI:
1217 0 : RETVAL_STRING("LONG RAW",1);
1218 0 : break;
1219 : case SQLT_CHR:
1220 2 : RETVAL_STRING("VARCHAR2",1);
1221 2 : break;
1222 : case SQLT_RSET:
1223 0 : RETVAL_STRING("REFCURSOR",1);
1224 0 : break;
1225 : case SQLT_AFC:
1226 1 : RETVAL_STRING("CHAR",1);
1227 1 : break;
1228 : case SQLT_BLOB:
1229 2 : RETVAL_STRING("BLOB",1);
1230 2 : break;
1231 : case SQLT_CLOB:
1232 2 : RETVAL_STRING("CLOB",1);
1233 2 : break;
1234 : case SQLT_BFILE:
1235 0 : RETVAL_STRING("BFILE",1);
1236 0 : break;
1237 : case SQLT_RDD:
1238 0 : RETVAL_STRING("ROWID",1);
1239 0 : break;
1240 : default:
1241 0 : RETVAL_LONG(column->data_type);
1242 : }
1243 : }
1244 : /* }}} */
1245 :
1246 : /* {{{ proto int oci_field_type_raw(resource stmt, int col)
1247 : Tell the raw oracle data type of a column */
1248 : PHP_FUNCTION(oci_field_type_raw)
1249 24 : {
1250 : php_oci_out_column *column;
1251 :
1252 24 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
1253 24 : if (column) {
1254 19 : RETURN_LONG(column->data_type);
1255 : }
1256 5 : RETURN_FALSE;
1257 : }
1258 : /* }}} */
1259 :
1260 : /* {{{ proto bool oci_field_is_null(resource stmt, int col)
1261 : Tell whether a column is NULL */
1262 : PHP_FUNCTION(oci_field_is_null)
1263 24 : {
1264 : php_oci_out_column *column;
1265 :
1266 24 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1267 19 : if (column->indicator == -1) {
1268 6 : RETURN_TRUE;
1269 : }
1270 : }
1271 18 : RETURN_FALSE;
1272 : }
1273 : /* }}} */
1274 :
1275 : /* {{{ proto void oci_internal_debug(int onoff)
1276 : Toggle internal debugging output for the OCI extension */
1277 : PHP_FUNCTION(oci_internal_debug)
1278 2 : {
1279 : zend_bool on_off;
1280 :
1281 2 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &on_off) == FAILURE) {
1282 1 : return;
1283 : }
1284 1 : OCI_G(debug_mode) = on_off;
1285 : }
1286 : /* }}} */
1287 :
1288 : /* {{{ proto bool oci_execute(resource stmt [, int mode])
1289 : Execute a parsed statement */
1290 : PHP_FUNCTION(oci_execute)
1291 34738 : {
1292 : zval *z_statement;
1293 : php_oci_statement *statement;
1294 34738 : long mode = OCI_COMMIT_ON_SUCCESS;
1295 :
1296 34738 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &z_statement, &mode) == FAILURE) {
1297 1 : return;
1298 : }
1299 :
1300 34737 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1301 :
1302 34737 : if (php_oci_statement_execute(statement, mode TSRMLS_CC)) {
1303 160 : RETURN_FALSE;
1304 : }
1305 34577 : RETURN_TRUE;
1306 : }
1307 : /* }}} */
1308 :
1309 : /* {{{ proto bool oci_cancel(resource stmt)
1310 : Cancel reading from a cursor */
1311 : PHP_FUNCTION(oci_cancel)
1312 5 : {
1313 : zval *z_statement;
1314 : php_oci_statement *statement;
1315 :
1316 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1317 1 : return;
1318 : }
1319 :
1320 4 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1321 :
1322 4 : if (php_oci_statement_cancel(statement TSRMLS_CC)) {
1323 0 : RETURN_FALSE;
1324 : }
1325 4 : RETURN_TRUE;
1326 : }
1327 : /* }}} */
1328 :
1329 : /* {{{ proto bool oci_fetch(resource stmt)
1330 : Prepare a new row of data for reading */
1331 : PHP_FUNCTION(oci_fetch)
1332 95 : {
1333 : zval *z_statement;
1334 : php_oci_statement *statement;
1335 95 : ub4 nrows = 1; /* only one row at a time is supported for now */
1336 :
1337 95 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1338 1 : return;
1339 : }
1340 :
1341 94 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1342 :
1343 94 : if (php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1344 28 : RETURN_FALSE;
1345 : }
1346 66 : RETURN_TRUE;
1347 : }
1348 : /* }}} */
1349 :
1350 : /* {{{ proto int ocifetchinto(resource stmt, array &output [, int mode])
1351 : Fetch a row of result data into an array */
1352 : PHP_FUNCTION(ocifetchinto)
1353 6625 : {
1354 6625 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM, 3);
1355 6625 : }
1356 : /* }}} */
1357 :
1358 : /* {{{ proto int oci_fetch_all(resource stmt, array &output[, int skip[, int maxrows[, int flags]]])
1359 : Fetch all rows of result data into an array */
1360 : PHP_FUNCTION(oci_fetch_all)
1361 60 : {
1362 : zval *z_statement, *array, *element, *tmp;
1363 : php_oci_statement *statement;
1364 : php_oci_out_column **columns;
1365 : zval ***outarrs;
1366 60 : ub4 nrows = 1;
1367 : int i;
1368 60 : long rows = 0, flags = 0, skip = 0, maxrows = -1;
1369 :
1370 60 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/|lll", &z_statement, &array, &skip, &maxrows, &flags) == FAILURE) {
1371 1 : return;
1372 : }
1373 :
1374 59 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1375 :
1376 59 : zval_dtor(array);
1377 59 : array_init(array);
1378 :
1379 59 : while (skip--) {
1380 4 : if (php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1381 1 : RETURN_LONG(0);
1382 : }
1383 : }
1384 :
1385 58 : if (flags & PHP_OCI_FETCHSTATEMENT_BY_ROW) {
1386 10 : columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
1387 :
1388 36 : for (i = 0; i < statement->ncolumns; i++) {
1389 26 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1390 : }
1391 :
1392 56 : while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1393 : zval *row;
1394 :
1395 37 : MAKE_STD_ZVAL(row);
1396 37 : array_init(row);
1397 :
1398 126 : for (i = 0; i < statement->ncolumns; i++) {
1399 89 : MAKE_STD_ZVAL(element);
1400 89 : php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC);
1401 :
1402 89 : if (flags & PHP_OCI_NUM) {
1403 42 : zend_hash_next_index_insert(Z_ARRVAL_P(row), &element, sizeof(zval*), NULL);
1404 : } else { /* default to ASSOC */
1405 47 : zend_hash_update(Z_ARRVAL_P(row), columns[ i ]->name, columns[ i ]->name_len+1, &element, sizeof(zval*), NULL);
1406 : }
1407 : }
1408 :
1409 37 : zend_hash_next_index_insert(Z_ARRVAL_P(array), &row, sizeof(zval*), NULL);
1410 37 : rows++;
1411 :
1412 37 : if (maxrows != -1 && rows == maxrows) {
1413 1 : php_oci_statement_cancel(statement TSRMLS_CC);
1414 1 : break;
1415 : }
1416 : }
1417 10 : efree(columns);
1418 :
1419 : } else { /* default to BY_COLUMN */
1420 48 : columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
1421 48 : outarrs = safe_emalloc(statement->ncolumns, sizeof(zval*), 0);
1422 :
1423 48 : if (flags & PHP_OCI_NUM) {
1424 24 : for (i = 0; i < statement->ncolumns; i++) {
1425 18 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1426 :
1427 18 : MAKE_STD_ZVAL(tmp);
1428 18 : array_init(tmp);
1429 18 : zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
1430 : }
1431 : } else { /* default to ASSOC */
1432 125 : for (i = 0; i < statement->ncolumns; i++) {
1433 83 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1434 :
1435 83 : MAKE_STD_ZVAL(tmp);
1436 83 : array_init(tmp);
1437 83 : zend_hash_update(Z_ARRVAL_P(array), columns[ i ]->name, columns[ i ]->name_len+1, (void *) &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
1438 : }
1439 : }
1440 :
1441 198 : while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1442 351 : for (i = 0; i < statement->ncolumns; i++) {
1443 247 : MAKE_STD_ZVAL(element);
1444 247 : php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC);
1445 247 : zend_hash_index_update((*(outarrs[ i ]))->value.ht, rows, (void *)&element, sizeof(zval*), NULL);
1446 : }
1447 :
1448 104 : rows++;
1449 :
1450 104 : if (maxrows != -1 && rows == maxrows) {
1451 2 : php_oci_statement_cancel(statement TSRMLS_CC);
1452 2 : break;
1453 : }
1454 : }
1455 :
1456 48 : efree(columns);
1457 48 : efree(outarrs);
1458 : }
1459 :
1460 58 : RETURN_LONG(rows);
1461 : }
1462 : /* }}} */
1463 :
1464 : /* {{{ proto object oci_fetch_object( resource stmt )
1465 : Fetch a result row as an object */
1466 : PHP_FUNCTION(oci_fetch_object)
1467 4 : {
1468 4 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 2);
1469 :
1470 4 : if (Z_TYPE_P(return_value) == IS_ARRAY) {
1471 3 : object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value));
1472 : }
1473 4 : }
1474 : /* }}} */
1475 :
1476 : /* {{{ proto array oci_fetch_row( resource stmt )
1477 : Fetch a result row as an enumerated array */
1478 : PHP_FUNCTION(oci_fetch_row)
1479 13 : {
1480 13 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM | PHP_OCI_RETURN_NULLS, 1);
1481 13 : }
1482 : /* }}} */
1483 :
1484 : /* {{{ proto array oci_fetch_assoc( resource stmt )
1485 : Fetch a result row as an associative array */
1486 : PHP_FUNCTION(oci_fetch_assoc)
1487 120065 : {
1488 120065 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 1);
1489 120065 : }
1490 : /* }}} */
1491 :
1492 : /* {{{ proto array oci_fetch_array( resource stmt [, int mode ])
1493 : Fetch a result row as an array */
1494 : PHP_FUNCTION(oci_fetch_array)
1495 4541 : {
1496 4541 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_BOTH | PHP_OCI_RETURN_NULLS, 2);
1497 4541 : }
1498 : /* }}} */
1499 :
1500 : /* {{{ proto bool oci_free_statement(resource stmt)
1501 : Free all resources associated with a statement */
1502 : PHP_FUNCTION(oci_free_statement)
1503 32150 : {
1504 : zval *z_statement;
1505 : php_oci_statement *statement;
1506 :
1507 32150 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1508 3 : return;
1509 : }
1510 :
1511 32147 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1512 :
1513 32147 : zend_list_delete(statement->id);
1514 32147 : RETURN_TRUE;
1515 : }
1516 : /* }}} */
1517 :
1518 : /* {{{ proto bool oci_close(resource connection)
1519 : Disconnect from database */
1520 : PHP_FUNCTION(oci_close)
1521 47 : {
1522 : zval *z_connection;
1523 : php_oci_connection *connection;
1524 :
1525 47 : if (OCI_G(old_oci_close_semantics)) {
1526 : /* do nothing to keep BC */
1527 8 : return;
1528 : }
1529 :
1530 39 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1531 1 : return;
1532 : }
1533 :
1534 38 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1535 38 : zend_list_delete(connection->rsrc_id);
1536 38 : ZVAL_NULL(z_connection);
1537 :
1538 38 : RETURN_TRUE;
1539 : }
1540 : /* }}} */
1541 :
1542 : /* {{{ proto resource oci_new_connect(string user, string pass [, string db])
1543 : Connect to an Oracle database and log on. Returns a new session. */
1544 : PHP_FUNCTION(oci_new_connect)
1545 29 : {
1546 29 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
1547 29 : }
1548 : /* }}} */
1549 :
1550 : /* {{{ proto resource oci_connect(string user, string pass [, string db [, string charset [, int session_mode ]])
1551 : Connect to an Oracle database and log on. Returns a new session. */
1552 : PHP_FUNCTION(oci_connect)
1553 252 : {
1554 252 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
1555 252 : }
1556 : /* }}} */
1557 :
1558 : /* {{{ proto resource oci_pconnect(string user, string pass [, string db [, string charset ]])
1559 : Connect to an Oracle database using a persistent connection and log on. Returns a new session. */
1560 : PHP_FUNCTION(oci_pconnect)
1561 38 : {
1562 38 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
1563 38 : }
1564 : /* }}} */
1565 :
1566 : /* {{{ proto array oci_error([resource stmt|connection|global])
1567 : Return the last error of stmt|connection|global. If no error happened returns false. */
1568 : PHP_FUNCTION(oci_error)
1569 24 : {
1570 : zval *arg;
1571 : php_oci_statement *statement;
1572 : php_oci_connection *connection;
1573 : text *errbuf;
1574 24 : sb4 errcode = 0;
1575 24 : sword error = OCI_SUCCESS;
1576 24 : dvoid *errh = NULL;
1577 : #ifdef HAVE_OCI8_ATTR_STATEMENT
1578 24 : ub2 error_offset = 0;
1579 24 : text *sqltext = NULL;
1580 : #endif
1581 :
1582 24 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg) == FAILURE) {
1583 0 : return;
1584 : }
1585 :
1586 24 : if (ZEND_NUM_ARGS() > 0) {
1587 21 : statement = (php_oci_statement *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_statement);
1588 :
1589 21 : if (statement) {
1590 9 : errh = statement->err;
1591 9 : error = statement->errcode;
1592 :
1593 : #ifdef HAVE_OCI8_ATTR_STATEMENT
1594 9 : if (php_oci_fetch_sqltext_offset(statement, &sqltext, &error_offset TSRMLS_CC)) {
1595 0 : RETURN_FALSE;
1596 : }
1597 : #endif
1598 9 : goto go_out;
1599 : }
1600 :
1601 12 : connection = (php_oci_connection *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_connection);
1602 12 : if (connection) {
1603 8 : errh = connection->err;
1604 8 : error = connection->errcode;
1605 8 : goto go_out;
1606 : }
1607 :
1608 4 : connection = (php_oci_connection *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_pconnection);
1609 4 : if (connection) {
1610 4 : errh = connection->err;
1611 4 : error = connection->errcode;
1612 4 : goto go_out;
1613 : }
1614 : } else {
1615 3 : errh = OCI_G(err);
1616 3 : error = OCI_G(errcode);
1617 : }
1618 :
1619 24 : go_out:
1620 24 : if (error == OCI_SUCCESS) { /* no error set in the handle */
1621 6 : RETURN_FALSE;
1622 : }
1623 :
1624 18 : if (!errh) {
1625 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "OCIError: unable to find error handle");
1626 0 : RETURN_FALSE;
1627 : }
1628 :
1629 18 : errcode = php_oci_fetch_errmsg(errh, &errbuf TSRMLS_CC);
1630 :
1631 18 : if (errcode) {
1632 18 : array_init(return_value);
1633 18 : add_assoc_long(return_value, "code", errcode);
1634 18 : add_assoc_string(return_value, "message", (char*) errbuf, 0);
1635 : #ifdef HAVE_OCI8_ATTR_STATEMENT
1636 18 : add_assoc_long(return_value, "offset", error_offset);
1637 18 : add_assoc_string(return_value, "sqltext", sqltext ? (char *) sqltext : "", 1);
1638 : #endif
1639 : } else {
1640 0 : RETURN_FALSE;
1641 : }
1642 : }
1643 : /* }}} */
1644 :
1645 : /* {{{ proto int oci_num_fields(resource stmt)
1646 : Return the number of result columns in a statement */
1647 : PHP_FUNCTION(oci_num_fields)
1648 40 : {
1649 : zval *z_statement;
1650 : php_oci_statement *statement;
1651 :
1652 40 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1653 3 : return;
1654 : }
1655 :
1656 37 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1657 :
1658 37 : RETURN_LONG(statement->ncolumns);
1659 : }
1660 : /* }}} */
1661 :
1662 : /* {{{ proto resource oci_parse(resource connection, string query)
1663 : Parse a query and return a statement */
1664 : PHP_FUNCTION(oci_parse)
1665 32425 : {
1666 : zval *z_connection;
1667 : php_oci_connection *connection;
1668 : php_oci_statement *statement;
1669 : char *query;
1670 : int query_len;
1671 :
1672 32425 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &query, &query_len) == FAILURE) {
1673 2 : return;
1674 : }
1675 :
1676 32423 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1677 :
1678 32423 : statement = php_oci_statement_create(connection, query, query_len TSRMLS_CC);
1679 :
1680 32423 : if (statement) {
1681 32420 : RETURN_RESOURCE(statement->id);
1682 : }
1683 3 : RETURN_FALSE;
1684 : }
1685 : /* }}} */
1686 :
1687 : /* {{{ proto bool oci_set_prefetch(resource stmt, int prefetch_rows)
1688 : Sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
1689 : PHP_FUNCTION(oci_set_prefetch)
1690 4 : {
1691 : zval *z_statement;
1692 : php_oci_statement *statement;
1693 : long size;
1694 :
1695 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_statement, &size) == FAILURE) {
1696 1 : return;
1697 : }
1698 :
1699 3 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1700 :
1701 3 : if (php_oci_statement_set_prefetch(statement, size TSRMLS_CC)) {
1702 0 : RETURN_FALSE;
1703 : }
1704 3 : RETURN_TRUE;
1705 : }
1706 : /* }}} */
1707 :
1708 : /* {{{ proto bool oci_password_change(resource connection, string username, string old_password, string new_password)
1709 : Changes the password of an account */
1710 : PHP_FUNCTION(oci_password_change)
1711 8 : {
1712 : zval *z_connection;
1713 : text *user, *pass_old, *pass_new, *dbname;
1714 : int user_len, pass_old_len, pass_new_len, dbname_len;
1715 : php_oci_connection *connection;
1716 :
1717 : /* Disable in Safe Mode */
1718 8 : if (PG(safe_mode)) {
1719 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "is disabled in Safe Mode");
1720 1 : RETURN_FALSE;
1721 : }
1722 :
1723 7 : if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &z_connection, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
1724 2 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1725 :
1726 2 : if (!user_len) {
1727 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "username cannot be empty");
1728 0 : RETURN_FALSE;
1729 : }
1730 2 : if (!pass_old_len) {
1731 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "old password cannot be empty");
1732 0 : RETURN_FALSE;
1733 : }
1734 2 : if (!pass_new_len) {
1735 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "new password cannot be empty");
1736 0 : RETURN_FALSE;
1737 : }
1738 :
1739 2 : if (php_oci_password_change(connection, (char *)user, user_len, (char *)pass_old, pass_old_len, (char *)pass_new, pass_new_len TSRMLS_CC)) {
1740 0 : RETURN_FALSE;
1741 : }
1742 2 : RETURN_TRUE;
1743 5 : } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &dbname, &dbname_len, &user, &user_len, &pass_old, &pass_old_len, &pass_new, &pass_new_len) == SUCCESS) {
1744 :
1745 4 : if (!user_len) {
1746 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "username cannot be empty");
1747 0 : RETURN_FALSE;
1748 : }
1749 4 : if (!pass_old_len) {
1750 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "old password cannot be empty");
1751 0 : RETURN_FALSE;
1752 : }
1753 4 : if (!pass_new_len) {
1754 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "new password cannot be empty");
1755 0 : RETURN_FALSE;
1756 : }
1757 :
1758 4 : connection = php_oci_do_connect_ex((char *)user, user_len, (char *)pass_old, pass_old_len, (char *)pass_new, pass_new_len, (char *)dbname, dbname_len, NULL, OCI_DEFAULT, 0, 0 TSRMLS_CC);
1759 4 : if (!connection) {
1760 0 : RETURN_FALSE;
1761 : }
1762 4 : RETURN_RESOURCE(connection->rsrc_id);
1763 : }
1764 1 : WRONG_PARAM_COUNT;
1765 : }
1766 : /* }}} */
1767 :
1768 : /* {{{ proto resource oci_new_cursor(resource connection)
1769 : Return a new cursor (Statement-Handle) - use this to bind ref-cursors! */
1770 : PHP_FUNCTION(oci_new_cursor)
1771 7 : {
1772 : zval *z_connection;
1773 : php_oci_connection *connection;
1774 : php_oci_statement *statement;
1775 :
1776 7 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1777 1 : return;
1778 : }
1779 :
1780 6 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1781 :
1782 6 : statement = php_oci_statement_create(connection, NULL, 0 TSRMLS_CC);
1783 :
1784 6 : if (statement) {
1785 6 : RETURN_RESOURCE(statement->id);
1786 : }
1787 0 : RETURN_FALSE;
1788 : }
1789 : /* }}} */
1790 :
1791 : /* {{{ proto string oci_result(resource stmt, mixed column)
1792 : Return a single column of result data */
1793 : PHP_FUNCTION(oci_result)
1794 60 : {
1795 : php_oci_out_column *column;
1796 :
1797 60 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
1798 60 : if(column) {
1799 57 : php_oci_column_to_zval(column, return_value, 0 TSRMLS_CC);
1800 : }
1801 : else {
1802 3 : RETURN_FALSE;
1803 : }
1804 : }
1805 : /* }}} */
1806 :
1807 : /* {{{ proto string oci_server_version(resource connection)
1808 : Return a string containing server version information */
1809 : PHP_FUNCTION(oci_server_version)
1810 5 : {
1811 : zval *z_connection;
1812 : php_oci_connection *connection;
1813 5 : char *version = NULL;
1814 :
1815 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1816 1 : return;
1817 : }
1818 :
1819 4 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1820 :
1821 4 : if (php_oci_server_get_version(connection, &version TSRMLS_CC)) {
1822 0 : RETURN_FALSE;
1823 : }
1824 :
1825 4 : RETURN_STRING(version, 0);
1826 : }
1827 : /* }}} */
1828 :
1829 : /* {{{ proto string oci_statement_type(resource stmt)
1830 : Return the query type of an OCI statement */
1831 : PHP_FUNCTION(oci_statement_type)
1832 27 : {
1833 : zval *z_statement;
1834 : php_oci_statement *statement;
1835 : ub2 type;
1836 :
1837 27 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1838 1 : return;
1839 : }
1840 :
1841 26 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1842 :
1843 26 : if (php_oci_statement_get_type(statement, &type TSRMLS_CC)) {
1844 0 : RETURN_FALSE;
1845 : }
1846 :
1847 26 : switch (type) {
1848 : case OCI_STMT_SELECT:
1849 2 : RETVAL_STRING("SELECT",1);
1850 2 : break;
1851 : case OCI_STMT_UPDATE:
1852 2 : RETVAL_STRING("UPDATE",1);
1853 2 : break;
1854 : case OCI_STMT_DELETE:
1855 2 : RETVAL_STRING("DELETE",1);
1856 2 : break;
1857 : case OCI_STMT_INSERT:
1858 2 : RETVAL_STRING("INSERT",1);
1859 2 : break;
1860 : case OCI_STMT_CREATE:
1861 4 : RETVAL_STRING("CREATE",1);
1862 4 : break;
1863 : case OCI_STMT_DROP:
1864 2 : RETVAL_STRING("DROP",1);
1865 2 : break;
1866 : case OCI_STMT_ALTER:
1867 2 : RETVAL_STRING("ALTER",1);
1868 2 : break;
1869 : case OCI_STMT_BEGIN:
1870 2 : RETVAL_STRING("BEGIN",1);
1871 2 : break;
1872 : case OCI_STMT_DECLARE:
1873 2 : RETVAL_STRING("DECLARE",1);
1874 2 : break;
1875 : case OCI_STMT_CALL:
1876 2 : RETVAL_STRING("CALL",1);
1877 2 : break;
1878 : default:
1879 4 : RETVAL_STRING("UNKNOWN",1);
1880 : }
1881 : }
1882 : /* }}} */
1883 :
1884 : /* {{{ proto int oci_num_rows(resource stmt)
1885 : Return the row count of an OCI statement */
1886 : PHP_FUNCTION(oci_num_rows)
1887 28 : {
1888 : zval *z_statement;
1889 : php_oci_statement *statement;
1890 : ub4 rowcount;
1891 :
1892 28 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1893 3 : return;
1894 : }
1895 :
1896 25 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1897 :
1898 25 : if (php_oci_statement_get_numrows(statement, &rowcount TSRMLS_CC)) {
1899 0 : RETURN_FALSE;
1900 : }
1901 25 : RETURN_LONG(rowcount);
1902 : }
1903 : /* }}} */
1904 :
1905 : #ifdef PHP_OCI8_HAVE_COLLECTIONS
1906 : /* {{{ proto bool oci_free_collection()
1907 : Deletes collection object*/
1908 : PHP_FUNCTION(oci_free_collection)
1909 5 : {
1910 5 : zval **tmp, *z_collection = getThis();
1911 : php_oci_collection *collection;
1912 :
1913 5 : if (!getThis()) {
1914 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
1915 1 : return;
1916 : }
1917 : }
1918 :
1919 4 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
1920 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
1921 0 : RETURN_FALSE;
1922 : }
1923 :
1924 4 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
1925 :
1926 4 : zend_list_delete(collection->id);
1927 4 : RETURN_TRUE;
1928 : }
1929 : /* }}} */
1930 :
1931 : /* {{{ proto bool oci_collection_append(string value)
1932 : Append an object to the collection */
1933 : PHP_FUNCTION(oci_collection_append)
1934 33 : {
1935 33 : zval **tmp, *z_collection = getThis();
1936 : php_oci_collection *collection;
1937 : char *value;
1938 : int value_len;
1939 :
1940 33 : if (getThis()) {
1941 20 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
1942 0 : return;
1943 : }
1944 : }
1945 : else {
1946 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) {
1947 1 : return;
1948 : }
1949 : }
1950 :
1951 32 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
1952 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
1953 0 : RETURN_FALSE;
1954 : }
1955 :
1956 32 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
1957 :
1958 32 : if (php_oci_collection_append(collection, value, value_len TSRMLS_CC)) {
1959 4 : RETURN_FALSE;
1960 : }
1961 28 : RETURN_TRUE;
1962 : }
1963 : /* }}} */
1964 :
1965 : /* {{{ proto string oci_collection_element_get(int ndx)
1966 : Retrieve the value at collection index ndx */
1967 : PHP_FUNCTION(oci_collection_element_get)
1968 48 : {
1969 48 : zval **tmp, *z_collection = getThis();
1970 : php_oci_collection *collection;
1971 : long element_index;
1972 : zval *value;
1973 :
1974 48 : if (getThis()) {
1975 34 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &element_index) == FAILURE) {
1976 0 : return;
1977 : }
1978 : }
1979 : else {
1980 14 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) {
1981 1 : return;
1982 : }
1983 : }
1984 :
1985 47 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
1986 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
1987 0 : RETURN_FALSE;
1988 : }
1989 :
1990 47 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
1991 :
1992 47 : if (php_oci_collection_element_get(collection, element_index, &value TSRMLS_CC)) {
1993 18 : RETURN_FALSE;
1994 : }
1995 :
1996 29 : *return_value = *value;
1997 29 : zval_copy_ctor(return_value);
1998 29 : zval_ptr_dtor(&value);
1999 : }
2000 : /* }}} */
2001 :
2002 : /* {{{ proto bool oci_collection_assign(object from)
2003 : Assign a collection from another existing collection */
2004 : PHP_FUNCTION(oci_collection_assign)
2005 11 : {
2006 11 : zval **tmp_dest, **tmp_from, *z_collection_dest = getThis(), *z_collection_from;
2007 : php_oci_collection *collection_dest, *collection_from;
2008 :
2009 11 : if (getThis()) {
2010 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) {
2011 0 : return;
2012 : }
2013 : }
2014 : else {
2015 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &z_collection_dest, oci_coll_class_entry_ptr, &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) {
2016 0 : return;
2017 : }
2018 : }
2019 :
2020 11 : if (zend_hash_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection"), (void **)&tmp_dest) == FAILURE) {
2021 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property. The first argument should be valid collection object");
2022 0 : RETURN_FALSE;
2023 : }
2024 :
2025 11 : if (zend_hash_find(Z_OBJPROP_P(z_collection_from), "collection", sizeof("collection"), (void **)&tmp_from) == FAILURE) {
2026 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property. The second argument should be valid collection object");
2027 0 : RETURN_FALSE;
2028 : }
2029 :
2030 11 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp_dest, collection_dest);
2031 11 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp_from, collection_from);
2032 :
2033 11 : if (php_oci_collection_assign(collection_dest, collection_from TSRMLS_CC)) {
2034 0 : RETURN_FALSE;
2035 : }
2036 11 : RETURN_TRUE;
2037 : }
2038 : /* }}} */
2039 :
2040 : /* {{{ proto bool oci_collection_element_assign(int index, string val)
2041 : Assign element val to collection at index ndx */
2042 : PHP_FUNCTION(oci_collection_element_assign)
2043 21 : {
2044 21 : zval **tmp, *z_collection = getThis();
2045 : php_oci_collection *collection;
2046 : int value_len;
2047 : long element_index;
2048 : char *value;
2049 :
2050 21 : if (getThis()) {
2051 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element_index, &value, &value_len) == FAILURE) {
2052 0 : return;
2053 : }
2054 : }
2055 : else {
2056 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) {
2057 1 : return;
2058 : }
2059 : }
2060 :
2061 20 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2062 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2063 0 : RETURN_FALSE;
2064 : }
2065 :
2066 20 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2067 :
2068 20 : if (php_oci_collection_element_set(collection, element_index, value, value_len TSRMLS_CC)) {
2069 9 : RETURN_FALSE;
2070 : }
2071 11 : RETURN_TRUE;
2072 : }
2073 : /* }}} */
2074 :
2075 : /* {{{ proto int oci_collection_size()
2076 : Return the size of a collection */
2077 : PHP_FUNCTION(oci_collection_size)
2078 9 : {
2079 9 : zval **tmp, *z_collection = getThis();
2080 : php_oci_collection *collection;
2081 9 : sb4 size = 0;
2082 :
2083 9 : if (!getThis()) {
2084 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
2085 1 : return;
2086 : }
2087 : }
2088 :
2089 8 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2090 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2091 0 : RETURN_FALSE;
2092 : }
2093 :
2094 8 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2095 :
2096 4 : if (php_oci_collection_size(collection, &size TSRMLS_CC)) {
2097 0 : RETURN_FALSE;
2098 : }
2099 4 : RETURN_LONG(size);
2100 : }
2101 : /* }}} */
2102 :
2103 : /* {{{ proto int oci_collection_max()
2104 : Return the max value of a collection. For a varray this is the maximum length of the array */
2105 : PHP_FUNCTION(oci_collection_max)
2106 4 : {
2107 4 : zval **tmp, *z_collection = getThis();
2108 : php_oci_collection *collection;
2109 : long max;
2110 :
2111 4 : if (!getThis()) {
2112 2 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
2113 1 : return;
2114 : }
2115 : }
2116 :
2117 3 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2118 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2119 0 : RETURN_FALSE;
2120 : }
2121 :
2122 3 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2123 :
2124 3 : if (php_oci_collection_max(collection, &max TSRMLS_CC)) {
2125 0 : RETURN_FALSE;
2126 : }
2127 3 : RETURN_LONG(max);
2128 : }
2129 : /* }}} */
2130 :
2131 : /* {{{ proto bool oci_collection_trim(int num)
2132 : Trim num elements from the end of a collection */
2133 : PHP_FUNCTION(oci_collection_trim)
2134 10 : {
2135 10 : zval **tmp, *z_collection = getThis();
2136 : php_oci_collection *collection;
2137 : long trim_size;
2138 :
2139 10 : if (getThis()) {
2140 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &trim_size) == FAILURE) {
2141 1 : return;
2142 : }
2143 : }
2144 : else {
2145 2 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) {
2146 1 : return;
2147 : }
2148 : }
2149 :
2150 8 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2151 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2152 0 : RETURN_FALSE;
2153 : }
2154 :
2155 8 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2156 :
2157 8 : if (php_oci_collection_trim(collection, trim_size TSRMLS_CC)) {
2158 3 : RETURN_FALSE;
2159 : }
2160 5 : RETURN_TRUE;
2161 : }
2162 : /* }}} */
2163 :
2164 : /* {{{ proto object oci_new_collection(resource connection, string tdo [, string schema])
2165 : Initialize a new collection */
2166 : PHP_FUNCTION(oci_new_collection)
2167 70054 : {
2168 : zval *z_connection;
2169 : php_oci_connection *connection;
2170 : php_oci_collection *collection;
2171 70054 : char *tdo, *schema = NULL;
2172 70054 : int tdo_len, schema_len = 0;
2173 :
2174 70054 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) {
2175 1 : return;
2176 : }
2177 :
2178 70053 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
2179 :
2180 70053 : if ( (collection = php_oci_collection_create(connection, tdo, tdo_len, schema, schema_len TSRMLS_CC)) ) {
2181 70047 : object_init_ex(return_value, oci_coll_class_entry_ptr);
2182 70047 : add_property_resource(return_value, "collection", collection->id);
2183 : }
2184 : else {
2185 6 : RETURN_FALSE;
2186 : }
2187 : }
2188 : /* }}} */
2189 :
2190 : #endif
2191 :
2192 : #endif /* HAVE_OCI8 */
2193 :
2194 : /*
2195 : * Local variables:
2196 : * tab-width: 4
2197 : * c-basic-offset: 4
2198 : * End:
2199 : * vim600: noet sw=4 ts=4 fdm=marker
2200 : * vim<600: noet sw=4 ts=4
2201 : */
|