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 289264 2009-10-06 22:36:32Z sixd $ */
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 324 : {
100 324 : ub2 bind_type = SQLT_CHR; /* unterminated string */
101 : int name_len;
102 324 : long maxlen = -1, type = 0;
103 : char *name;
104 : zval *z_statement;
105 324 : zval *bind_var = NULL;
106 : php_oci_statement *statement;
107 :
108 324 : 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 319 : if (type) {
113 195 : bind_type = (ub2) type;
114 : }
115 :
116 319 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
117 :
118 319 : if (php_oci_bind_by_name(statement, name, name_len, bind_var, maxlen, bind_type TSRMLS_CC)) {
119 3 : RETURN_FALSE;
120 : }
121 316 : 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 181112 : {
164 181112 : zval **tmp, *z_descriptor = getThis();
165 : php_oci_descriptor *descriptor;
166 :
167 181112 : 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 181109 : 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 181108 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
179 :
180 181107 : zend_list_delete(descriptor->id);
181 181107 : 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 75 : {
264 75 : zval **tmp, *z_descriptor = getThis();
265 : php_oci_descriptor *descriptor;
266 75 : char *buffer = NULL;
267 : ub4 buffer_len;
268 :
269 75 : 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 72 : 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 71 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
281 :
282 71 : if (php_oci_lob_read(descriptor, -1, 0, &buffer, &buffer_len TSRMLS_CC)) {
283 0 : RETURN_FALSE;
284 : }
285 71 : if (buffer_len > 0) {
286 57 : 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 18 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
447 0 : RETURN_FALSE;
448 : }
449 :
450 18 : switch(whence) {
451 : case PHP_OCI_SEEK_CUR:
452 6 : descriptor->lob_current_position += offset;
453 6 : break;
454 : case PHP_OCI_SEEK_END:
455 2 : if ((descriptor->lob_size + offset) >= 0) {
456 2 : descriptor->lob_current_position = descriptor->lob_size + offset;
457 : }
458 : else {
459 0 : descriptor->lob_current_position = 0;
460 : }
461 2 : break;
462 : case PHP_OCI_SEEK_SET:
463 : default:
464 10 : descriptor->lob_current_position = (offset > 0) ? offset : 0;
465 : break;
466 : }
467 18 : RETURN_TRUE;
468 : }
469 : /* }}} */
470 :
471 : /* {{{ proto int oci_lob_size()
472 : Returns size of a large object */
473 : PHP_FUNCTION(oci_lob_size)
474 211 : {
475 211 : zval **tmp, *z_descriptor = getThis();
476 : php_oci_descriptor *descriptor;
477 : ub4 lob_length;
478 :
479 211 : if (!getThis()) {
480 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
481 2 : return;
482 : }
483 : }
484 :
485 209 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
486 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
487 1 : RETURN_FALSE;
488 : }
489 :
490 208 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
491 :
492 208 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
493 0 : RETURN_FALSE;
494 : }
495 208 : RETURN_LONG(lob_length);
496 : }
497 : /* }}} */
498 :
499 : /* {{{ proto int oci_lob_write( string string [, int length ])
500 : Writes data to current position of a LOB */
501 : PHP_FUNCTION(oci_lob_write)
502 71 : {
503 71 : zval **tmp, *z_descriptor = getThis();
504 : php_oci_descriptor *descriptor;
505 : int data_len;
506 71 : long write_len = 0;
507 : ub4 bytes_written;
508 : char *data;
509 :
510 71 : if (getThis()) {
511 68 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &write_len) == FAILURE) {
512 1 : return;
513 : }
514 :
515 67 : if (ZEND_NUM_ARGS() == 2) {
516 3 : data_len = MIN(data_len, write_len);
517 : }
518 : }
519 : else {
520 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) {
521 1 : return;
522 : }
523 :
524 2 : if (ZEND_NUM_ARGS() == 3) {
525 0 : data_len = MIN(data_len, write_len);
526 : }
527 : }
528 :
529 69 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
530 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
531 0 : RETURN_FALSE;
532 : }
533 :
534 69 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
535 :
536 67 : if (data_len <= 0) {
537 1 : RETURN_LONG(0);
538 : }
539 :
540 66 : if (php_oci_lob_write(descriptor, descriptor->lob_current_position, data, data_len, &bytes_written TSRMLS_CC)) {
541 1 : RETURN_FALSE;
542 : }
543 65 : RETURN_LONG(bytes_written);
544 : }
545 : /* }}} */
546 :
547 : /* {{{ proto bool oci_lob_append( object lob )
548 : Appends data from a LOB to another LOB */
549 : PHP_FUNCTION(oci_lob_append)
550 5 : {
551 5 : zval **tmp_dest, **tmp_from, *z_descriptor_dest = getThis(), *z_descriptor_from;
552 : php_oci_descriptor *descriptor_dest, *descriptor_from;
553 :
554 5 : if (getThis()) {
555 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor_from, oci_lob_class_entry_ptr) == FAILURE) {
556 0 : return;
557 : }
558 : }
559 : else {
560 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) {
561 3 : return;
562 : }
563 : }
564 :
565 2 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) {
566 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
567 0 : RETURN_FALSE;
568 : }
569 :
570 2 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) {
571 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
572 0 : RETURN_FALSE;
573 : }
574 :
575 2 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest);
576 2 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from);
577 :
578 2 : if (php_oci_lob_append(descriptor_dest, descriptor_from TSRMLS_CC)) {
579 0 : RETURN_FALSE;
580 : }
581 : /* XXX should we increase lob_size here ? */
582 2 : RETURN_TRUE;
583 : }
584 : /* }}} */
585 :
586 : /* {{{ proto bool oci_lob_truncate( [ int length ])
587 : Truncates a LOB */
588 : PHP_FUNCTION(oci_lob_truncate)
589 14 : {
590 14 : zval **tmp, *z_descriptor = getThis();
591 : php_oci_descriptor *descriptor;
592 14 : long trim_length = 0;
593 : ub4 ub_trim_length;
594 :
595 14 : if (getThis()) {
596 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &trim_length) == FAILURE) {
597 0 : return;
598 : }
599 : }
600 : else {
601 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &z_descriptor, oci_lob_class_entry_ptr, &trim_length) == FAILURE) {
602 1 : return;
603 : }
604 : }
605 :
606 13 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
607 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
608 0 : RETURN_FALSE;
609 : }
610 :
611 13 : if (trim_length < 0) {
612 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to zero");
613 3 : RETURN_FALSE;
614 : }
615 :
616 10 : ub_trim_length = (ub4) trim_length;
617 10 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
618 :
619 10 : if (php_oci_lob_truncate(descriptor, ub_trim_length TSRMLS_CC)) {
620 1 : RETURN_FALSE;
621 : }
622 9 : RETURN_TRUE;
623 : }
624 : /* }}} */
625 :
626 : /* {{{ proto int oci_lob_erase( [ int offset [, int length ] ] )
627 : Erases a specified portion of the internal LOB, starting at a specified offset */
628 : PHP_FUNCTION(oci_lob_erase)
629 15 : {
630 15 : zval **tmp, *z_descriptor = getThis();
631 : php_oci_descriptor *descriptor;
632 : ub4 bytes_erased;
633 15 : long offset = -1, length = -1;
634 :
635 15 : if (getThis()) {
636 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &offset, &length) == FAILURE) {
637 1 : return;
638 : }
639 :
640 7 : if (ZEND_NUM_ARGS() > 0 && offset < 0) {
641 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be greater than or equal to 0");
642 2 : RETURN_FALSE;
643 : }
644 :
645 5 : if (ZEND_NUM_ARGS() > 1 && length < 0) {
646 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to 0");
647 1 : RETURN_FALSE;
648 : }
649 : }
650 : else {
651 7 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &z_descriptor, oci_lob_class_entry_ptr, &offset, &length) == FAILURE) {
652 2 : return;
653 : }
654 :
655 5 : if (ZEND_NUM_ARGS() > 1 && offset < 0) {
656 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be greater than or equal to 0");
657 2 : RETURN_FALSE;
658 : }
659 :
660 3 : if (ZEND_NUM_ARGS() > 2 && length < 0) {
661 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length must be greater than or equal to 0");
662 1 : RETURN_FALSE;
663 : }
664 : }
665 :
666 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
667 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
668 1 : RETURN_FALSE;
669 : }
670 :
671 5 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
672 :
673 5 : if (php_oci_lob_erase(descriptor, offset, length, &bytes_erased TSRMLS_CC)) {
674 2 : RETURN_FALSE;
675 : }
676 3 : RETURN_LONG(bytes_erased);
677 : }
678 : /* }}} */
679 :
680 : /* {{{ proto bool oci_lob_flush( [ int flag ] )
681 : Flushes the LOB buffer */
682 : PHP_FUNCTION(oci_lob_flush)
683 9 : {
684 9 : zval **tmp, *z_descriptor = getThis();
685 : php_oci_descriptor *descriptor;
686 9 : long flush_flag = 0;
687 :
688 9 : if (getThis()) {
689 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flush_flag) == FAILURE) {
690 0 : return;
691 : }
692 : }
693 : else {
694 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &z_descriptor, oci_lob_class_entry_ptr, &flush_flag) == FAILURE) {
695 1 : return;
696 : }
697 : }
698 :
699 8 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
700 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
701 0 : RETURN_FALSE;
702 : }
703 :
704 8 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
705 :
706 8 : if (descriptor->buffering == PHP_OCI_LOB_BUFFER_DISABLED) {
707 : /* buffering wasn't enabled, there is nothing to flush */
708 4 : RETURN_FALSE;
709 : }
710 :
711 4 : if (php_oci_lob_flush(descriptor, flush_flag TSRMLS_CC)) {
712 1 : RETURN_FALSE;
713 : }
714 3 : RETURN_TRUE;
715 : }
716 : /* }}} */
717 :
718 : /* {{{ proto bool ocisetbufferinglob( boolean flag )
719 : Enables/disables buffering for a LOB */
720 : PHP_FUNCTION(ocisetbufferinglob)
721 7 : {
722 7 : zval **tmp, *z_descriptor = getThis();
723 : php_oci_descriptor *descriptor;
724 : zend_bool flag;
725 :
726 7 : if (getThis()) {
727 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &flag) == FAILURE) {
728 0 : return;
729 : }
730 : }
731 : else {
732 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ob", &z_descriptor, oci_lob_class_entry_ptr, &flag) == FAILURE) {
733 1 : return;
734 : }
735 : }
736 :
737 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
738 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
739 0 : RETURN_FALSE;
740 : }
741 :
742 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
743 :
744 6 : if (php_oci_lob_set_buffering(descriptor, flag TSRMLS_CC)) {
745 0 : RETURN_FALSE;
746 : }
747 6 : RETURN_TRUE;
748 : }
749 : /* }}} */
750 :
751 : /* {{{ proto bool ocigetbufferinglob()
752 : Returns current state of buffering for a LOB */
753 : PHP_FUNCTION(ocigetbufferinglob)
754 4 : {
755 4 : zval **tmp, *z_descriptor = getThis();
756 : php_oci_descriptor *descriptor;
757 :
758 4 : if (!getThis()) {
759 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
760 1 : return;
761 : }
762 : }
763 :
764 3 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
765 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
766 0 : RETURN_FALSE;
767 : }
768 :
769 3 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
770 :
771 3 : if (descriptor->buffering != PHP_OCI_LOB_BUFFER_DISABLED) {
772 1 : RETURN_TRUE;
773 : }
774 2 : RETURN_FALSE;
775 : }
776 : /* }}} */
777 :
778 : /* {{{ proto bool oci_lob_copy( object lob_to, object lob_from [, int length ] )
779 : Copies data from a LOB to another LOB */
780 : PHP_FUNCTION(oci_lob_copy)
781 6 : {
782 : zval **tmp_dest, **tmp_from, *z_descriptor_dest, *z_descriptor_from;
783 : php_oci_descriptor *descriptor_dest, *descriptor_from;
784 6 : long length = 0;
785 :
786 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) {
787 0 : return;
788 : }
789 :
790 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_dest), "descriptor", sizeof("descriptor"), (void **)&tmp_dest) == FAILURE) {
791 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
792 0 : RETURN_FALSE;
793 : }
794 :
795 6 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_from), "descriptor", sizeof("descriptor"), (void **)&tmp_from) == FAILURE) {
796 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
797 0 : RETURN_FALSE;
798 : }
799 :
800 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_dest, descriptor_dest);
801 6 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_from, descriptor_from);
802 :
803 6 : if (ZEND_NUM_ARGS() == 3 && length < 0) {
804 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
805 1 : RETURN_FALSE;
806 : }
807 :
808 5 : if (ZEND_NUM_ARGS() == 2) {
809 : /* indicate that we want to copy from the current position to the end of the LOB */
810 3 : length = -1;
811 : }
812 :
813 5 : if (php_oci_lob_copy(descriptor_dest, descriptor_from, length TSRMLS_CC)) {
814 3 : RETURN_FALSE;
815 : }
816 2 : RETURN_TRUE;
817 : }
818 : /* }}} */
819 :
820 : /* {{{ proto bool oci_lob_is_equal( object lob1, object lob2 )
821 : Tests to see if two LOB/FILE locators are equal */
822 : PHP_FUNCTION(oci_lob_is_equal)
823 1 : {
824 : zval **tmp_first, **tmp_second, *z_descriptor_first, *z_descriptor_second;
825 : php_oci_descriptor *descriptor_first, *descriptor_second;
826 : boolean is_equal;
827 :
828 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) {
829 0 : return;
830 : }
831 :
832 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_first), "descriptor", sizeof("descriptor"), (void **)&tmp_first) == FAILURE) {
833 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The first argument should be valid descriptor object");
834 0 : RETURN_FALSE;
835 : }
836 :
837 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor_second), "descriptor", sizeof("descriptor"), (void **)&tmp_second) == FAILURE) {
838 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property. The second argument should be valid descriptor object");
839 0 : RETURN_FALSE;
840 : }
841 :
842 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_first, descriptor_first);
843 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp_second, descriptor_second);
844 :
845 1 : if (php_oci_lob_is_equal(descriptor_first, descriptor_second, &is_equal TSRMLS_CC)) {
846 0 : RETURN_FALSE;
847 : }
848 :
849 1 : if (is_equal == TRUE) {
850 1 : RETURN_TRUE;
851 : }
852 0 : RETURN_FALSE;
853 : }
854 : /* }}} */
855 :
856 : /* {{{ proto bool oci_lob_export([string filename [, int start [, int length]]])
857 : Writes a large object into a file */
858 : PHP_FUNCTION(oci_lob_export)
859 4 : {
860 4 : zval **tmp, *z_descriptor = getThis();
861 : php_oci_descriptor *descriptor;
862 : char *filename;
863 : char *buffer;
864 : int filename_len;
865 4 : long start = -1, length = -1, block_length;
866 : php_stream *stream;
867 : ub4 lob_length;
868 :
869 4 : if (getThis()) {
870 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &filename, &filename_len, &start, &length) == FAILURE) {
871 0 : return;
872 : }
873 :
874 1 : if (ZEND_NUM_ARGS() > 1 && start < 0) {
875 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0");
876 0 : RETURN_FALSE;
877 : }
878 1 : if (ZEND_NUM_ARGS() > 2 && length < 0) {
879 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than or equal to 0");
880 0 : RETURN_FALSE;
881 : }
882 : }
883 : else {
884 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) {
885 3 : return;
886 : }
887 :
888 0 : if (ZEND_NUM_ARGS() > 2 && start < 0) {
889 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start parameter must be greater than or equal to 0");
890 0 : RETURN_FALSE;
891 : }
892 0 : if (ZEND_NUM_ARGS() > 3 && length < 0) {
893 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than or equal to 0");
894 0 : RETURN_FALSE;
895 : }
896 : }
897 :
898 1 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
899 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
900 0 : RETURN_FALSE;
901 : }
902 :
903 1 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
904 :
905 1 : if (php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) {
906 0 : RETURN_FALSE;
907 : }
908 :
909 1 : if (start == -1) {
910 0 : start = 0;
911 : }
912 :
913 1 : if (length == -1) {
914 0 : length = lob_length - descriptor->lob_current_position;
915 : }
916 :
917 1 : if (length == 0) {
918 : /* nothing to write, fail silently */
919 0 : RETURN_FALSE;
920 : }
921 :
922 1 : if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
923 0 : RETURN_FALSE;
924 : }
925 :
926 1 : if (php_check_open_basedir(filename TSRMLS_CC)) {
927 0 : RETURN_FALSE;
928 : }
929 :
930 1 : stream = php_stream_open_wrapper_ex(filename, "w", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, NULL);
931 :
932 1 : block_length = PHP_OCI_LOB_BUFFER_SIZE;
933 1 : if (block_length > length) {
934 1 : block_length = length;
935 : }
936 :
937 3 : while(length > 0) {
938 1 : ub4 tmp_bytes_read = 0;
939 1 : if (php_oci_lob_read(descriptor, block_length, start, &buffer, &tmp_bytes_read TSRMLS_CC)) {
940 0 : php_stream_close(stream);
941 0 : RETURN_FALSE;
942 : }
943 1 : if (tmp_bytes_read && !php_stream_write(stream, buffer, tmp_bytes_read)) {
944 0 : php_stream_close(stream);
945 0 : efree(buffer);
946 0 : RETURN_FALSE;
947 : }
948 1 : if (buffer) {
949 1 : efree(buffer);
950 : }
951 :
952 1 : length -= tmp_bytes_read;
953 1 : descriptor->lob_current_position += tmp_bytes_read;
954 1 : start += tmp_bytes_read;
955 :
956 1 : if (block_length > length) {
957 1 : block_length = length;
958 : }
959 : }
960 :
961 1 : php_stream_close(stream);
962 1 : RETURN_TRUE;
963 : }
964 : /* }}} */
965 :
966 : /* {{{ proto bool oci_lob_write_temporary(string var [, int lob_type])
967 : Writes temporary blob */
968 : PHP_FUNCTION(oci_lob_write_temporary)
969 116 : {
970 116 : zval **tmp, *z_descriptor = getThis();
971 : php_oci_descriptor *descriptor;
972 : char *data;
973 : int data_len;
974 116 : long type = OCI_TEMP_CLOB;
975 :
976 116 : if (getThis()) {
977 116 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &type) == FAILURE) {
978 0 : return;
979 : }
980 : }
981 : else {
982 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &z_descriptor, oci_lob_class_entry_ptr, &data, &data_len, &type) == FAILURE) {
983 0 : return;
984 : }
985 : }
986 :
987 116 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
988 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
989 0 : RETURN_FALSE;
990 : }
991 :
992 116 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
993 :
994 116 : if (php_oci_lob_write_tmp(descriptor, type, data, data_len TSRMLS_CC)) {
995 1 : RETURN_FALSE;
996 : }
997 115 : RETURN_TRUE;
998 : }
999 : /* }}} */
1000 :
1001 : /* {{{ proto bool oci_lob_close()
1002 : Closes lob descriptor */
1003 : PHP_FUNCTION(oci_lob_close)
1004 115 : {
1005 115 : zval **tmp, *z_descriptor = getThis();
1006 : php_oci_descriptor *descriptor;
1007 :
1008 115 : if (!getThis()) {
1009 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_descriptor, oci_lob_class_entry_ptr) == FAILURE) {
1010 0 : return;
1011 : }
1012 : }
1013 :
1014 115 : if (zend_hash_find(Z_OBJPROP_P(z_descriptor), "descriptor", sizeof("descriptor"), (void **)&tmp) == FAILURE) {
1015 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find descriptor property");
1016 0 : RETURN_FALSE;
1017 : }
1018 :
1019 115 : PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor);
1020 :
1021 115 : if (php_oci_lob_close(descriptor TSRMLS_CC)) {
1022 0 : RETURN_FALSE;
1023 : }
1024 115 : RETURN_TRUE;
1025 : }
1026 : /* }}} */
1027 :
1028 : /* {{{ proto object oci_new_descriptor(resource connection [, int type])
1029 : Initialize a new empty descriptor LOB/FILE (LOB is default) */
1030 : PHP_FUNCTION(oci_new_descriptor)
1031 199 : {
1032 : zval *z_connection;
1033 : php_oci_connection *connection;
1034 : php_oci_descriptor *descriptor;
1035 199 : long type = OCI_DTYPE_LOB;
1036 :
1037 199 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &z_connection, &type) == FAILURE) {
1038 2 : return;
1039 : }
1040 :
1041 197 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1042 :
1043 : /* php_oci_lob_create() checks type */
1044 197 : descriptor = php_oci_lob_create(connection, type TSRMLS_CC);
1045 :
1046 197 : if (!descriptor) {
1047 4 : RETURN_NULL();
1048 : }
1049 :
1050 193 : object_init_ex(return_value, oci_lob_class_entry_ptr);
1051 193 : add_property_resource(return_value, "descriptor", descriptor->id);
1052 : }
1053 : /* }}} */
1054 :
1055 : /* {{{ proto bool oci_rollback(resource connection)
1056 : Rollback the current context */
1057 : PHP_FUNCTION(oci_rollback)
1058 5 : {
1059 : zval *z_connection;
1060 : php_oci_connection *connection;
1061 :
1062 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1063 1 : return;
1064 : }
1065 :
1066 4 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1067 :
1068 4 : if (connection->descriptors) {
1069 1 : zend_hash_destroy(connection->descriptors);
1070 1 : efree(connection->descriptors);
1071 1 : connection->descriptors = NULL;
1072 : }
1073 :
1074 4 : if (php_oci_connection_rollback(connection TSRMLS_CC)) {
1075 0 : RETURN_FALSE;
1076 : }
1077 4 : RETURN_TRUE;
1078 : }
1079 : /* }}} */
1080 :
1081 : /* {{{ proto bool oci_commit(resource connection)
1082 : Commit the current context */
1083 : PHP_FUNCTION(oci_commit)
1084 84 : {
1085 : zval *z_connection;
1086 : php_oci_connection *connection;
1087 :
1088 84 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1089 1 : return;
1090 : }
1091 :
1092 83 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1093 :
1094 83 : if (connection->descriptors) {
1095 51 : zend_hash_destroy(connection->descriptors);
1096 51 : efree(connection->descriptors);
1097 51 : connection->descriptors = NULL;
1098 : }
1099 :
1100 83 : if (php_oci_connection_commit(connection TSRMLS_CC)) {
1101 0 : RETURN_FALSE;
1102 : }
1103 83 : RETURN_TRUE;
1104 : }
1105 : /* }}} */
1106 :
1107 : /* {{{ proto string oci_field_name(resource stmt, int col)
1108 : Tell the name of a column */
1109 : PHP_FUNCTION(oci_field_name)
1110 45 : {
1111 : php_oci_out_column *column;
1112 :
1113 45 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1114 40 : RETURN_STRINGL(column->name, column->name_len, 1);
1115 : }
1116 5 : RETURN_FALSE;
1117 : }
1118 : /* }}} */
1119 :
1120 : /* {{{ proto int oci_field_size(resource stmt, int col)
1121 : Tell the maximum data size of a column */
1122 : PHP_FUNCTION(oci_field_size)
1123 25 : {
1124 : php_oci_out_column *column;
1125 :
1126 25 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1127 : /* Handle data type of LONG */
1128 19 : if (column->data_type == SQLT_LNG){
1129 0 : RETURN_LONG(column->storage_size4);
1130 : }
1131 19 : RETURN_LONG(column->data_size);
1132 : }
1133 6 : RETURN_FALSE;
1134 : }
1135 : /* }}} */
1136 :
1137 : /* {{{ proto int oci_field_scale(resource stmt, int col)
1138 : Tell the scale of a column */
1139 : PHP_FUNCTION(oci_field_scale)
1140 40 : {
1141 : php_oci_out_column *column;
1142 :
1143 40 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1144 35 : RETURN_LONG(column->scale);
1145 : }
1146 5 : RETURN_FALSE;
1147 : }
1148 : /* }}} */
1149 :
1150 : /* {{{ proto int oci_field_precision(resource stmt, int col)
1151 : Tell the precision of a column */
1152 : PHP_FUNCTION(oci_field_precision)
1153 40 : {
1154 : php_oci_out_column *column;
1155 :
1156 40 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1157 35 : RETURN_LONG(column->precision);
1158 : }
1159 5 : RETURN_FALSE;
1160 : }
1161 : /* }}} */
1162 :
1163 : /* {{{ proto mixed oci_field_type(resource stmt, int col)
1164 : Tell the data type of a column */
1165 : PHP_FUNCTION(oci_field_type)
1166 25 : {
1167 : php_oci_out_column *column;
1168 :
1169 25 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
1170 :
1171 25 : if (!column) {
1172 5 : RETURN_FALSE;
1173 : }
1174 :
1175 20 : switch (column->data_type) {
1176 : #ifdef SQLT_TIMESTAMP
1177 : case SQLT_TIMESTAMP:
1178 2 : RETVAL_STRING("TIMESTAMP",1);
1179 2 : break;
1180 : #endif
1181 : #ifdef SQLT_TIMESTAMP_TZ
1182 : case SQLT_TIMESTAMP_TZ:
1183 2 : RETVAL_STRING("TIMESTAMP WITH TIMEZONE",1);
1184 2 : break;
1185 : #endif
1186 : #ifdef SQLT_TIMESTAMP_LTZ
1187 : case SQLT_TIMESTAMP_LTZ:
1188 1 : RETVAL_STRING("TIMESTAMP WITH LOCAL TIMEZONE",1);
1189 1 : break;
1190 : #endif
1191 : #ifdef SQLT_INTERVAL_YM
1192 : case SQLT_INTERVAL_YM:
1193 2 : RETVAL_STRING("INTERVAL YEAR TO MONTH",1);
1194 2 : break;
1195 : #endif
1196 : #ifdef SQLT_INTERVAL_DS
1197 : case SQLT_INTERVAL_DS:
1198 2 : RETVAL_STRING("INTERVAL DAY TO SECOND",1);
1199 2 : break;
1200 : #endif
1201 : case SQLT_DAT:
1202 0 : RETVAL_STRING("DATE",1);
1203 0 : break;
1204 : case SQLT_NUM:
1205 4 : RETVAL_STRING("NUMBER",1);
1206 4 : break;
1207 : case SQLT_LNG:
1208 0 : RETVAL_STRING("LONG",1);
1209 0 : break;
1210 : case SQLT_BIN:
1211 0 : RETVAL_STRING("RAW",1);
1212 0 : break;
1213 : case SQLT_LBI:
1214 0 : RETVAL_STRING("LONG RAW",1);
1215 0 : break;
1216 : case SQLT_CHR:
1217 2 : RETVAL_STRING("VARCHAR2",1);
1218 2 : break;
1219 : case SQLT_RSET:
1220 0 : RETVAL_STRING("REFCURSOR",1);
1221 0 : break;
1222 : case SQLT_AFC:
1223 1 : RETVAL_STRING("CHAR",1);
1224 1 : break;
1225 : case SQLT_BLOB:
1226 2 : RETVAL_STRING("BLOB",1);
1227 2 : break;
1228 : case SQLT_CLOB:
1229 2 : RETVAL_STRING("CLOB",1);
1230 2 : break;
1231 : case SQLT_BFILE:
1232 0 : RETVAL_STRING("BFILE",1);
1233 0 : break;
1234 : case SQLT_RDD:
1235 0 : RETVAL_STRING("ROWID",1);
1236 0 : break;
1237 : default:
1238 0 : RETVAL_LONG(column->data_type);
1239 : }
1240 : }
1241 : /* }}} */
1242 :
1243 : /* {{{ proto int oci_field_type_raw(resource stmt, int col)
1244 : Tell the raw oracle data type of a column */
1245 : PHP_FUNCTION(oci_field_type_raw)
1246 24 : {
1247 : php_oci_out_column *column;
1248 :
1249 24 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
1250 24 : if (column) {
1251 19 : RETURN_LONG(column->data_type);
1252 : }
1253 5 : RETURN_FALSE;
1254 : }
1255 : /* }}} */
1256 :
1257 : /* {{{ proto bool oci_field_is_null(resource stmt, int col)
1258 : Tell whether a column is NULL */
1259 : PHP_FUNCTION(oci_field_is_null)
1260 24 : {
1261 : php_oci_out_column *column;
1262 :
1263 24 : if ( ( column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) ) ) {
1264 19 : if (column->indicator == -1) {
1265 6 : RETURN_TRUE;
1266 : }
1267 : }
1268 18 : RETURN_FALSE;
1269 : }
1270 : /* }}} */
1271 :
1272 : /* {{{ proto void oci_internal_debug(int onoff)
1273 : Toggle internal debugging output for the OCI extension */
1274 : PHP_FUNCTION(oci_internal_debug)
1275 1 : {
1276 : zend_bool on_off;
1277 :
1278 1 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &on_off) == FAILURE) {
1279 1 : return;
1280 : }
1281 0 : OCI_G(debug_mode) = on_off;
1282 : }
1283 : /* }}} */
1284 :
1285 : /* {{{ proto bool oci_execute(resource stmt [, int mode])
1286 : Execute a parsed statement */
1287 : PHP_FUNCTION(oci_execute)
1288 34313 : {
1289 : zval *z_statement;
1290 : php_oci_statement *statement;
1291 34313 : long mode = OCI_COMMIT_ON_SUCCESS;
1292 :
1293 34313 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &z_statement, &mode) == FAILURE) {
1294 1 : return;
1295 : }
1296 :
1297 34312 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1298 :
1299 34312 : if (php_oci_statement_execute(statement, mode TSRMLS_CC)) {
1300 190 : RETURN_FALSE;
1301 : }
1302 34122 : RETURN_TRUE;
1303 : }
1304 : /* }}} */
1305 :
1306 : /* {{{ proto bool oci_cancel(resource stmt)
1307 : Cancel reading from a cursor */
1308 : PHP_FUNCTION(oci_cancel)
1309 5 : {
1310 : zval *z_statement;
1311 : php_oci_statement *statement;
1312 :
1313 5 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1314 1 : return;
1315 : }
1316 :
1317 4 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1318 :
1319 4 : if (php_oci_statement_cancel(statement TSRMLS_CC)) {
1320 0 : RETURN_FALSE;
1321 : }
1322 4 : RETURN_TRUE;
1323 : }
1324 : /* }}} */
1325 :
1326 : /* {{{ proto bool oci_fetch(resource stmt)
1327 : Prepare a new row of data for reading */
1328 : PHP_FUNCTION(oci_fetch)
1329 193 : {
1330 : zval *z_statement;
1331 : php_oci_statement *statement;
1332 193 : ub4 nrows = 1; /* only one row at a time is supported for now */
1333 :
1334 193 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1335 1 : return;
1336 : }
1337 :
1338 192 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1339 :
1340 192 : if (php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1341 77 : RETURN_FALSE;
1342 : }
1343 115 : RETURN_TRUE;
1344 : }
1345 : /* }}} */
1346 :
1347 : /* {{{ proto int ocifetchinto(resource stmt, array &output [, int mode])
1348 : Fetch a row of result data into an array */
1349 : PHP_FUNCTION(ocifetchinto)
1350 6625 : {
1351 6625 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM, 3);
1352 6625 : }
1353 : /* }}} */
1354 :
1355 : /* {{{ proto int oci_fetch_all(resource stmt, array &output[, int skip[, int maxrows[, int flags]]])
1356 : Fetch all rows of result data into an array */
1357 : PHP_FUNCTION(oci_fetch_all)
1358 72 : {
1359 : zval *z_statement, *array, *element, *tmp;
1360 : php_oci_statement *statement;
1361 : php_oci_out_column **columns;
1362 : zval ***outarrs;
1363 72 : ub4 nrows = 1;
1364 : int i;
1365 72 : long rows = 0, flags = 0, skip = 0, maxrows = -1;
1366 :
1367 72 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/|lll", &z_statement, &array, &skip, &maxrows, &flags) == FAILURE) {
1368 1 : return;
1369 : }
1370 :
1371 71 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1372 :
1373 71 : zval_dtor(array);
1374 71 : array_init(array);
1375 :
1376 71 : while (skip--) {
1377 4 : if (php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1378 1 : RETURN_LONG(0);
1379 : }
1380 : }
1381 :
1382 70 : if (flags & PHP_OCI_FETCHSTATEMENT_BY_ROW) {
1383 17 : columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
1384 :
1385 75 : for (i = 0; i < statement->ncolumns; i++) {
1386 58 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1387 : }
1388 :
1389 78 : while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1390 : zval *row;
1391 :
1392 46 : MAKE_STD_ZVAL(row);
1393 46 : array_init(row);
1394 :
1395 217 : for (i = 0; i < statement->ncolumns; i++) {
1396 171 : MAKE_STD_ZVAL(element);
1397 171 : php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC);
1398 :
1399 171 : if (flags & PHP_OCI_NUM) {
1400 42 : zend_hash_next_index_insert(Z_ARRVAL_P(row), &element, sizeof(zval*), NULL);
1401 : } else { /* default to ASSOC */
1402 : #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5)
1403 : /* zend_symtable_update is only available in 5.2+ */
1404 129 : zend_symtable_update(Z_ARRVAL_P(row), columns[ i ]->name, columns[ i ]->name_len+1, &element, sizeof(zval*), NULL);
1405 : #else
1406 : /* This code path means Bug #45458 will remain broken when OCI8 is built with PHP 4 */
1407 : zend_hash_update(Z_ARRVAL_P(row), columns[ i ]->name, columns[ i ]->name_len+1, &element, sizeof(zval*), NULL);
1408 : #endif
1409 : }
1410 : }
1411 :
1412 46 : zend_hash_next_index_insert(Z_ARRVAL_P(array), &row, sizeof(zval*), NULL);
1413 46 : rows++;
1414 :
1415 46 : if (maxrows != -1 && rows == maxrows) {
1416 2 : php_oci_statement_cancel(statement TSRMLS_CC);
1417 2 : break;
1418 : }
1419 : }
1420 17 : efree(columns);
1421 :
1422 : } else { /* default to BY_COLUMN */
1423 53 : columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
1424 53 : outarrs = safe_emalloc(statement->ncolumns, sizeof(zval*), 0);
1425 :
1426 53 : if (flags & PHP_OCI_NUM) {
1427 24 : for (i = 0; i < statement->ncolumns; i++) {
1428 18 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1429 :
1430 18 : MAKE_STD_ZVAL(tmp);
1431 18 : array_init(tmp);
1432 18 : zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
1433 : }
1434 : } else { /* default to ASSOC */
1435 128 : for (i = 0; i < statement->ncolumns; i++) {
1436 81 : columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC);
1437 :
1438 81 : MAKE_STD_ZVAL(tmp);
1439 81 : array_init(tmp);
1440 : #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5)
1441 : /* zend_symtable_update is only available in 5.2+ */
1442 81 : zend_symtable_update(Z_ARRVAL_P(array), columns[ i ]->name, columns[ i ]->name_len+1, (void *) &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
1443 : #else
1444 : /* This code path means Bug #45458 will remain broken when OCI8 is built with PHP 4 */
1445 : zend_hash_update(Z_ARRVAL_P(array), columns[ i ]->name, columns[ i ]->name_len+1, (void *) &tmp, sizeof(zval*), (void **) &(outarrs[ i ]));
1446 : #endif
1447 : }
1448 : }
1449 :
1450 212 : while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) {
1451 333 : for (i = 0; i < statement->ncolumns; i++) {
1452 225 : MAKE_STD_ZVAL(element);
1453 225 : php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC);
1454 225 : zend_hash_index_update((*(outarrs[ i ]))->value.ht, rows, (void *)&element, sizeof(zval*), NULL);
1455 : }
1456 :
1457 108 : rows++;
1458 :
1459 108 : if (maxrows != -1 && rows == maxrows) {
1460 2 : php_oci_statement_cancel(statement TSRMLS_CC);
1461 2 : break;
1462 : }
1463 : }
1464 :
1465 53 : efree(columns);
1466 53 : efree(outarrs);
1467 : }
1468 :
1469 70 : RETURN_LONG(rows);
1470 : }
1471 : /* }}} */
1472 :
1473 : /* {{{ proto object oci_fetch_object( resource stmt )
1474 : Fetch a result row as an object */
1475 : PHP_FUNCTION(oci_fetch_object)
1476 4 : {
1477 4 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 2);
1478 :
1479 4 : if (Z_TYPE_P(return_value) == IS_ARRAY) {
1480 3 : object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value));
1481 : }
1482 4 : }
1483 : /* }}} */
1484 :
1485 : /* {{{ proto array oci_fetch_row( resource stmt )
1486 : Fetch a result row as an enumerated array */
1487 : PHP_FUNCTION(oci_fetch_row)
1488 13 : {
1489 13 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM | PHP_OCI_RETURN_NULLS, 1);
1490 13 : }
1491 : /* }}} */
1492 :
1493 : /* {{{ proto array oci_fetch_assoc( resource stmt )
1494 : Fetch a result row as an associative array */
1495 : PHP_FUNCTION(oci_fetch_assoc)
1496 120065 : {
1497 120065 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 1);
1498 120065 : }
1499 : /* }}} */
1500 :
1501 : /* {{{ proto array oci_fetch_array( resource stmt [, int mode ])
1502 : Fetch a result row as an array */
1503 : PHP_FUNCTION(oci_fetch_array)
1504 4545 : {
1505 4545 : php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_BOTH | PHP_OCI_RETURN_NULLS, 2);
1506 4545 : }
1507 : /* }}} */
1508 :
1509 : /* {{{ proto bool oci_free_statement(resource stmt)
1510 : Free all resources associated with a statement */
1511 : PHP_FUNCTION(oci_free_statement)
1512 32154 : {
1513 : zval *z_statement;
1514 : php_oci_statement *statement;
1515 :
1516 32154 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1517 3 : return;
1518 : }
1519 :
1520 32151 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1521 :
1522 32151 : zend_list_delete(statement->id);
1523 32151 : RETURN_TRUE;
1524 : }
1525 : /* }}} */
1526 :
1527 : /* {{{ proto bool oci_close(resource connection)
1528 : Disconnect from database */
1529 : PHP_FUNCTION(oci_close)
1530 68 : {
1531 : /* oci_close for pconnect (if old_oci_close_semantics not set) would
1532 : * release the connection back to the client-side session pool (and to the
1533 : * server-side pool if Database Resident Connection Pool is being used).
1534 : * Subsequent pconnects in the same script are not guaranteed to get the
1535 : * same database session.
1536 : */
1537 :
1538 : zval *z_connection;
1539 : php_oci_connection *connection;
1540 :
1541 68 : if (OCI_G(old_oci_close_semantics)) {
1542 : /* do nothing to keep BC */
1543 8 : return;
1544 : }
1545 :
1546 60 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1547 1 : return;
1548 : }
1549 :
1550 59 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1551 59 : zend_list_delete(connection->rsrc_id);
1552 :
1553 59 : ZVAL_NULL(z_connection);
1554 :
1555 59 : RETURN_TRUE;
1556 : }
1557 : /* }}} */
1558 :
1559 : /* {{{ proto resource oci_new_connect(string user, string pass [, string db])
1560 : Connect to an Oracle database and log on. Returns a new session. */
1561 : PHP_FUNCTION(oci_new_connect)
1562 45 : {
1563 45 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
1564 45 : }
1565 : /* }}} */
1566 :
1567 : /* {{{ proto resource oci_connect(string user, string pass [, string db [, string charset [, int session_mode ]])
1568 : Connect to an Oracle database and log on. Returns a new session. */
1569 : PHP_FUNCTION(oci_connect)
1570 302 : {
1571 302 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
1572 302 : }
1573 : /* }}} */
1574 :
1575 : /* {{{ proto resource oci_pconnect(string user, string pass [, string db [, string charset ]])
1576 : Connect to an Oracle database using a persistent connection and log on. Returns a new session. */
1577 : PHP_FUNCTION(oci_pconnect)
1578 58 : {
1579 58 : php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
1580 58 : }
1581 : /* }}} */
1582 :
1583 : /* {{{ proto array oci_error([resource stmt|connection|global])
1584 : Return the last error of stmt|connection|global. If no error happened returns false. */
1585 : PHP_FUNCTION(oci_error)
1586 79 : {
1587 79 : zval *arg = NULL;
1588 : php_oci_statement *statement;
1589 : php_oci_connection *connection;
1590 : text *errbuf;
1591 79 : sb4 errcode = 0;
1592 79 : sword error = OCI_SUCCESS;
1593 79 : dvoid *errh = NULL;
1594 79 : ub2 error_offset = 0;
1595 79 : text *sqltext = NULL;
1596 :
1597 79 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg) == FAILURE) {
1598 0 : return;
1599 : }
1600 :
1601 79 : if (ZEND_NUM_ARGS() > 0) {
1602 46 : statement = (php_oci_statement *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_statement);
1603 :
1604 46 : if (statement) {
1605 34 : errh = statement->err;
1606 34 : error = statement->errcode;
1607 :
1608 34 : if (php_oci_fetch_sqltext_offset(statement, &sqltext, &error_offset TSRMLS_CC)) {
1609 0 : RETURN_FALSE;
1610 : }
1611 34 : goto go_out;
1612 : }
1613 :
1614 12 : connection = (php_oci_connection *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_connection);
1615 12 : if (connection) {
1616 8 : errh = connection->err;
1617 8 : error = connection->errcode;
1618 8 : goto go_out;
1619 : }
1620 :
1621 4 : connection = (php_oci_connection *) zend_fetch_resource(&arg TSRMLS_CC, -1, NULL, NULL, 1, le_pconnection);
1622 4 : if (connection) {
1623 4 : errh = connection->err;
1624 4 : error = connection->errcode;
1625 4 : goto go_out;
1626 : }
1627 : } else {
1628 33 : errh = OCI_G(err);
1629 33 : error = OCI_G(errcode);
1630 : }
1631 :
1632 79 : go_out:
1633 79 : if (error == OCI_SUCCESS) { /* no error set in the handle */
1634 24 : RETURN_FALSE;
1635 : }
1636 :
1637 55 : if (!errh) {
1638 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Oci_error: unable to find error handle");
1639 0 : RETURN_FALSE;
1640 : }
1641 :
1642 55 : errcode = php_oci_fetch_errmsg(errh, &errbuf TSRMLS_CC);
1643 :
1644 55 : if (errcode) {
1645 55 : array_init(return_value);
1646 55 : add_assoc_long(return_value, "code", errcode);
1647 55 : add_assoc_string(return_value, "message", (char*) errbuf, 0);
1648 55 : add_assoc_long(return_value, "offset", error_offset);
1649 55 : add_assoc_string(return_value, "sqltext", sqltext ? (char *) sqltext : "", 1);
1650 : } else {
1651 0 : RETURN_FALSE;
1652 : }
1653 : }
1654 : /* }}} */
1655 :
1656 : /* {{{ proto int oci_num_fields(resource stmt)
1657 : Return the number of result columns in a statement */
1658 : PHP_FUNCTION(oci_num_fields)
1659 41 : {
1660 : zval *z_statement;
1661 : php_oci_statement *statement;
1662 :
1663 41 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1664 3 : return;
1665 : }
1666 :
1667 38 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1668 :
1669 38 : RETURN_LONG(statement->ncolumns);
1670 : }
1671 : /* }}} */
1672 :
1673 : /* {{{ proto resource oci_parse(resource connection, string query)
1674 : Parse a query and return a statement */
1675 : PHP_FUNCTION(oci_parse)
1676 32613 : {
1677 : zval *z_connection;
1678 : php_oci_connection *connection;
1679 : php_oci_statement *statement;
1680 : char *query;
1681 : int query_len;
1682 :
1683 32613 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &query, &query_len) == FAILURE) {
1684 2 : return;
1685 : }
1686 :
1687 32611 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1688 :
1689 32611 : statement = php_oci_statement_create(connection, query, query_len TSRMLS_CC);
1690 :
1691 32611 : if (statement) {
1692 32608 : RETURN_RESOURCE(statement->id);
1693 : }
1694 3 : RETURN_FALSE;
1695 : }
1696 : /* }}} */
1697 :
1698 : /* {{{ proto bool oci_set_prefetch(resource stmt, int prefetch_rows)
1699 : Sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
1700 : PHP_FUNCTION(oci_set_prefetch)
1701 4 : {
1702 : zval *z_statement;
1703 : php_oci_statement *statement;
1704 : long size;
1705 :
1706 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_statement, &size) == FAILURE) {
1707 1 : return;
1708 : }
1709 :
1710 3 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
1711 :
1712 3 : if (php_oci_statement_set_prefetch(statement, size TSRMLS_CC)) {
1713 0 : RETURN_FALSE;
1714 : }
1715 3 : RETURN_TRUE;
1716 : }
1717 : /* }}} */
1718 :
1719 : /* {{{ proto bool oci_set_client_identifier(resource connection, string value)
1720 : Sets the client identifier attribute on the connection */
1721 : PHP_FUNCTION(oci_set_client_identifier)
1722 9 : {
1723 : zval *z_connection;
1724 : php_oci_connection *connection;
1725 : char *client_id;
1726 : long client_id_len;
1727 :
1728 9 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &client_id, &client_id_len) == FAILURE) {
1729 0 : return;
1730 : }
1731 :
1732 9 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1733 :
1734 9 : PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_id, (ub4) client_id_len, (ub4) OCI_ATTR_CLIENT_IDENTIFIER, OCI_G(err)));
1735 :
1736 9 : if (OCI_G(errcode) != OCI_SUCCESS) {
1737 1 : php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
1738 1 : RETURN_FALSE;
1739 : }
1740 :
1741 8 : RETURN_TRUE;
1742 : }
1743 : /* }}} */
1744 :
1745 : /* {{{ proto bool oci_set_edition(string value)
1746 : Sets the edition attribute for all subsequent connections created */
1747 : PHP_FUNCTION(oci_set_edition)
1748 0 : {
1749 : #if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2)))
1750 : char *edition;
1751 : long edition_len;
1752 :
1753 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &edition, &edition_len) == FAILURE) {
1754 : return;
1755 : }
1756 :
1757 : if (OCI_G(edition)) {
1758 : efree(OCI_G(edition));
1759 : OCI_G(edition) = NULL;
1760 : }
1761 :
1762 : if (edition) {
1763 : OCI_G(edition) = (char *)safe_emalloc(edition_len+1, sizeof(text), 0);
1764 : memcpy(OCI_G(edition), edition, edition_len);
1765 : OCI_G(edition)[edition_len] = '\0';
1766 : }
1767 :
1768 : RETURN_TRUE;
1769 : #else
1770 0 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type");
1771 0 : RETURN_FALSE;
1772 : #endif
1773 : }
1774 : /* }}} */
1775 :
1776 : /* {{{ proto bool oci_set_module_name(resource connection, string value)
1777 : Sets the module attribute on the connection */
1778 : PHP_FUNCTION(oci_set_module_name)
1779 9 : {
1780 : #if (OCI_MAJOR_VERSION >= 10)
1781 : zval *z_connection;
1782 : php_oci_connection *connection;
1783 : char *module;
1784 : long module_len;
1785 :
1786 9 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &module, &module_len) == FAILURE) {
1787 0 : return;
1788 : }
1789 :
1790 9 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1791 :
1792 9 : PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) module, (ub4) module_len, (ub4) OCI_ATTR_MODULE, OCI_G(err)));
1793 :
1794 9 : if (OCI_G(errcode) != OCI_SUCCESS) {
1795 1 : php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
1796 1 : RETURN_FALSE;
1797 : }
1798 :
1799 8 : RETURN_TRUE;
1800 : #else
1801 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type");
1802 : RETURN_FALSE;
1803 : #endif
1804 : }
1805 : /* }}} */
1806 :
1807 : /* {{{ proto bool oci_set_action(resource connection, string value)
1808 : Sets the action attribute on the connection */
1809 : PHP_FUNCTION(oci_set_action)
1810 15 : {
1811 : #if (OCI_MAJOR_VERSION >= 10)
1812 : zval *z_connection;
1813 : php_oci_connection *connection;
1814 : char *action;
1815 : long action_len;
1816 :
1817 15 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &action, &action_len) == FAILURE) {
1818 2 : return;
1819 : }
1820 :
1821 13 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1822 :
1823 13 : PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) action, (ub4) action_len, (ub4) OCI_ATTR_ACTION, OCI_G(err)));
1824 :
1825 13 : if (OCI_G(errcode) != OCI_SUCCESS) {
1826 1 : php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
1827 1 : RETURN_FALSE;
1828 : }
1829 :
1830 12 : RETURN_TRUE;
1831 : #else
1832 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type");
1833 : RETURN_FALSE;
1834 : #endif
1835 : }
1836 : /* }}} */
1837 :
1838 : /* {{{ proto bool oci_set_client_info(resource connection, string value)
1839 : Sets the client info attribute on the connection */
1840 : PHP_FUNCTION(oci_set_client_info)
1841 10 : {
1842 : #if (OCI_MAJOR_VERSION >= 10)
1843 : zval *z_connection;
1844 : php_oci_connection *connection;
1845 : char *client_info;
1846 : long client_info_len;
1847 :
1848 10 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_connection, &client_info, &client_info_len) == FAILURE) {
1849 1 : return;
1850 : }
1851 :
1852 9 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1853 :
1854 9 : PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrSet, ((dvoid *) connection->session, (ub4) OCI_HTYPE_SESSION, (dvoid *) client_info, (ub4) client_info_len, (ub4) OCI_ATTR_CLIENT_INFO, OCI_G(err)));
1855 :
1856 9 : if (OCI_G(errcode) != OCI_SUCCESS) {
1857 1 : php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
1858 1 : RETURN_FALSE;
1859 : }
1860 :
1861 8 : RETURN_TRUE;
1862 : #else
1863 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unsupported attribute type");
1864 : RETURN_FALSE;
1865 : #endif
1866 : }
1867 : /* }}} */
1868 :
1869 : /* {{{ proto bool oci_password_change(resource connection, string username, string old_password, string new_password)
1870 : Changes the password of an account */
1871 : PHP_FUNCTION(oci_password_change)
1872 8 : {
1873 : zval *z_connection;
1874 : char *user, *pass_old, *pass_new, *dbname;
1875 : int user_len, pass_old_len, pass_new_len, dbname_len;
1876 : php_oci_connection *connection;
1877 :
1878 : /* Disable in Safe Mode */
1879 8 : if (PG(safe_mode)) {
1880 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "is disabled in Safe Mode");
1881 1 : RETURN_FALSE;
1882 : }
1883 :
1884 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) {
1885 2 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1886 :
1887 2 : if (!user_len) {
1888 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "username cannot be empty");
1889 0 : RETURN_FALSE;
1890 : }
1891 2 : if (!pass_old_len) {
1892 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "old password cannot be empty");
1893 0 : RETURN_FALSE;
1894 : }
1895 2 : if (!pass_new_len) {
1896 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "new password cannot be empty");
1897 0 : RETURN_FALSE;
1898 : }
1899 :
1900 2 : if (php_oci_password_change(connection, user, user_len, pass_old, pass_old_len, pass_new, pass_new_len TSRMLS_CC)) {
1901 0 : RETURN_FALSE;
1902 : }
1903 2 : RETURN_TRUE;
1904 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) {
1905 :
1906 4 : if (!user_len) {
1907 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "username cannot be empty");
1908 0 : RETURN_FALSE;
1909 : }
1910 4 : if (!pass_old_len) {
1911 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "old password cannot be empty");
1912 0 : RETURN_FALSE;
1913 : }
1914 4 : if (!pass_new_len) {
1915 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "new password cannot be empty");
1916 0 : RETURN_FALSE;
1917 : }
1918 :
1919 4 : connection = php_oci_do_connect_ex(user, user_len, pass_old, pass_old_len, pass_new, pass_new_len, dbname, dbname_len, NULL, OCI_DEFAULT, 0, 0 TSRMLS_CC);
1920 4 : if (!connection) {
1921 0 : RETURN_FALSE;
1922 : }
1923 4 : RETURN_RESOURCE(connection->rsrc_id);
1924 : }
1925 1 : WRONG_PARAM_COUNT;
1926 : }
1927 : /* }}} */
1928 :
1929 : /* {{{ proto resource oci_new_cursor(resource connection)
1930 : Return a new cursor (Statement-Handle) - use this to bind ref-cursors! */
1931 : PHP_FUNCTION(oci_new_cursor)
1932 7 : {
1933 : zval *z_connection;
1934 : php_oci_connection *connection;
1935 : php_oci_statement *statement;
1936 :
1937 7 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1938 1 : return;
1939 : }
1940 :
1941 6 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1942 :
1943 6 : statement = php_oci_statement_create(connection, NULL, 0 TSRMLS_CC);
1944 :
1945 6 : if (statement) {
1946 6 : RETURN_RESOURCE(statement->id);
1947 : }
1948 0 : RETURN_FALSE;
1949 : }
1950 : /* }}} */
1951 :
1952 : /* {{{ proto string oci_result(resource stmt, mixed column)
1953 : Return a single column of result data */
1954 : PHP_FUNCTION(oci_result)
1955 106 : {
1956 : php_oci_out_column *column;
1957 :
1958 106 : column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
1959 106 : if(column) {
1960 103 : php_oci_column_to_zval(column, return_value, 0 TSRMLS_CC);
1961 : }
1962 : else {
1963 3 : RETURN_FALSE;
1964 : }
1965 : }
1966 : /* }}} */
1967 :
1968 : /* {{{ proto string oci_server_version(resource connection)
1969 : Return a string containing server version information */
1970 : PHP_FUNCTION(oci_server_version)
1971 49 : {
1972 : zval *z_connection;
1973 : php_oci_connection *connection;
1974 49 : char *version = NULL;
1975 :
1976 49 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_connection) == FAILURE) {
1977 1 : return;
1978 : }
1979 :
1980 48 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
1981 :
1982 48 : if (php_oci_server_get_version(connection, &version TSRMLS_CC)) {
1983 0 : RETURN_FALSE;
1984 : }
1985 :
1986 48 : RETURN_STRING(version, 0);
1987 : }
1988 : /* }}} */
1989 :
1990 : /* {{{ proto string oci_statement_type(resource stmt)
1991 : Return the query type of an OCI statement */
1992 : PHP_FUNCTION(oci_statement_type)
1993 27 : {
1994 : zval *z_statement;
1995 : php_oci_statement *statement;
1996 : ub2 type;
1997 :
1998 27 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
1999 1 : return;
2000 : }
2001 :
2002 26 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
2003 :
2004 26 : if (php_oci_statement_get_type(statement, &type TSRMLS_CC)) {
2005 0 : RETURN_FALSE;
2006 : }
2007 :
2008 26 : switch (type) {
2009 : case OCI_STMT_SELECT:
2010 2 : RETVAL_STRING("SELECT",1);
2011 2 : break;
2012 : case OCI_STMT_UPDATE:
2013 2 : RETVAL_STRING("UPDATE",1);
2014 2 : break;
2015 : case OCI_STMT_DELETE:
2016 2 : RETVAL_STRING("DELETE",1);
2017 2 : break;
2018 : case OCI_STMT_INSERT:
2019 2 : RETVAL_STRING("INSERT",1);
2020 2 : break;
2021 : case OCI_STMT_CREATE:
2022 4 : RETVAL_STRING("CREATE",1);
2023 4 : break;
2024 : case OCI_STMT_DROP:
2025 2 : RETVAL_STRING("DROP",1);
2026 2 : break;
2027 : case OCI_STMT_ALTER:
2028 2 : RETVAL_STRING("ALTER",1);
2029 2 : break;
2030 : case OCI_STMT_BEGIN:
2031 2 : RETVAL_STRING("BEGIN",1);
2032 2 : break;
2033 : case OCI_STMT_DECLARE:
2034 2 : RETVAL_STRING("DECLARE",1);
2035 2 : break;
2036 : case OCI_STMT_CALL:
2037 2 : RETVAL_STRING("CALL",1);
2038 2 : break;
2039 : default:
2040 4 : RETVAL_STRING("UNKNOWN",1);
2041 : }
2042 : }
2043 : /* }}} */
2044 :
2045 : /* {{{ proto int oci_num_rows(resource stmt)
2046 : Return the row count of an OCI statement */
2047 : PHP_FUNCTION(oci_num_rows)
2048 28 : {
2049 : zval *z_statement;
2050 : php_oci_statement *statement;
2051 : ub4 rowcount;
2052 :
2053 28 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_statement) == FAILURE) {
2054 3 : return;
2055 : }
2056 :
2057 25 : PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
2058 :
2059 25 : if (php_oci_statement_get_numrows(statement, &rowcount TSRMLS_CC)) {
2060 0 : RETURN_FALSE;
2061 : }
2062 25 : RETURN_LONG(rowcount);
2063 : }
2064 : /* }}} */
2065 :
2066 : /* {{{ proto bool oci_free_collection()
2067 : Deletes collection object*/
2068 : PHP_FUNCTION(oci_free_collection)
2069 5 : {
2070 5 : zval **tmp, *z_collection = getThis();
2071 : php_oci_collection *collection;
2072 :
2073 5 : if (!getThis()) {
2074 3 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
2075 1 : return;
2076 : }
2077 : }
2078 :
2079 4 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2080 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2081 0 : RETURN_FALSE;
2082 : }
2083 :
2084 4 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2085 :
2086 4 : zend_list_delete(collection->id);
2087 4 : RETURN_TRUE;
2088 : }
2089 : /* }}} */
2090 :
2091 : /* {{{ proto bool oci_collection_append(string value)
2092 : Append an object to the collection */
2093 : PHP_FUNCTION(oci_collection_append)
2094 33 : {
2095 33 : zval **tmp, *z_collection = getThis();
2096 : php_oci_collection *collection;
2097 : char *value;
2098 : int value_len;
2099 :
2100 33 : if (getThis()) {
2101 20 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
2102 0 : return;
2103 : }
2104 : }
2105 : else {
2106 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) {
2107 1 : return;
2108 : }
2109 : }
2110 :
2111 32 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2112 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2113 0 : RETURN_FALSE;
2114 : }
2115 :
2116 32 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2117 :
2118 32 : if (php_oci_collection_append(collection, value, value_len TSRMLS_CC)) {
2119 4 : RETURN_FALSE;
2120 : }
2121 28 : RETURN_TRUE;
2122 : }
2123 : /* }}} */
2124 :
2125 : /* {{{ proto string oci_collection_element_get(int ndx)
2126 : Retrieve the value at collection index ndx */
2127 : PHP_FUNCTION(oci_collection_element_get)
2128 48 : {
2129 48 : zval **tmp, *z_collection = getThis();
2130 : php_oci_collection *collection;
2131 : long element_index;
2132 : zval *value;
2133 :
2134 48 : if (getThis()) {
2135 34 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &element_index) == FAILURE) {
2136 0 : return;
2137 : }
2138 : }
2139 : else {
2140 14 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) {
2141 1 : return;
2142 : }
2143 : }
2144 :
2145 47 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2146 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2147 0 : RETURN_FALSE;
2148 : }
2149 :
2150 47 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2151 :
2152 47 : if (php_oci_collection_element_get(collection, element_index, &value TSRMLS_CC)) {
2153 18 : RETURN_FALSE;
2154 : }
2155 :
2156 29 : *return_value = *value;
2157 29 : zval_copy_ctor(return_value);
2158 29 : zval_ptr_dtor(&value);
2159 : }
2160 : /* }}} */
2161 :
2162 : /* {{{ proto bool oci_collection_assign(object from)
2163 : Assign a collection from another existing collection */
2164 : PHP_FUNCTION(oci_collection_assign)
2165 11 : {
2166 11 : zval **tmp_dest, **tmp_from, *z_collection_dest = getThis(), *z_collection_from;
2167 : php_oci_collection *collection_dest, *collection_from;
2168 :
2169 11 : if (getThis()) {
2170 6 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) {
2171 0 : return;
2172 : }
2173 : }
2174 : else {
2175 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) {
2176 0 : return;
2177 : }
2178 : }
2179 :
2180 11 : if (zend_hash_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection"), (void **)&tmp_dest) == FAILURE) {
2181 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property. The first argument should be valid collection object");
2182 0 : RETURN_FALSE;
2183 : }
2184 :
2185 11 : if (zend_hash_find(Z_OBJPROP_P(z_collection_from), "collection", sizeof("collection"), (void **)&tmp_from) == FAILURE) {
2186 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property. The second argument should be valid collection object");
2187 0 : RETURN_FALSE;
2188 : }
2189 :
2190 11 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp_dest, collection_dest);
2191 11 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp_from, collection_from);
2192 :
2193 11 : if (php_oci_collection_assign(collection_dest, collection_from TSRMLS_CC)) {
2194 0 : RETURN_FALSE;
2195 : }
2196 11 : RETURN_TRUE;
2197 : }
2198 : /* }}} */
2199 :
2200 : /* {{{ proto bool oci_collection_element_assign(int index, string val)
2201 : Assign element val to collection at index ndx */
2202 : PHP_FUNCTION(oci_collection_element_assign)
2203 21 : {
2204 21 : zval **tmp, *z_collection = getThis();
2205 : php_oci_collection *collection;
2206 : int value_len;
2207 : long element_index;
2208 : char *value;
2209 :
2210 21 : if (getThis()) {
2211 13 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element_index, &value, &value_len) == FAILURE) {
2212 0 : return;
2213 : }
2214 : }
2215 : else {
2216 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) {
2217 1 : return;
2218 : }
2219 : }
2220 :
2221 20 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2222 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2223 0 : RETURN_FALSE;
2224 : }
2225 :
2226 20 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2227 :
2228 20 : if (php_oci_collection_element_set(collection, element_index, value, value_len TSRMLS_CC)) {
2229 9 : RETURN_FALSE;
2230 : }
2231 11 : RETURN_TRUE;
2232 : }
2233 : /* }}} */
2234 :
2235 : /* {{{ proto int oci_collection_size()
2236 : Return the size of a collection */
2237 : PHP_FUNCTION(oci_collection_size)
2238 9 : {
2239 9 : zval **tmp, *z_collection = getThis();
2240 : php_oci_collection *collection;
2241 9 : sb4 size = 0;
2242 :
2243 9 : if (!getThis()) {
2244 4 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
2245 1 : return;
2246 : }
2247 : }
2248 :
2249 8 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2250 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2251 0 : RETURN_FALSE;
2252 : }
2253 :
2254 8 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2255 :
2256 4 : if (php_oci_collection_size(collection, &size TSRMLS_CC)) {
2257 0 : RETURN_FALSE;
2258 : }
2259 4 : RETURN_LONG(size);
2260 : }
2261 : /* }}} */
2262 :
2263 : /* {{{ proto int oci_collection_max()
2264 : Return the max value of a collection. For a varray this is the maximum length of the array */
2265 : PHP_FUNCTION(oci_collection_max)
2266 4 : {
2267 4 : zval **tmp, *z_collection = getThis();
2268 : php_oci_collection *collection;
2269 : long max;
2270 :
2271 4 : if (!getThis()) {
2272 2 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
2273 1 : return;
2274 : }
2275 : }
2276 :
2277 3 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2278 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2279 0 : RETURN_FALSE;
2280 : }
2281 :
2282 3 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2283 :
2284 3 : if (php_oci_collection_max(collection, &max TSRMLS_CC)) {
2285 0 : RETURN_FALSE;
2286 : }
2287 3 : RETURN_LONG(max);
2288 : }
2289 : /* }}} */
2290 :
2291 : /* {{{ proto bool oci_collection_trim(int num)
2292 : Trim num elements from the end of a collection */
2293 : PHP_FUNCTION(oci_collection_trim)
2294 10 : {
2295 10 : zval **tmp, *z_collection = getThis();
2296 : php_oci_collection *collection;
2297 : long trim_size;
2298 :
2299 10 : if (getThis()) {
2300 8 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &trim_size) == FAILURE) {
2301 1 : return;
2302 : }
2303 : }
2304 : else {
2305 2 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) {
2306 1 : return;
2307 : }
2308 : }
2309 :
2310 8 : if (zend_hash_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection"), (void **)&tmp) == FAILURE) {
2311 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find collection property");
2312 0 : RETURN_FALSE;
2313 : }
2314 :
2315 8 : PHP_OCI_ZVAL_TO_COLLECTION(*tmp, collection);
2316 :
2317 8 : if (php_oci_collection_trim(collection, trim_size TSRMLS_CC)) {
2318 3 : RETURN_FALSE;
2319 : }
2320 5 : RETURN_TRUE;
2321 : }
2322 : /* }}} */
2323 :
2324 : /* {{{ proto object oci_new_collection(resource connection, string tdo [, string schema])
2325 : Initialize a new collection */
2326 : PHP_FUNCTION(oci_new_collection)
2327 70054 : {
2328 : zval *z_connection;
2329 : php_oci_connection *connection;
2330 : php_oci_collection *collection;
2331 70054 : char *tdo, *schema = NULL;
2332 70054 : int tdo_len, schema_len = 0;
2333 :
2334 70054 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) {
2335 1 : return;
2336 : }
2337 :
2338 70053 : PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
2339 :
2340 70053 : if ( (collection = php_oci_collection_create(connection, tdo, tdo_len, schema, schema_len TSRMLS_CC)) ) {
2341 70047 : object_init_ex(return_value, oci_coll_class_entry_ptr);
2342 70047 : add_property_resource(return_value, "collection", collection->id);
2343 : }
2344 : else {
2345 6 : RETURN_FALSE;
2346 : }
2347 : }
2348 : /* }}} */
2349 :
2350 : #endif /* HAVE_OCI8 */
2351 :
2352 : /*
2353 : * Local variables:
2354 : * tab-width: 4
2355 : * c-basic-offset: 4
2356 : * End:
2357 : * vim600: noet sw=4 ts=4 fdm=marker
2358 : * vim<600: noet sw=4 ts=4
2359 : */
|