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

LTP GCOV extension - code coverage report
Current view: directory - oci8 - oci8_interface.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 997
Code covered: 84.3 % Executed lines: 840
Legend: not executed executed

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

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:33 +0000 (35 hours ago)

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