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

Generated by: LCOV version 1.10

Generated at Wed, 20 Jul 2016 02:56:21 +0000 (3 days ago)

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