PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/oci8 - oci8_interface.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 841 1001 84.0 %
Date: 2016-09-18 Functions: 75 76 98.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:10 +0000 (6 days ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.