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: 839 999 84.0 %
Date: 2016-05-26 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        4184 : PHP_FUNCTION(oci_bind_by_name)
     106             : {
     107        4184 :         ub2     bind_type = SQLT_CHR; /* unterminated string */
     108             :         size_t name_len;
     109        4184 :         zend_long maxlen = -1, type = 0;
     110             :         char *name;
     111             :         zval *z_statement;
     112        4184 :         zval *bind_var = NULL;
     113             :         php_oci_statement *statement;
     114             :         
     115        4184 :         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        4179 :         if (type) {
     120         416 :                 bind_type = (ub2) type;
     121             :         }
     122             :         
     123        4179 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
     124             : 
     125        4179 :         if (php_oci_bind_by_name(statement, name, name_len, bind_var, maxlen, bind_type)) {
     126          13 :                 RETURN_FALSE;
     127             :         }
     128        4166 :         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      181112 :         zval *tmp, *z_descriptor = getThis();
     172             :         php_oci_descriptor *descriptor;
     173             : 
     174      181112 :         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          29 :         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          52 :         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          13 :         zval *tmp, *z_descriptor = getThis();
     238             :         php_oci_descriptor *descriptor;
     239             :         char *filename;
     240             :         size_t filename_len;
     241             : 
     242          18 :         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          77 :         zval *tmp, *z_descriptor = getThis();
     272             :         php_oci_descriptor *descriptor;
     273          77 :         char *buffer = NULL;
     274             :         ub4 buffer_len;
     275             : 
     276          77 :         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         448 :         zval *tmp, *z_descriptor = getThis();
     309             :         php_oci_descriptor *descriptor;
     310             :         zend_long length;
     311             :         char *buffer;
     312             :         ub4 buffer_len;
     313             : 
     314         888 :         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          18 :         zval *tmp, *z_descriptor = getThis();
     356             :         php_oci_descriptor *descriptor;
     357             :         ub4 lob_length;
     358             :         
     359          18 :         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         420 :         zval *tmp, *z_descriptor = getThis();
     386             :         php_oci_descriptor *descriptor;
     387             :         
     388         420 :         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           4 :         zval *tmp, *z_descriptor = getThis();
     410             :         php_oci_descriptor *descriptor;
     411             :         
     412           4 :         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          23 :         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          42 :         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         211 :         zval *tmp, *z_descriptor = getThis();
     492             :         php_oci_descriptor *descriptor;
     493             :         ub4 lob_length;
     494             :         
     495         211 :         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          57 :         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         110 :         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           5 :         zval *tmp_dest, *tmp_from, *z_descriptor_dest = getThis(), *z_descriptor_from;
     568             :         php_oci_descriptor *descriptor_dest, *descriptor_from;
     569             :         
     570           6 :         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          15 :         zval *tmp, *z_descriptor = getThis();
     607             :         php_oci_descriptor *descriptor;
     608          15 :         zend_long trim_length = 0;
     609             :         ub4 ub_trim_length;
     610             :         
     611          29 :         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          15 :         zval *tmp, *z_descriptor = getThis();
     647             :         php_oci_descriptor *descriptor;
     648             :         ub4 bytes_erased;
     649          15 :         zend_long offset = -1, length = -1;
     650             :         
     651          19 :         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           9 :         zval *tmp, *z_descriptor = getThis();
     701             :         php_oci_descriptor *descriptor;
     702           9 :         zend_long flush_flag = 0;
     703             :         
     704          17 :         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           7 :         zval *tmp, *z_descriptor = getThis();
     739             :         php_oci_descriptor *descriptor;
     740             :         zend_bool flag;
     741             :         
     742          13 :         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           4 :         zval *tmp, *z_descriptor = getThis();
     772             :         php_oci_descriptor *descriptor;
     773             :         
     774           4 :         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           5 :         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           6 :         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         117 :         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         234 :         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         115 :         zval *tmp, *z_descriptor = getThis();
    1023             :         php_oci_descriptor *descriptor;
    1024             :         
    1025         115 :         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       37842 : PHP_FUNCTION(oci_execute)
    1296             : {
    1297             :         zval *z_statement;
    1298             :         php_oci_statement *statement;
    1299       37842 :         zend_long mode = OCI_COMMIT_ON_SUCCESS;
    1300             : 
    1301       37842 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &z_statement, &mode) == FAILURE) {
    1302           1 :                 return;
    1303             :         }
    1304             : 
    1305       37841 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    1306             : 
    1307       37841 :         if (php_oci_statement_execute(statement, (ub4) mode)) {
    1308         262 :                 RETURN_FALSE;
    1309             :         }
    1310       37579 :         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         136 : 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         136 :         ub4 nrows = 1;
    1373             :         int i;
    1374         136 :         zend_long rows = 0, flags = 0, skip = 0, maxrows = -1;
    1375             : 
    1376         136 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/|lll", &z_statement, &array, &skip, &maxrows, &flags) == FAILURE) {
    1377           1 :                 return;
    1378             :         }
    1379             : 
    1380         135 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    1381             : 
    1382         135 :         zval_dtor(array);
    1383         135 :         array_init(array);
    1384             : 
    1385         135 :         while (skip--) {
    1386           8 :                 if (php_oci_statement_fetch(statement, nrows)) {
    1387           2 :                         RETURN_LONG(0);
    1388             :                 }
    1389             :         }
    1390             : 
    1391         133 :         if (flags & PHP_OCI_FETCHSTATEMENT_BY_ROW) {
    1392          17 :                 columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
    1393             : 
    1394          75 :                 for (i = 0; i < statement->ncolumns; i++) {
    1395          58 :                         columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
    1396             :                 }
    1397             : 
    1398          78 :                 while (!php_oci_statement_fetch(statement, nrows)) {
    1399             :                         zval row;
    1400             :                         
    1401          46 :                         array_init(&row);
    1402             : 
    1403         217 :                         for (i = 0; i < statement->ncolumns; i++) {
    1404         171 :                                 php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS);
    1405             : 
    1406         171 :                                 if (flags & PHP_OCI_NUM) {
    1407          42 :                                         zend_hash_next_index_insert(Z_ARRVAL(row), &element);
    1408             :                                 } else { /* default to ASSOC */
    1409             :                                         zend_string *zvtmp;
    1410         258 :                                         zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
    1411         129 :                                         zend_symtable_update(Z_ARRVAL(row), zvtmp, &element);
    1412             :                    zend_string_release(zvtmp);
    1413             :                                 }
    1414             :                         }
    1415             : 
    1416          46 :                         zend_hash_next_index_insert(Z_ARRVAL_P(array), &row);
    1417          46 :                         rows++;
    1418             : 
    1419          46 :                         if (maxrows != -1 && rows == maxrows) {
    1420           2 :                                 php_oci_statement_cancel(statement);
    1421           2 :                                 break;
    1422             :                         }
    1423             :                 }
    1424          17 :                 efree(columns);
    1425             : 
    1426             :         } else { /* default to BY_COLUMN */
    1427         116 :                 columns = safe_emalloc(statement->ncolumns, sizeof(php_oci_out_column *), 0);
    1428         116 :                 outarrs = safe_emalloc(statement->ncolumns, sizeof(zval*), 0);
    1429             :                 
    1430         116 :                 if (flags & PHP_OCI_NUM) {
    1431          24 :                         for (i = 0; i < statement->ncolumns; i++) {
    1432          18 :                                 columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
    1433             :                                 
    1434          18 :                                 array_init(&tmp);
    1435          18 :                                 outarrs[ i ] = zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp);
    1436             :                         }
    1437             :                 } else { /* default to ASSOC */
    1438         275 :                         for (i = 0; i < statement->ncolumns; i++) {
    1439             :                                 zend_string *zvtmp;
    1440         165 :                                 columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0);
    1441             :                                 
    1442         165 :                                 array_init(&tmp);
    1443         330 :                 zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
    1444         330 :                                 outarrs[ i ] = zend_symtable_update(Z_ARRVAL_P(array), zvtmp, &tmp);
    1445             :                zend_string_release(zvtmp);
    1446             :                         }
    1447             :                 }
    1448             : 
    1449         403 :                 while (!php_oci_statement_fetch(statement, nrows)) {
    1450         492 :                         for (i = 0; i < statement->ncolumns; i++) {
    1451         319 :                                 php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS);
    1452         319 :                                 zend_hash_index_update(Z_ARRVAL_P(outarrs[ i ]), rows, &element);
    1453             :                         }
    1454             : 
    1455         173 :                         rows++;
    1456             : 
    1457         173 :                         if (maxrows != -1 && rows == maxrows) {
    1458           2 :                                 php_oci_statement_cancel(statement);
    1459           2 :                                 break;
    1460             :                         }
    1461             :                 }
    1462             :                 
    1463         116 :                 efree(columns);
    1464         116 :                 efree(outarrs);
    1465             :         }
    1466             : 
    1467         133 :         RETURN_LONG(rows);
    1468             : }
    1469             : /* }}} */
    1470             : 
    1471             : /* {{{ proto object oci_fetch_object( resource stmt )
    1472             :    Fetch a result row as an object */
    1473          26 : PHP_FUNCTION(oci_fetch_object)
    1474             : {
    1475          26 :         php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 2);
    1476             : 
    1477          26 :         if (Z_TYPE_P(return_value) == IS_ARRAY) {
    1478          20 :                 object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value));
    1479             :         }
    1480          26 : }
    1481             : /* }}} */
    1482             : 
    1483             : /* {{{ proto array oci_fetch_row( resource stmt )
    1484             :    Fetch a result row as an enumerated array */
    1485          67 : PHP_FUNCTION(oci_fetch_row)
    1486             : {
    1487          67 :         php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_NUM | PHP_OCI_RETURN_NULLS, 1);
    1488          67 : }
    1489             : /* }}} */
    1490             : 
    1491             : /* {{{ proto array oci_fetch_assoc( resource stmt )
    1492             :    Fetch a result row as an associative array */
    1493      120061 : PHP_FUNCTION(oci_fetch_assoc)
    1494             : {
    1495      120061 :         php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_ASSOC | PHP_OCI_RETURN_NULLS, 1);
    1496      120061 : }
    1497             : /* }}} */
    1498             : 
    1499             : /* {{{ proto array oci_fetch_array( resource stmt [, int mode ])
    1500             :    Fetch a result row as an array */
    1501      104709 : PHP_FUNCTION(oci_fetch_array)
    1502             : {
    1503      104709 :         php_oci_fetch_row(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_OCI_BOTH | PHP_OCI_RETURN_NULLS, 2);
    1504      104709 : }
    1505             : /* }}} */
    1506             : 
    1507             : /* {{{ proto bool oci_free_statement(resource stmt)
    1508             :    Free all resources associated with a statement */
    1509       32154 : PHP_FUNCTION(oci_free_statement)
    1510             : {
    1511             :         zval *z_statement;
    1512             :         php_oci_statement *statement;
    1513             : 
    1514       32154 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
    1515           3 :                 return;
    1516             :         }
    1517             : 
    1518       32151 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    1519             : 
    1520       32151 :         zend_list_close(statement->id);
    1521       32151 :         RETURN_TRUE;
    1522             : }
    1523             : /* }}} */
    1524             : 
    1525             : /* {{{ proto bool oci_close(resource connection)
    1526             :    Disconnect from database */
    1527          75 : PHP_FUNCTION(oci_close)
    1528             : {
    1529             :         /* oci_close for pconnect (if old_oci_close_semantics not set) would
    1530             :          * release the connection back to the client-side session pool (and to the
    1531             :          * server-side pool if Database Resident Connection Pool is being used).
    1532             :          * Subsequent pconnects in the same script are not guaranteed to get the
    1533             :          * same database session.
    1534             :          */
    1535             : 
    1536             :         zval *z_connection;
    1537             :         php_oci_connection *connection;
    1538             : 
    1539          75 :         if (OCI_G(old_oci_close_semantics)) {
    1540             :                 /* do nothing to keep BC */
    1541           8 :                 return;
    1542             :         }
    1543             :         
    1544          67 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_connection) == FAILURE) {
    1545           1 :                 return;
    1546             :         }
    1547             : 
    1548          66 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1549          66 :         if (GC_REFCOUNT(connection->id) == 2) /* CHANGED VERSION::PHP7
    1550             :                                                                                          Changed the refCount to 2 since
    1551             :                                                                                          internally Zend engine increments
    1552             :                                                                                          RefCount value by 1 */
    1553          47 :                 zend_list_close(connection->id);
    1554             : 
    1555             :         /* ZVAL_NULL(z_connection); */
    1556             :         
    1557          66 :         RETURN_TRUE;
    1558             : }
    1559             : /* }}} */
    1560             : 
    1561             : /* {{{ proto resource oci_new_connect(string user, string pass [, string db, string charset [, int session_mode ]])
    1562             :    Connect to an Oracle database and log on. Returns a new session. */
    1563          49 : PHP_FUNCTION(oci_new_connect)
    1564             : {
    1565          49 :         php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
    1566          49 : }
    1567             : /* }}} */
    1568             : 
    1569             : /* {{{ proto resource oci_connect(string user, string pass [, string db [, string charset [, int session_mode ]])
    1570             :    Connect to an Oracle database and log on. Returns a new session. */
    1571         582 : PHP_FUNCTION(oci_connect)
    1572             : {
    1573         582 :         php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
    1574         582 : }
    1575             : /* }}} */
    1576             : 
    1577             : /* {{{ proto resource oci_pconnect(string user, string pass [, string db [, string charset [, int session_mode ]])
    1578             :    Connect to an Oracle database using a persistent connection and log on. Returns a new session. */
    1579          60 : PHP_FUNCTION(oci_pconnect)
    1580             : {
    1581          60 :         php_oci_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
    1582          60 : }
    1583             : /* }}} */
    1584             : 
    1585             : /* {{{ proto array oci_error([resource stmt|connection|global])
    1586             :    Return the last error of stmt|connection|global. If no error happened returns false. */
    1587         258 : PHP_FUNCTION(oci_error)
    1588             : {
    1589         258 :         zval *arg = NULL;
    1590             :         php_oci_statement *statement;
    1591             :         php_oci_connection *connection;
    1592             :         text errbuf[PHP_OCI_ERRBUF_LEN];
    1593         258 :         sb4 errcode = 0;
    1594         258 :         dvoid *errh = NULL;
    1595         258 :         ub2 error_offset = 0;
    1596         258 :         text *sqltext = NULL;
    1597             : 
    1598         258 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &arg) == FAILURE) {
    1599           2 :                 return;
    1600             :         }
    1601             : 
    1602         256 :         if (ZEND_NUM_ARGS() > 0) {
    1603         206 :                 statement = (php_oci_statement *) zend_fetch_resource_ex(arg, NULL, le_statement);
    1604         206 :                 if (statement) {
    1605         171 :                         errh = statement->err;
    1606         171 :                         errcode = statement->errcode;
    1607             : 
    1608         171 :                         if (php_oci_fetch_sqltext_offset(statement, &sqltext, &error_offset)) {
    1609           0 :                                 RETURN_FALSE;
    1610             :                         }
    1611         171 :                         goto go_out;
    1612             :                 }
    1613             : 
    1614          35 :                 connection = (php_oci_connection *) zend_fetch_resource_ex(arg, NULL, le_connection);
    1615          35 :                 if (connection) {
    1616          31 :                         errh = connection->err;
    1617          31 :                         errcode = connection->errcode;
    1618          31 :                         goto go_out;
    1619             :                 }
    1620             : 
    1621           4 :                 connection = (php_oci_connection *) zend_fetch_resource_ex(arg, NULL, le_pconnection);
    1622           4 :                 if (connection) {
    1623           4 :                         errh = connection->err;
    1624           4 :                         errcode = connection->errcode;
    1625           4 :                         goto go_out;
    1626             :                 }
    1627             :         } else {
    1628          50 :                 errh = OCI_G(err);
    1629          50 :                 errcode = OCI_G(errcode);
    1630             :         }
    1631             : 
    1632             : go_out:
    1633         256 :         if (errcode == 0) { /* no error set in the handle */
    1634          53 :                 RETURN_FALSE;
    1635             :         }
    1636             : 
    1637         203 :         if (!errh) {
    1638           0 :                 php_error_docref(NULL, E_WARNING, "Oci_error: unable to find error handle");
    1639           0 :                 RETURN_FALSE;
    1640             :         }
    1641             : 
    1642         203 :         errcode = php_oci_fetch_errmsg(errh, errbuf, sizeof(errbuf));
    1643             : 
    1644         203 :         if (errcode) {
    1645         203 :                 array_init(return_value);
    1646         203 :                 add_assoc_long(return_value, "code", errcode);
    1647             :                 /* TODO: avoid reallocation ??? */
    1648         203 :                 add_assoc_string(return_value, "message", (char*) errbuf);
    1649         203 :                 add_assoc_long(return_value, "offset", error_offset);
    1650         203 :                 add_assoc_string(return_value, "sqltext", sqltext ? (char *) sqltext : "");
    1651             :         } else {
    1652           0 :                 RETURN_FALSE;
    1653             :         }
    1654             : }
    1655             : /* }}} */
    1656             : 
    1657             : /* {{{ proto int oci_num_fields(resource stmt)
    1658             :    Return the number of result columns in a statement */
    1659          41 : PHP_FUNCTION(oci_num_fields)
    1660             : {
    1661             :         zval *z_statement;
    1662             :         php_oci_statement *statement;
    1663             : 
    1664          41 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
    1665           3 :                 return;
    1666             :         }
    1667             : 
    1668          38 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    1669             : 
    1670          38 :         RETURN_LONG(statement->ncolumns);
    1671             : }
    1672             : /* }}} */
    1673             : 
    1674             : /* {{{ proto resource oci_parse(resource connection, string statement)
    1675             :    Parse a SQL or PL/SQL statement and return a statement resource */
    1676       33071 : PHP_FUNCTION(oci_parse)
    1677             : {
    1678             :         zval *z_connection;
    1679             :         php_oci_connection *connection;
    1680             :         php_oci_statement *statement;
    1681             :         char *query;
    1682             :         size_t query_len;
    1683             : 
    1684       33071 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &query, &query_len) == FAILURE) {
    1685           1 :                 return;
    1686             :         }
    1687             : 
    1688       33070 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1689             : 
    1690       33069 :         statement = php_oci_statement_create(connection, query, (int) query_len);
    1691             : 
    1692       33069 :         if (statement) {
    1693       33064 :                 RETURN_RES(statement->id);
    1694             :         }
    1695           5 :         RETURN_FALSE;
    1696             : }
    1697             : /* }}} */
    1698             : 
    1699             : /* {{{ proto bool oci_set_prefetch(resource stmt, int prefetch_rows)
    1700             :   Sets the number of rows to be prefetched on execute to prefetch_rows for stmt */
    1701          19 : PHP_FUNCTION(oci_set_prefetch)
    1702             : {
    1703             :         zval *z_statement;
    1704             :         php_oci_statement *statement;
    1705             :         zend_long size;
    1706             : 
    1707          19 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &z_statement, &size) == FAILURE) {
    1708           1 :                 return;
    1709             :         }
    1710             : 
    1711          18 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    1712             : 
    1713          18 :         if (size < 0) {
    1714           2 :                 php_error_docref(NULL, E_WARNING, "Number of rows to be prefetched has to be greater than or equal to 0");
    1715           2 :                 return;
    1716             :         }
    1717             : 
    1718          16 :         if (php_oci_statement_set_prefetch(statement, (ub4)size)) {
    1719           0 :                 RETURN_FALSE;
    1720             :         }
    1721          16 :         RETURN_TRUE;
    1722             : }
    1723             : /* }}} */
    1724             : 
    1725             : /* {{{ proto bool oci_set_client_identifier(resource connection, string value)
    1726             :   Sets the client identifier attribute on the connection */
    1727          11 : PHP_FUNCTION(oci_set_client_identifier)
    1728             : {
    1729             :         zval *z_connection;
    1730             :         php_oci_connection *connection;
    1731             :         char *client_id;
    1732             :         size_t client_id_len;
    1733             :         sword errstatus;
    1734             : 
    1735          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &client_id, &client_id_len) == FAILURE) {
    1736           0 :                 return;
    1737             :         }
    1738             : 
    1739          11 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1740             : 
    1741          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));
    1742             : 
    1743          11 :         if (errstatus != OCI_SUCCESS) {
    1744           2 :                 connection->errcode = php_oci_error(connection->err, errstatus);
    1745           2 :                 RETURN_FALSE;
    1746             :         }
    1747             : 
    1748             : #ifdef HAVE_OCI8_DTRACE
    1749             :         /* The alternatives to storing client_id like done below are
    1750             :            i) display it in a probe here in oci_set_client_identifier and
    1751             :            let the user D script correlate the connection address probe
    1752             :            argument and the client_id. This would likely require user D
    1753             :            script variables, which would use kernel memory.
    1754             :            ii) call OCIAttrGet for each probe definition that uses
    1755             :            client_id. This would be slower than storing it.
    1756             :         */
    1757             : 
    1758             :         if (connection->client_id) {
    1759             :                 pefree(connection->client_id, connection->is_persistent);
    1760             :         }
    1761             : 
    1762             :         if (client_id) {
    1763             :                 /* this long winded copy allows compatibility with older PHP versions */
    1764             :                 connection->client_id = (char *)pemalloc(client_id_len+1, connection->is_persistent);
    1765             :                 memcpy(connection->client_id, client_id, client_id_len);
    1766             :                 connection->client_id[client_id_len] = '\0';
    1767             :         } else {
    1768             :                 connection->client_id = NULL;
    1769             :         }
    1770             : #endif /* HAVE_OCI8_DTRACE */
    1771             : 
    1772           9 :         RETURN_TRUE;
    1773             : }
    1774             : /* }}} */
    1775             : 
    1776             : /* {{{ proto bool oci_set_edition(string value)
    1777             :   Sets the edition attribute for all subsequent connections created */
    1778          14 : PHP_FUNCTION(oci_set_edition)
    1779             : {
    1780             : #if ((OCI_MAJOR_VERSION > 11) || ((OCI_MAJOR_VERSION == 11) && (OCI_MINOR_VERSION >= 2)))
    1781             :         char *edition;
    1782             :         size_t edition_len;
    1783             : 
    1784          14 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &edition, &edition_len) == FAILURE) {
    1785           0 :                 return;
    1786             :         }
    1787             : 
    1788          14 :         if (OCI_G(edition)) {
    1789          12 :                 efree(OCI_G(edition));
    1790             :         }
    1791             : 
    1792          14 :         if (edition) {
    1793          14 :                 OCI_G(edition) = (char *)safe_emalloc(edition_len+1, sizeof(char), 0);
    1794          14 :                 memcpy(OCI_G(edition), edition, edition_len);
    1795          14 :                 OCI_G(edition)[edition_len] = '\0';
    1796             :         } else {
    1797           0 :                 OCI_G(edition) = NULL;
    1798             :         }
    1799             : 
    1800          14 :         RETURN_TRUE;
    1801             : #else
    1802             :         php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
    1803             :         RETURN_FALSE;
    1804             : #endif
    1805             : }
    1806             : /* }}} */
    1807             : 
    1808             : /* {{{ proto bool oci_set_module_name(resource connection, string value)
    1809             :   Sets the module attribute on the connection for end-to-end tracing */
    1810          11 : PHP_FUNCTION(oci_set_module_name)
    1811             : {
    1812             : #if (OCI_MAJOR_VERSION >= 10)
    1813             :         zval *z_connection;
    1814             :         php_oci_connection *connection;
    1815             :         char *module;
    1816             :         size_t module_len;
    1817             :         sword errstatus;
    1818             : 
    1819          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &module, &module_len) == FAILURE) {
    1820           0 :                 return;
    1821             :         }
    1822             : 
    1823          11 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1824             : 
    1825          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));
    1826             : 
    1827          11 :         if (errstatus != OCI_SUCCESS) {
    1828           2 :                 connection->errcode = php_oci_error(connection->err, errstatus);
    1829           2 :                 RETURN_FALSE;
    1830             :         }
    1831             : 
    1832           9 :         RETURN_TRUE;
    1833             : #else
    1834             :         php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
    1835             :         RETURN_FALSE;
    1836             : #endif
    1837             : }
    1838             : /* }}} */
    1839             : 
    1840             : /* {{{ proto bool oci_set_action(resource connection, string value)
    1841             :   Sets the action attribute on the connection for end-to-end tracing */
    1842          17 : PHP_FUNCTION(oci_set_action)
    1843             : {
    1844             : #if (OCI_MAJOR_VERSION >= 10)
    1845             :         zval *z_connection;
    1846             :         php_oci_connection *connection;
    1847             :         char *action;
    1848             :         size_t action_len;
    1849             :         sword errstatus;
    1850             : 
    1851          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &action, &action_len) == FAILURE) {
    1852           2 :                 return;
    1853             :         }
    1854             : 
    1855          15 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1856             : 
    1857          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));
    1858             : 
    1859          15 :         if (errstatus != OCI_SUCCESS) {
    1860           2 :                 connection->errcode = php_oci_error(connection->err, errstatus);
    1861           2 :                 RETURN_FALSE;
    1862             :         }
    1863             : 
    1864          13 :         RETURN_TRUE;
    1865             : #else
    1866             :         php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
    1867             :         RETURN_FALSE;
    1868             : #endif
    1869             : }
    1870             : /* }}} */
    1871             : 
    1872             : /* {{{ proto bool oci_set_client_info(resource connection, string value)
    1873             :   Sets the client info attribute on the connection  for end-to-end tracing */
    1874          12 : PHP_FUNCTION(oci_set_client_info)
    1875             : {
    1876             : #if (OCI_MAJOR_VERSION >= 10)
    1877             :         zval *z_connection;
    1878             :         php_oci_connection *connection;
    1879             :         char *client_info;
    1880             :         size_t client_info_len;
    1881             :         sword errstatus;
    1882             : 
    1883          12 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &client_info, &client_info_len) == FAILURE) {
    1884           1 :                 return;
    1885             :         }
    1886             : 
    1887          11 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1888             : 
    1889          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));
    1890             : 
    1891          11 :         if (errstatus != OCI_SUCCESS) {
    1892           2 :                 connection->errcode = php_oci_error(connection->err, errstatus);
    1893           2 :                 RETURN_FALSE;
    1894             :         }
    1895             : 
    1896           9 :         RETURN_TRUE;
    1897             : #else
    1898             :         php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
    1899             :         RETURN_FALSE;
    1900             : #endif
    1901             : }
    1902             : /* }}} */
    1903             : 
    1904             : #ifdef WAITIING_ORACLE_BUG_16695981_FIX
    1905             : /* {{{ proto bool oci_set_db_operation(resource connection, string value)
    1906             :    Sets the "DB operation" on the connection for Oracle end-to-end tracing */
    1907             : PHP_FUNCTION(oci_set_db_operation)
    1908             : {
    1909             : #if (OCI_MAJOR_VERSION > 11)
    1910             :         zval *z_connection;
    1911             :         php_oci_connection *connection;
    1912             :         char *dbop_name;
    1913             :         size_t dbop_name_len;
    1914             : 
    1915             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_connection, &dbop_name, &dbop_name_len) == FAILURE) {
    1916             :                 return;
    1917             :         }
    1918             : 
    1919             :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1920             : 
    1921             :         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)));
    1922             : 
    1923             :         if (OCI_G(errcode) != OCI_SUCCESS) {
    1924             :                 php_oci_error(OCI_G(err), OCI_G(errcode));
    1925             :                 RETURN_FALSE;
    1926             :         }
    1927             :         RETURN_TRUE;
    1928             : #else
    1929             :         php_error_docref(NULL, E_NOTICE, "Unsupported attribute type");
    1930             :         RETURN_FALSE;
    1931             : #endif
    1932             : }
    1933             : /* }}} */
    1934             : #endif /* WAITIING_ORACLE_BUG_16695981_FIX */
    1935             : 
    1936             : /* {{{ proto bool oci_password_change(resource connection, string username, string old_password, string new_password)
    1937             :   Changes the password of an account */
    1938           7 : PHP_FUNCTION(oci_password_change)
    1939             : {
    1940             :         zval *z_connection;
    1941             :         char *user, *pass_old, *pass_new, *dbname;
    1942             :         size_t user_len, pass_old_len, pass_new_len, dbname_len;
    1943             :         php_oci_connection *connection;
    1944             : 
    1945           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) {
    1946           2 :                 PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    1947             : 
    1948           2 :                 if (!user_len) {
    1949           0 :                         php_error_docref(NULL, E_WARNING, "username cannot be empty");
    1950           0 :                         RETURN_FALSE;
    1951             :                 }
    1952           2 :                 if (!pass_old_len) {
    1953           0 :                         php_error_docref(NULL, E_WARNING, "old password cannot be empty");
    1954           0 :                         RETURN_FALSE;
    1955             :                 }
    1956           2 :                 if (!pass_new_len) {
    1957           0 :                         php_error_docref(NULL, E_WARNING, "new password cannot be empty");
    1958           0 :                         RETURN_FALSE;
    1959             :                 }
    1960             : 
    1961           2 :                 if (php_oci_password_change(connection, user, (int) user_len, pass_old, (int) pass_old_len, pass_new, (int) pass_new_len)) {
    1962           0 :                         RETURN_FALSE;
    1963             :                 }
    1964           2 :                 RETURN_TRUE;
    1965           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) {
    1966             : 
    1967           4 :                 if (!user_len) {
    1968           0 :                         php_error_docref(NULL, E_WARNING, "username cannot be empty");
    1969           0 :                         RETURN_FALSE;
    1970             :                 }
    1971           4 :                 if (!pass_old_len) {
    1972           0 :                         php_error_docref(NULL, E_WARNING, "old password cannot be empty");
    1973           0 :                         RETURN_FALSE;
    1974             :                 }
    1975           4 :                 if (!pass_new_len) {
    1976           0 :                         php_error_docref(NULL, E_WARNING, "new password cannot be empty");
    1977           0 :                         RETURN_FALSE;
    1978             :                 }
    1979             : 
    1980           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);
    1981           4 :                 if (!connection) {
    1982           0 :                         RETURN_FALSE;
    1983             :                 }
    1984           4 :                 RETURN_RES(connection->id);
    1985             :         }
    1986           1 :         WRONG_PARAM_COUNT;
    1987             : }
    1988             : /* }}} */
    1989             : 
    1990             : /* {{{ proto resource oci_new_cursor(resource connection)
    1991             :    Return a new cursor (Statement-Handle) - use this to bind ref-cursors! */
    1992          27 : PHP_FUNCTION(oci_new_cursor)
    1993             : {
    1994             :         zval *z_connection;
    1995             :         php_oci_connection *connection;
    1996             :         php_oci_statement *statement;
    1997             : 
    1998          27 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_connection) == FAILURE) {
    1999           1 :                 return;
    2000             :         }
    2001             : 
    2002          26 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    2003             : 
    2004          26 :         statement = php_oci_statement_create(connection, NULL, 0);
    2005             :         
    2006          26 :         if (statement) {
    2007          26 :                 RETURN_RES(statement->id);
    2008             :         }
    2009           0 :         RETURN_FALSE;
    2010             : }
    2011             : /* }}} */
    2012             : 
    2013             : /* {{{ proto string oci_result(resource stmt, mixed column)
    2014             :    Return a single column of result data */
    2015         130 : PHP_FUNCTION(oci_result)
    2016             : {
    2017             :         php_oci_out_column *column;
    2018             :         
    2019         130 :         column = php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    2020         130 :         if(column) {
    2021         127 :                 php_oci_column_to_zval(column, return_value, 0);
    2022             :         }
    2023             :         else {
    2024           3 :                 RETURN_FALSE;
    2025             :         }
    2026             : }
    2027             : /* }}} */
    2028             : 
    2029             : /* {{{ proto string oci_client_version()
    2030             :    Return a string containing runtime client library version information */
    2031          19 : PHP_FUNCTION(oci_client_version)
    2032             : {
    2033             :         char version[256];
    2034             : 
    2035          19 :         php_oci_client_get_version(version, sizeof(version));
    2036          38 :         RETURN_STRING(version);
    2037             : }
    2038             : /* }}} */
    2039             : 
    2040             : /* {{{ proto string oci_server_version(resource connection)
    2041             :    Return a string containing server version information */
    2042         310 : PHP_FUNCTION(oci_server_version)
    2043             : {
    2044             :         zval *z_connection;
    2045             :         php_oci_connection *connection;
    2046             :         char version[256];
    2047             :         zend_string *ret;
    2048             : 
    2049         310 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_connection) == FAILURE) {
    2050           1 :                 return;
    2051             :         }
    2052             : 
    2053         309 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    2054             : 
    2055         309 :         if (php_oci_server_get_version(connection, version, sizeof(version))) {
    2056           0 :                 RETURN_FALSE;
    2057             :         }
    2058             :         
    2059         618 :         ret = zend_string_init(version, strlen(version), 0);
    2060         309 :         RETURN_STR(ret);
    2061             : }
    2062             : /* }}} */
    2063             : 
    2064             : /* {{{ proto string oci_statement_type(resource stmt)
    2065             :    Return the query type of an OCI statement */
    2066          27 : PHP_FUNCTION(oci_statement_type)
    2067             : {
    2068             :         zval *z_statement;
    2069             :         php_oci_statement *statement;
    2070             :         ub2 type;
    2071             : 
    2072          27 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
    2073           1 :                 return;
    2074             :         }
    2075             : 
    2076          26 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    2077             : 
    2078          26 :         if (php_oci_statement_get_type(statement, &type)) {
    2079           0 :                 RETURN_FALSE;
    2080             :         }
    2081             : 
    2082          26 :         switch (type) {
    2083             :                 case OCI_STMT_SELECT:
    2084           4 :                         RETVAL_STRING("SELECT");
    2085           2 :                         break;
    2086             :                 case OCI_STMT_UPDATE:
    2087           4 :                         RETVAL_STRING("UPDATE");
    2088           2 :                         break;
    2089             :                 case OCI_STMT_DELETE:
    2090           4 :                         RETVAL_STRING("DELETE");
    2091           2 :                         break;
    2092             :                 case OCI_STMT_INSERT:
    2093           4 :                         RETVAL_STRING("INSERT");
    2094           2 :                         break;
    2095             :                 case OCI_STMT_CREATE:
    2096           8 :                         RETVAL_STRING("CREATE");
    2097           4 :                         break;
    2098             :                 case OCI_STMT_DROP:
    2099           4 :                         RETVAL_STRING("DROP");
    2100           2 :                         break;
    2101             :                 case OCI_STMT_ALTER:
    2102           4 :                         RETVAL_STRING("ALTER");
    2103           2 :                         break;
    2104             :                 case OCI_STMT_BEGIN:
    2105           4 :                         RETVAL_STRING("BEGIN");
    2106           2 :                         break;
    2107             :                 case OCI_STMT_DECLARE:
    2108           4 :                         RETVAL_STRING("DECLARE");
    2109           2 :                         break;
    2110             :                 case OCI_STMT_CALL:
    2111           4 :                         RETVAL_STRING("CALL");
    2112           2 :                         break;
    2113             :                 default:
    2114           8 :                         RETVAL_STRING("UNKNOWN");
    2115             :         }
    2116             : }
    2117             : /* }}} */
    2118             : 
    2119             : /* {{{ proto int oci_num_rows(resource stmt)
    2120             :    Return the row count of an OCI statement */
    2121          29 : PHP_FUNCTION(oci_num_rows)
    2122             : {
    2123             :         zval *z_statement;
    2124             :         php_oci_statement *statement;
    2125             :         ub4 rowcount;
    2126             : 
    2127          29 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
    2128           3 :                 return;
    2129             :         }
    2130             : 
    2131          26 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    2132             : 
    2133          26 :         if (php_oci_statement_get_numrows(statement, &rowcount)) {
    2134           0 :                 RETURN_FALSE;
    2135             :         }
    2136          26 :         RETURN_LONG(rowcount);
    2137             : }
    2138             : /* }}} */
    2139             : 
    2140             : /* {{{ proto bool oci_free_collection()
    2141             :    Deletes collection object*/
    2142           5 : PHP_FUNCTION(oci_free_collection)
    2143             : {
    2144           5 :         zval *tmp, *z_collection = getThis();
    2145             :         php_oci_collection *collection;
    2146             : 
    2147           5 :         if (!getThis()) {
    2148           3 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
    2149           1 :                         return;
    2150             :                 }       
    2151             :         }
    2152             :         
    2153           4 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2154           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2155           0 :                 RETURN_FALSE;
    2156             :         }
    2157             :         
    2158           4 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2159             : 
    2160           4 :         zend_list_close(collection->id);
    2161           4 :         RETURN_TRUE;
    2162             : }
    2163             : /* }}} */
    2164             : 
    2165             : /* {{{ proto bool oci_collection_append(string value)
    2166             :    Append an object to the collection */
    2167          33 : PHP_FUNCTION(oci_collection_append)
    2168             : {
    2169          33 :         zval *tmp, *z_collection = getThis();
    2170             :         php_oci_collection *collection;
    2171             :         char *value;
    2172             :         size_t value_len;
    2173             : 
    2174          53 :         if (getThis()) {
    2175          20 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &value, &value_len) == FAILURE) {
    2176           0 :                         return;
    2177             :                 }
    2178             :         }
    2179             :         else {
    2180          13 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_collection, oci_coll_class_entry_ptr, &value, &value_len) == FAILURE) {
    2181           1 :                         return;
    2182             :                 }       
    2183             :         }
    2184             :         
    2185          32 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2186           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2187           0 :                 RETURN_FALSE;
    2188             :         }
    2189             :         
    2190          32 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2191             : 
    2192          32 :         if (php_oci_collection_append(collection, value, (int) value_len)) {
    2193           4 :                 RETURN_FALSE;
    2194             :         }
    2195          28 :         RETURN_TRUE;
    2196             : }
    2197             : /* }}} */
    2198             : 
    2199             : /* {{{ proto string oci_collection_element_get(int ndx)
    2200             :    Retrieve the value at collection index ndx */
    2201          48 : PHP_FUNCTION(oci_collection_element_get)
    2202             : {
    2203          48 :         zval *tmp, *z_collection = getThis();
    2204             :         php_oci_collection *collection;
    2205             :         zend_long element_index;
    2206             :         zval value;
    2207             : 
    2208          82 :         if (getThis()) {
    2209          34 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &element_index) == FAILURE) {
    2210           0 :                         return;
    2211             :                 }
    2212             :         }
    2213             :         else {
    2214          14 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_collection, oci_coll_class_entry_ptr, &element_index) == FAILURE) {
    2215           1 :                         return;
    2216             :                 }       
    2217             :         }
    2218             :         
    2219          47 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2220           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2221           0 :                 RETURN_FALSE;
    2222             :         }
    2223             :         
    2224          47 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2225             : 
    2226          47 :         if (php_oci_collection_element_get(collection, element_index, &value)) {
    2227          18 :                 RETURN_FALSE;
    2228             :         }
    2229             :         
    2230          58 :         RETURN_ZVAL(&value, 1, 1);
    2231             : }
    2232             : /* }}} */
    2233             : 
    2234             : /* {{{ proto bool oci_collection_assign(object from)
    2235             :    Assign a collection from another existing collection */
    2236          11 : PHP_FUNCTION(oci_collection_assign)
    2237             : {
    2238          11 :         zval *tmp_dest, *tmp_from, *z_collection_dest = getThis(), *z_collection_from;
    2239             :         php_oci_collection *collection_dest, *collection_from;
    2240             : 
    2241          17 :         if (getThis()) {
    2242           6 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection_from, oci_coll_class_entry_ptr) == FAILURE) {
    2243           0 :                         return;
    2244             :                 }
    2245             :         }
    2246             :         else {
    2247           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) {
    2248           0 :                         return;
    2249             :                 }       
    2250             :         }
    2251             :         
    2252          11 :         if ((tmp_dest = zend_hash_str_find(Z_OBJPROP_P(z_collection_dest), "collection", sizeof("collection")-1)) == NULL) {
    2253           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property. The first argument should be valid collection object");
    2254           0 :                 RETURN_FALSE;
    2255             :         }
    2256             : 
    2257          11 :         if ((tmp_from = zend_hash_str_find(Z_OBJPROP_P(z_collection_from), "collection", sizeof("collection")-1)) == NULL) {
    2258           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property. The second argument should be valid collection object");
    2259           0 :                 RETURN_FALSE;
    2260             :         }
    2261             : 
    2262          11 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp_dest, collection_dest);
    2263          11 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp_from, collection_from);
    2264             : 
    2265          11 :         if (php_oci_collection_assign(collection_dest, collection_from)) {
    2266           0 :                 RETURN_FALSE;
    2267             :         }
    2268          11 :         RETURN_TRUE;
    2269             : }
    2270             : /* }}} */
    2271             : 
    2272             : /* {{{ proto bool oci_collection_element_assign(int index, string val)
    2273             :    Assign element val to collection at index ndx */
    2274          21 : PHP_FUNCTION(oci_collection_element_assign)
    2275             : {
    2276          21 :         zval *tmp, *z_collection = getThis();
    2277             :         php_oci_collection *collection;
    2278             :         size_t value_len;
    2279             :         zend_long element_index;
    2280             :         char *value;
    2281             : 
    2282          34 :         if (getThis()) {
    2283          13 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &element_index, &value, &value_len) == FAILURE) {
    2284           0 :                         return;
    2285             :                 }
    2286             :         }
    2287             :         else {
    2288           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ols", &z_collection, oci_coll_class_entry_ptr, &element_index, &value, &value_len) == FAILURE) {
    2289           1 :                         return;
    2290             :                 }       
    2291             :         }
    2292             :         
    2293          20 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2294           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2295           0 :                 RETURN_FALSE;
    2296             :         }
    2297             :         
    2298          20 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2299             : 
    2300          20 :         if (php_oci_collection_element_set(collection, element_index, value, (int) value_len)) {
    2301           9 :                 RETURN_FALSE;
    2302             :         }
    2303          11 :         RETURN_TRUE;
    2304             : }
    2305             : /* }}} */
    2306             : 
    2307             : /* {{{ proto int oci_collection_size()
    2308             :    Return the size of a collection */
    2309           9 : PHP_FUNCTION(oci_collection_size)
    2310             : {
    2311           9 :         zval *tmp, *z_collection = getThis();
    2312             :         php_oci_collection *collection;
    2313           9 :         sb4 size = 0;
    2314             :         
    2315           9 :         if (!getThis()) {
    2316           4 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
    2317           1 :                         return;
    2318             :                 }       
    2319             :         }
    2320             :         
    2321           8 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2322           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2323           0 :                 RETURN_FALSE;
    2324             :         }
    2325             :         
    2326           8 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2327             : 
    2328           4 :         if (php_oci_collection_size(collection, &size)) {
    2329           0 :                 RETURN_FALSE;
    2330             :         }
    2331           4 :         RETURN_LONG(size);
    2332             : }
    2333             : /* }}} */
    2334             : 
    2335             : /* {{{ proto int oci_collection_max()
    2336             :    Return the max value of a collection. For a varray this is the maximum length of the array */
    2337           4 : PHP_FUNCTION(oci_collection_max)
    2338             : {
    2339           4 :         zval *tmp, *z_collection = getThis();
    2340             :         php_oci_collection *collection;
    2341             :         zend_long max;
    2342             :         
    2343           4 :         if (!getThis()) {
    2344           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_collection, oci_coll_class_entry_ptr) == FAILURE) {
    2345           1 :                         return;
    2346             :                 }       
    2347             :         }
    2348             :         
    2349           3 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2350           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2351           0 :                 RETURN_FALSE;
    2352             :         }
    2353             :         
    2354           3 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2355             : 
    2356           3 :         if (php_oci_collection_max(collection, &max)) {
    2357           0 :                 RETURN_FALSE;
    2358             :         }
    2359           3 :         RETURN_LONG(max);
    2360             : }
    2361             : /* }}} */
    2362             : 
    2363             : /* {{{ proto bool oci_collection_trim(int num)
    2364             :    Trim num elements from the end of a collection */
    2365          10 : PHP_FUNCTION(oci_collection_trim)
    2366             : {
    2367          10 :         zval *tmp, *z_collection = getThis();
    2368             :         php_oci_collection *collection;
    2369             :         zend_long trim_size;
    2370             : 
    2371          17 :         if (getThis()) {
    2372           8 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &trim_size) == FAILURE) {
    2373           1 :                         return;
    2374             :                 }
    2375             :         }
    2376             :         else {
    2377           2 :                 if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_collection, oci_coll_class_entry_ptr, &trim_size) == FAILURE) {
    2378           1 :                         return;
    2379             :                 }       
    2380             :         }
    2381             :         
    2382           8 :         if ((tmp = zend_hash_str_find(Z_OBJPROP_P(z_collection), "collection", sizeof("collection")-1)) == NULL) {
    2383           0 :                 php_error_docref(NULL, E_WARNING, "Unable to find collection property");
    2384           0 :                 RETURN_FALSE;
    2385             :         }
    2386             :         
    2387           8 :         PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
    2388             : 
    2389           8 :         if (php_oci_collection_trim(collection, trim_size)) {
    2390           3 :                 RETURN_FALSE;
    2391             :         }
    2392           5 :         RETURN_TRUE;    
    2393             : }
    2394             : /* }}} */
    2395             : 
    2396             : /* {{{ proto object oci_new_collection(resource connection, string tdo [, string schema])
    2397             :    Initialize a new collection */
    2398       70054 : PHP_FUNCTION(oci_new_collection)
    2399             : {
    2400             :         zval *z_connection;
    2401             :         php_oci_connection *connection;
    2402             :         php_oci_collection *collection;
    2403       70054 :         char *tdo, *schema = NULL;
    2404       70054 :         size_t tdo_len, schema_len = 0;
    2405             :         
    2406       70054 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|s", &z_connection, &tdo, &tdo_len, &schema, &schema_len) == FAILURE) {
    2407           1 :                 return;
    2408             :         }
    2409             :         
    2410       70053 :         PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);
    2411             :         
    2412       70053 :         if ( (collection = php_oci_collection_create(connection, tdo, (int) tdo_len, schema, (int) schema_len)) ) {
    2413       70047 :                 object_init_ex(return_value, oci_coll_class_entry_ptr);
    2414       70047 :                 add_property_resource(return_value, "collection", collection->id);
    2415             :         }
    2416             :         else {
    2417           6 :                 RETURN_FALSE;
    2418             :         }
    2419             : }
    2420             : /* }}} */
    2421             : 
    2422             : /* {{{ proto bool oci_get_implicit(resource stmt)
    2423             :    Get the next statement resource from an Oracle 12c PL/SQL Implicit Result Set */
    2424           0 : PHP_FUNCTION(oci_get_implicit_resultset)
    2425             : {
    2426             :         zval *z_statement;
    2427             :         php_oci_statement *statement;
    2428             :         php_oci_statement *imp_statement;
    2429             : 
    2430           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_statement) == FAILURE) {
    2431           0 :                 return;
    2432             :         }
    2433             : 
    2434           0 :         PHP_OCI_ZVAL_TO_STATEMENT(z_statement, statement);
    2435             : 
    2436           0 :         imp_statement = php_oci_get_implicit_resultset(statement);
    2437             : 
    2438           0 :         if (imp_statement) {
    2439           0 :                 if (php_oci_statement_execute(imp_statement, (ub4)OCI_DEFAULT))
    2440           0 :                         RETURN_FALSE;
    2441           0 :                 RETURN_RES(imp_statement->id);
    2442             :         }
    2443           0 :         RETURN_FALSE;
    2444             : }
    2445             : 
    2446             : /* }}} */
    2447             : 
    2448             : #endif /* HAVE_OCI8 */
    2449             : 
    2450             : /*
    2451             :  * Local variables:
    2452             :  * tab-width: 4
    2453             :  * c-basic-offset: 4
    2454             :  * End:
    2455             :  * vim600: noet sw=4 ts=4 fdm=marker
    2456             :  * vim<600: noet sw=4 ts=4
    2457             :  */

Generated by: LCOV version 1.10

Generated at Thu, 26 May 2016 12:48:01 +0000 (23 hours ago)

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