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_collection.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 252
Code covered: 75.8 % Executed lines: 191
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_collection.c 277841 2009-03-26 20:02:53Z felipe $ */
      29                 : 
      30                 : 
      31                 : 
      32                 : #ifdef HAVE_CONFIG_H
      33                 : #include "config.h"
      34                 : #endif
      35                 : 
      36                 : #include "php.h"
      37                 : #include "ext/standard/info.h"
      38                 : #include "php_ini.h"
      39                 : 
      40                 : #if HAVE_OCI8
      41                 : 
      42                 : #include "php_oci8.h"
      43                 : #include "php_oci8_int.h"
      44                 : 
      45                 : /* {{{ php_oci_collection_create()
      46                 :  Create and return connection handle */
      47                 : php_oci_collection * php_oci_collection_create(php_oci_connection *connection, zstr tdo, int tdo_len, zstr schema, int schema_len TSRMLS_DC)
      48           70053 : {       
      49           70053 :         dvoid *dschp1 = NULL;
      50                 :         dvoid *parmp1;
      51                 :         dvoid *parmp2;
      52                 :         php_oci_collection *collection;
      53                 :         
      54           70053 :         collection = emalloc(sizeof(php_oci_collection));
      55                 : 
      56           70053 :         collection->connection = connection;
      57           70053 :         collection->collection = NULL;
      58           70053 :         zend_list_addref(collection->connection->rsrc_id);
      59                 : 
      60                 :         /* get type handle by name */
      61           70053 :         PHP_OCI_CALL_RETURN(connection->errcode, OCITypeByName,
      62                 :                         (
      63                 :                          connection->env,
      64                 :                          connection->err,
      65                 :                          connection->svc,
      66                 :                          (text *) schema.s,
      67                 :                          (ub4) TEXT_BYTES(schema_len),
      68                 :                          (text *) tdo.s,
      69                 :                          (ub4) TEXT_BYTES(tdo_len),
      70                 :                          (CONST text *) 0,
      71                 :                          (ub4) 0,
      72                 :                          OCI_DURATION_SESSION,
      73                 :                          OCI_TYPEGET_ALL,
      74                 :                          &(collection->tdo)
      75                 :                         )
      76                 :         );
      77                 : 
      78           70053 :         if (connection->errcode != OCI_SUCCESS) {
      79               6 :                 goto CLEANUP;
      80                 :         }
      81                 : 
      82                 :         /* allocate describe handle */
      83           70047 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIHandleAlloc, (connection->env, (dvoid **) &dschp1, (ub4) OCI_HTYPE_DESCRIBE, (size_t) 0, (dvoid **) 0));
      84                 : 
      85           70047 :         if (connection->errcode != OCI_SUCCESS) {
      86               0 :                 goto CLEANUP;
      87                 :         }
      88                 : 
      89                 :         /* describe TDO */
      90           70047 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIDescribeAny,
      91                 :                         (
      92                 :                          connection->svc,
      93                 :                          connection->err,
      94                 :                          (dvoid *) collection->tdo,
      95                 :                          (ub4) 0,
      96                 :                          OCI_OTYPE_PTR,
      97                 :                          (ub1) OCI_DEFAULT,
      98                 :                          (ub1) OCI_PTYPE_TYPE,
      99                 :                          dschp1
     100                 :                         )
     101                 :         );
     102                 : 
     103           70047 :         if (connection->errcode != OCI_SUCCESS) {
     104               0 :                 goto CLEANUP;
     105                 :         }
     106                 : 
     107                 :         /* get first parameter handle */
     108           70047 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet, ((dvoid *) dschp1, (ub4) OCI_HTYPE_DESCRIBE, (dvoid *)&parmp1, (ub4 *)0, (ub4)OCI_ATTR_PARAM,       connection->err));
     109                 : 
     110           70047 :         if (connection->errcode != OCI_SUCCESS) {
     111               0 :                 goto CLEANUP;
     112                 :         }
     113                 : 
     114                 :         /* get the collection type code of the attribute */
     115           70047 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
     116                 :                         (
     117                 :                          (dvoid*) parmp1,
     118                 :                          (ub4) OCI_DTYPE_PARAM,
     119                 :                          (dvoid*) &(collection->coll_typecode),
     120                 :                          (ub4 *) 0,
     121                 :                          (ub4) OCI_ATTR_COLLECTION_TYPECODE,
     122                 :                          connection->err
     123                 :                         )
     124                 :         );
     125                 : 
     126           70047 :         if (connection->errcode != OCI_SUCCESS) {
     127               0 :                 goto CLEANUP;
     128                 :         }
     129                 : 
     130           70047 :         switch(collection->coll_typecode) {
     131                 :                 case OCI_TYPECODE_TABLE:
     132                 :                 case OCI_TYPECODE_VARRAY:
     133                 :                         /* get collection element handle */
     134           70047 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
     135                 :                                         (
     136                 :                                          (dvoid*) parmp1,
     137                 :                                          (ub4) OCI_DTYPE_PARAM,
     138                 :                                          (dvoid*) &parmp2,
     139                 :                                          (ub4 *) 0,
     140                 :                                          (ub4) OCI_ATTR_COLLECTION_ELEMENT,
     141                 :                                          connection->err
     142                 :                                         )
     143                 :                         );
     144                 : 
     145           70047 :                         if (connection->errcode != OCI_SUCCESS) {
     146               0 :                                 goto CLEANUP;
     147                 :                         }
     148                 : 
     149                 :                         /* get REF of the TDO for the type */
     150           70047 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
     151                 :                                         (
     152                 :                                          (dvoid*) parmp2,
     153                 :                                          (ub4) OCI_DTYPE_PARAM,
     154                 :                                          (dvoid*) &(collection->elem_ref),
     155                 :                                          (ub4 *) 0,
     156                 :                                          (ub4) OCI_ATTR_REF_TDO,
     157                 :                                          connection->err
     158                 :                                         )
     159                 :                         );
     160                 : 
     161           70047 :                         if (connection->errcode != OCI_SUCCESS) {
     162               0 :                                 goto CLEANUP;
     163                 :                         }
     164                 : 
     165                 :                         /* get the TDO (only header) */
     166           70047 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCITypeByRef,
     167                 :                                         (
     168                 :                                          connection->env,
     169                 :                                          connection->err,
     170                 :                                          collection->elem_ref,
     171                 :                                          OCI_DURATION_SESSION,
     172                 :                                          OCI_TYPEGET_HEADER,
     173                 :                                          &(collection->element_type)
     174                 :                                         )
     175                 :                         );
     176                 : 
     177           70047 :                         if (connection->errcode != OCI_SUCCESS) {
     178               0 :                                 goto CLEANUP;
     179                 :                         }
     180                 : 
     181                 :                         /* get typecode */
     182           70047 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
     183                 :                                         (
     184                 :                                          (dvoid*) parmp2,
     185                 :                                          (ub4) OCI_DTYPE_PARAM,
     186                 :                                          (dvoid*) &(collection->element_typecode),
     187                 :                                          (ub4 *) 0,
     188                 :                                          (ub4) OCI_ATTR_TYPECODE,
     189                 :                                          connection->err
     190                 :                                         )
     191                 :                         );
     192                 : 
     193           70047 :                         if (connection->errcode != OCI_SUCCESS) {
     194               0 :                                 goto CLEANUP;
     195                 :                         }
     196           70047 :                         break;
     197                 :                         /* we only support VARRAYs and TABLEs */
     198                 :                 default:
     199               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown collection type %d", collection->coll_typecode);
     200                 :                         break;
     201                 :         }       
     202                 : 
     203                 :         /* Create object to hold return table */
     204           70047 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIObjectNew,
     205                 :                 (
     206                 :                         connection->env,
     207                 :                         connection->err,
     208                 :                         connection->svc,
     209                 :                         OCI_TYPECODE_TABLE,
     210                 :                         collection->tdo,
     211                 :                         (dvoid *)0,
     212                 :                         OCI_DURATION_DEFAULT,
     213                 :                         TRUE,
     214                 :                         (dvoid **) &(collection->collection)
     215                 :                 )
     216                 :         );
     217                 : 
     218           70047 :         if (connection->errcode != OCI_SUCCESS) {
     219               0 :                 goto CLEANUP;
     220                 :         }
     221                 : 
     222                 :         /* free the describe handle (Bug #44113) */
     223           70047 :         PHP_OCI_CALL(OCIHandleFree, ((dvoid *) dschp1, OCI_HTYPE_DESCRIBE));
     224           70047 :         PHP_OCI_REGISTER_RESOURCE(collection, le_collection);
     225           70047 :         return collection;
     226                 :         
     227               6 : CLEANUP:
     228                 : 
     229               6 :         if (dschp1) {
     230                 :                 /* free the describe handle (Bug #44113) */
     231               0 :                 PHP_OCI_CALL(OCIHandleFree, ((dvoid *) dschp1, OCI_HTYPE_DESCRIBE));
     232                 :         }
     233               6 :         connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     234               6 :         PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     235               6 :         php_oci_collection_close(collection TSRMLS_CC); 
     236               6 :         return NULL;
     237                 : } /* }}} */
     238                 : 
     239                 : /* {{{ php_oci_collection_size()
     240                 :  Return size of the collection */
     241                 : int php_oci_collection_size(php_oci_collection *collection, sb4 *size TSRMLS_DC)
     242               4 : {
     243               4 :         php_oci_connection *connection = collection->connection;
     244                 :         
     245               4 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollSize, (connection->env, connection->err, collection->collection, (sb4 *)size));
     246                 : 
     247               4 :         if (connection->errcode != OCI_SUCCESS) {
     248               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     249               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     250               0 :                 return 1;
     251                 :         }
     252               4 :         return 0;
     253                 : } /* }}} */
     254                 : 
     255                 : /* {{{ php_oci_collection_max()
     256                 :  Return max number of elements in the collection */
     257                 : int php_oci_collection_max(php_oci_collection *collection, long *max TSRMLS_DC)
     258               3 : {
     259               3 :         php_oci_connection *connection = collection->connection;
     260                 :         
     261               3 :         PHP_OCI_CALL_RETURN(*max, OCICollMax, (connection->env, collection->collection));
     262                 : 
     263                 :         /* error handling is not necessary here? */
     264               3 :         return 0;
     265                 : } /* }}} */
     266                 : 
     267                 : /* {{{ php_oci_collection_trim()
     268                 :  Trim collection to the given number of elements */
     269                 : int php_oci_collection_trim(php_oci_collection *collection, long trim_size TSRMLS_DC)
     270               8 : {
     271               8 :         php_oci_connection *connection = collection->connection;
     272                 :         
     273               8 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollTrim, (connection->env, connection->err, trim_size, collection->collection));
     274                 : 
     275               8 :         if (connection->errcode != OCI_SUCCESS) {
     276               3 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     277               3 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     278               3 :                 return 1;
     279                 :         }
     280               5 :         return 0;
     281                 : } /* }}} */
     282                 : 
     283                 : /* {{{ php_oci_collection_append_null()
     284                 :  Append NULL element to the end of the collection */
     285                 : int php_oci_collection_append_null(php_oci_collection *collection TSRMLS_DC)
     286               2 : {
     287               2 :         OCIInd null_index = OCI_IND_NULL;
     288               2 :         php_oci_connection *connection = collection->connection;
     289                 : 
     290                 :         /* append NULL element */
     291               2 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAppend, (connection->env, connection->err, (dvoid *)0, &null_index, collection->collection));
     292                 :         
     293               2 :         if (connection->errcode != OCI_SUCCESS) {
     294               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     295               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     296               0 :                 return 1;
     297                 :         }
     298               2 :         return 0;
     299                 : } /* }}} */
     300                 : 
     301                 : /* {{{ php_oci_collection_append_date()
     302                 :  Append DATE element to the end of the collection (use "DD-MON-YY" format) */
     303                 : int php_oci_collection_append_date(php_oci_collection *collection, zstr date, int date_len TSRMLS_DC)
     304               7 : {
     305               7 :         OCIInd new_index = OCI_IND_NOTNULL;
     306                 :         OCIDate oci_date;
     307               7 :         php_oci_connection *connection = collection->connection;
     308                 : 
     309                 :         /* format and language are NULLs, so format is "DD-MON-YY" and language is the default language of the session */
     310               7 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIDateFromText, (connection->err, (CONST text *)date.s, TEXT_BYTES(date_len), NULL, 0, NULL, 0, &oci_date));
     311                 : 
     312               7 :         if (connection->errcode != OCI_SUCCESS) {
     313                 :                 /* failed to convert string to date */
     314               3 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     315               3 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     316               3 :                 return 1;
     317                 :         }
     318                 : 
     319               4 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAppend,
     320                 :                         (
     321                 :                          connection->env,
     322                 :                          connection->err,
     323                 :                          (dvoid *) &oci_date,
     324                 :                          (dvoid *) &new_index,
     325                 :                          (OCIColl *) collection->collection
     326                 :                         )
     327                 :         );
     328                 : 
     329               4 :         if (connection->errcode != OCI_SUCCESS) {
     330               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     331               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     332               0 :                 return 1;
     333                 :         }
     334                 :                         
     335               4 :         return 0;
     336                 : } /* }}} */
     337                 : 
     338                 : /* {{{ php_oci_collection_append_number()
     339                 :  Append NUMBER to the end of the collection */
     340                 : int php_oci_collection_append_number(php_oci_collection *collection, zstr number, int number_len TSRMLS_DC)
     341              14 : {
     342              14 :         OCIInd new_index = OCI_IND_NOTNULL;
     343                 :         double element_double;
     344                 :         OCINumber oci_number;
     345              14 :         php_oci_connection *connection = collection->connection;
     346                 : 
     347              14 :         element_double = zend_u_strtod(number.u, NULL);
     348                 :                         
     349              14 :         PHP_OCI_CALL_RETURN(connection->errcode, OCINumberFromReal, (connection->err, &element_double, sizeof(double), &oci_number));
     350                 : 
     351              14 :         if (connection->errcode != OCI_SUCCESS) {
     352               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     353               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     354               0 :                 return 1;
     355                 :         }
     356                 : 
     357              14 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAppend,
     358                 :                         (
     359                 :                          connection->env,
     360                 :                          connection->err,
     361                 :                          (dvoid *) &oci_number,
     362                 :                          (dvoid *) &new_index,
     363                 :                          (OCIColl *) collection->collection
     364                 :                         )
     365                 :         );
     366                 : 
     367              14 :         if (connection->errcode != OCI_SUCCESS) {
     368               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     369               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     370               0 :                 return 1;
     371                 :         }
     372                 : 
     373              14 :         return 0;
     374                 : } /* }}} */
     375                 : 
     376                 : /* {{{ php_oci_collection_append_string()
     377                 :  Append STRING to the end of the collection */
     378                 : int php_oci_collection_append_string(php_oci_collection *collection, zstr element, int element_len TSRMLS_DC)
     379               8 : {
     380               8 :         OCIInd new_index = OCI_IND_NOTNULL;
     381               8 :         OCIString *ocistr = (OCIString *)0;
     382               8 :         php_oci_connection *connection = collection->connection;
     383                 :                         
     384               8 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIStringAssignText, (connection->env, connection->err, (CONST oratext *)element.s, TEXT_BYTES(element_len), &ocistr));
     385                 : 
     386               8 :         if (connection->errcode != OCI_SUCCESS) {
     387               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     388               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     389               0 :                 return 1;
     390                 :         }
     391                 : 
     392               8 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAppend,
     393                 :                         (
     394                 :                          connection->env,
     395                 :                          connection->err,
     396                 :                          (dvoid *) ocistr,
     397                 :                          (dvoid *) &new_index,
     398                 :                          (OCIColl *) collection->collection
     399                 :                         )
     400                 :         );
     401                 : 
     402               8 :         if (connection->errcode != OCI_SUCCESS) {
     403               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     404               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     405               0 :                 return 1;
     406                 :         }
     407                 : 
     408               8 :         return 0;
     409                 : } /* }}} */
     410                 : 
     411                 : /* {{{ php_oci_collection_append()
     412                 :  Append wrapper. Appends any supported element to the end of the collection */
     413                 : int php_oci_collection_append(php_oci_collection *collection, zstr element, int element_len TSRMLS_DC)
     414              32 : {
     415              32 :         if (element_len == 0) {
     416               2 :                 return php_oci_collection_append_null(collection TSRMLS_CC);
     417                 :         }
     418                 :         
     419              30 :         switch(collection->element_typecode) {
     420                 :                 case OCI_TYPECODE_DATE:
     421               7 :                         return php_oci_collection_append_date(collection, element, element_len TSRMLS_CC);
     422                 :                         break;
     423                 :                         
     424                 :                 case OCI_TYPECODE_VARCHAR2 :
     425               8 :                         return php_oci_collection_append_string(collection, element, element_len TSRMLS_CC);
     426                 :                         break;
     427                 : 
     428                 :                 case OCI_TYPECODE_UNSIGNED16 :                                           /* UNSIGNED SHORT      */
     429                 :                 case OCI_TYPECODE_UNSIGNED32 :                                            /* UNSIGNED LONG      */
     430                 :                 case OCI_TYPECODE_REAL :                                                                         /* REAL        */
     431                 :                 case OCI_TYPECODE_DOUBLE :                                                                       /* DOUBLE      */
     432                 :                 case OCI_TYPECODE_INTEGER :                                                                             /* INT  */
     433                 :                 case OCI_TYPECODE_SIGNED16 :                                                              /* SHORT      */
     434                 :                 case OCI_TYPECODE_SIGNED32 :                                                               /* LONG      */
     435                 :                 case OCI_TYPECODE_DECIMAL :                                                                     /* DECIMAL      */
     436                 :                 case OCI_TYPECODE_FLOAT :                                                                       /* FLOAT        */
     437                 :                 case OCI_TYPECODE_NUMBER :                                                                      /* NUMBER       */
     438                 :                 case OCI_TYPECODE_SMALLINT :                                                            /* SMALLINT */
     439              14 :                         return php_oci_collection_append_number(collection, element, element_len TSRMLS_CC);
     440                 :                         break;
     441                 : 
     442                 :                 default:
     443               1 :                         php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or unsupported type of element: %d", collection->element_typecode);
     444               1 :                         return 1;
     445                 :                         break;
     446                 :         }
     447                 :         /* never reached */
     448                 :         return 1;
     449                 : } /* }}} */
     450                 : 
     451                 : /* {{{ php_oci_collection_element_get()
     452                 :  Get the element with the given index */
     453                 : int php_oci_collection_element_get(php_oci_collection *collection, long index, zval **result_element TSRMLS_DC)
     454              47 : {
     455              47 :         php_oci_connection *connection = collection->connection;
     456                 :         dvoid *element;
     457                 :         OCIInd *element_index;
     458                 :         boolean exists;
     459                 :         oratext buff[1024];
     460              47 :         ub4 buff_len = 1024;
     461                 :         
     462              47 :         MAKE_STD_ZVAL(*result_element);
     463              47 :         ZVAL_NULL(*result_element);
     464                 : 
     465              47 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollGetElem,
     466                 :                         (
     467                 :                          connection->env,
     468                 :                          connection->err,
     469                 :                          collection->collection,
     470                 :                          (ub4)index,
     471                 :                          &exists,
     472                 :                          &element,
     473                 :                          (dvoid **)&element_index
     474                 :                         )
     475                 :         );
     476                 : 
     477              47 :         if (connection->errcode != OCI_SUCCESS) {
     478               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     479               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     480               0 :                 FREE_ZVAL(*result_element);
     481               0 :                 return 1;
     482                 :         }
     483                 :         
     484              47 :         if (exists == 0) {
     485                 :                 /* element doesn't exist */
     486              18 :                 FREE_ZVAL(*result_element);
     487              18 :                 return 1;
     488                 :         }
     489                 : 
     490              29 :         if (*element_index == OCI_IND_NULL) {
     491                 :                 /* this is not an error, we're returning NULL here */
     492               4 :                 return 0;
     493                 :         }
     494                 : 
     495              25 :         switch (collection->element_typecode) {
     496                 :                 case OCI_TYPECODE_DATE:
     497               4 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCIDateToText, (connection->err, element, 0, 0, 0, 0, &buff_len, buff));
     498                 :         
     499               4 :                         if (connection->errcode != OCI_SUCCESS) {
     500               0 :                                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     501               0 :                                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     502               0 :                                 FREE_ZVAL(*result_element);
     503               0 :                                 return 1;
     504                 :                         }
     505                 : 
     506               4 :                         ZVAL_UNICODEL(*result_element, (UChar *)buff, TEXT_CHARS(buff_len), 1);
     507                 :                         /* Z_UNIVAL_P(*result_element)[buff_len] = 0; XXX */
     508                 : 
     509               4 :                         return 0;
     510                 :                         break;
     511                 : 
     512                 :                 case OCI_TYPECODE_VARCHAR2:
     513                 :                 {
     514               4 :                         OCIString *oci_string = *(OCIString **)element;
     515                 :                         text *str;
     516                 :                         ub4 str_len;
     517                 :                         
     518               4 :                         PHP_OCI_CALL_RETURN(str, OCIStringPtr, (connection->env, oci_string));
     519                 :                         
     520               4 :                         if (str) {
     521               4 :                                 PHP_OCI_CALL_RETURN(str_len, OCIStringSize, (connection->env, oci_string));
     522                 : 
     523               4 :                                 ZVAL_UNICODEL(*result_element, (UChar *)str, TEXT_CHARS(str_len), 1);
     524                 :                         }
     525               4 :                         return 0;
     526                 :                 }
     527                 :                         break;
     528                 : 
     529                 :                 case OCI_TYPECODE_UNSIGNED16:                                           /* UNSIGNED SHORT  */
     530                 :                 case OCI_TYPECODE_UNSIGNED32:                                           /* UNSIGNED LONG  */
     531                 :                 case OCI_TYPECODE_REAL:                                                         /* REAL    */
     532                 :                 case OCI_TYPECODE_DOUBLE:                                                       /* DOUBLE  */
     533                 :                 case OCI_TYPECODE_INTEGER:                                                      /* INT  */
     534                 :                 case OCI_TYPECODE_SIGNED16:                                                     /* SHORT  */
     535                 :                 case OCI_TYPECODE_SIGNED32:                                                     /* LONG  */
     536                 :                 case OCI_TYPECODE_DECIMAL:                                                      /* DECIMAL      */
     537                 :                 case OCI_TYPECODE_FLOAT:                                                        /* FLOAT        */
     538                 :                 case OCI_TYPECODE_NUMBER:                                                       /* NUMBER       */
     539                 :                 case OCI_TYPECODE_SMALLINT:                                                     /* SMALLINT */
     540                 :                 {
     541                 :                         double double_number;
     542                 :                         
     543              17 :                         PHP_OCI_CALL_RETURN(connection->errcode, OCINumberToReal, (connection->err, (CONST OCINumber *) element, (uword) sizeof(double), (dvoid *) &double_number));
     544                 : 
     545              17 :                         if (connection->errcode != OCI_SUCCESS) {
     546               0 :                                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     547               0 :                                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     548               0 :                                 FREE_ZVAL(*result_element);
     549               0 :                                 return 1;
     550                 :                         }
     551                 :                         
     552              17 :                         ZVAL_DOUBLE(*result_element, double_number);
     553                 : 
     554              17 :                         return 0;
     555                 :                 }
     556                 :                         break;
     557                 :                 default:
     558               0 :                         php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or unsupported type of element: %d", collection->element_typecode);
     559               0 :                         FREE_ZVAL(*result_element);
     560               0 :                         return 1;
     561                 :                         break;
     562                 :         }
     563                 :         /* never reached */
     564                 :         return 1;
     565                 : } /* }}} */
     566                 : 
     567                 : /* {{{ php_oci_collection_element_set_null()
     568                 :  Set the element with the given index to NULL */
     569                 : int php_oci_collection_element_set_null(php_oci_collection *collection, long index TSRMLS_DC)
     570               3 : {
     571               3 :         OCIInd null_index = OCI_IND_NULL;
     572               3 :         php_oci_connection *connection = collection->connection;
     573                 : 
     574                 :         /* set NULL element */
     575               3 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAssignElem, (connection->env, connection->err, (ub4) index, (dvoid *)"", &null_index, collection->collection));
     576                 :         
     577               3 :         if (connection->errcode != OCI_SUCCESS) {
     578               1 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     579               1 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     580               1 :                 return 1;
     581                 :         }
     582               2 :         return 0;
     583                 : } /* }}} */
     584                 : 
     585                 : /* {{{ php_oci_collection_element_set_date()
     586                 :  Change element's value to the given DATE */
     587                 : int php_oci_collection_element_set_date(php_oci_collection *collection, long index, zstr date, int date_len TSRMLS_DC)
     588               3 : {
     589               3 :         OCIInd new_index = OCI_IND_NOTNULL;
     590                 :         OCIDate oci_date;
     591               3 :         php_oci_connection *connection = collection->connection;
     592                 : 
     593                 :         /* format and language are NULLs, so format is "DD-MON-YY" and language is the default language of the session */
     594               3 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIDateFromText, (connection->err, (CONST oratext *)date.s, TEXT_BYTES(date_len), NULL, 0, NULL, 0, &oci_date));
     595                 : 
     596               3 :         if (connection->errcode != OCI_SUCCESS) {
     597                 :                 /* failed to convert string to date */
     598               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     599               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     600               0 :                 return 1;
     601                 :         }
     602                 : 
     603               3 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAssignElem,
     604                 :                         (
     605                 :                          connection->env,
     606                 :                          connection->err,
     607                 :                          (ub4)index,
     608                 :                          (dvoid *) &oci_date,
     609                 :                          (dvoid *) &new_index,
     610                 :                          (OCIColl *) collection->collection
     611                 :                          )
     612                 :         );
     613                 : 
     614               3 :         if (connection->errcode != OCI_SUCCESS) {
     615               1 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     616               1 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     617               1 :                 return 1;
     618                 :         }
     619                 :                         
     620               2 :         return 0;
     621                 : } /* }}} */
     622                 : 
     623                 : /* {{{ php_oci_collection_element_set_number()
     624                 :  Change element's value to the given NUMBER */
     625                 : int php_oci_collection_element_set_number(php_oci_collection *collection, long index, zstr number, int number_len TSRMLS_DC)
     626              10 : {
     627              10 :         OCIInd new_index = OCI_IND_NOTNULL;
     628                 :         double element_double;
     629                 :         OCINumber oci_number;
     630              10 :         php_oci_connection *connection = collection->connection;
     631                 : 
     632              10 :         element_double = zend_u_strtod(number.u, NULL);
     633                 :                         
     634              10 :         PHP_OCI_CALL_RETURN(connection->errcode, OCINumberFromReal, (connection->err, &element_double, sizeof(double), &oci_number));
     635                 : 
     636              10 :         if (connection->errcode != OCI_SUCCESS) {
     637               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     638               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     639               0 :                 return 1;
     640                 :         }
     641                 : 
     642              10 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAssignElem,
     643                 :                         (
     644                 :                          connection->env,
     645                 :                          connection->err,
     646                 :                          (ub4) index,
     647                 :                          (dvoid *) &oci_number,
     648                 :                          (dvoid *) &new_index,
     649                 :                          (OCIColl *) collection->collection
     650                 :                          )
     651                 :         );
     652                 : 
     653              10 :         if (connection->errcode != OCI_SUCCESS) {
     654               5 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     655               5 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     656               5 :                 return 1;
     657                 :         }
     658                 : 
     659               5 :         return 0;
     660                 : } /* }}} */
     661                 : 
     662                 : /* {{{ php_oci_collection_element_set_string()
     663                 :  Change element's value to the given string */
     664                 : int php_oci_collection_element_set_string(php_oci_collection *collection, long index, zstr element, int element_len TSRMLS_DC)
     665               3 : {
     666               3 :         OCIInd new_index = OCI_IND_NOTNULL;
     667               3 :         OCIString *ocistr = (OCIString *)0;
     668               3 :         php_oci_connection *connection = collection->connection;
     669                 :                         
     670               3 :         PHP_OCI_CALL_RETURN(connection->errcode, OCIStringAssignText, (connection->env, connection->err, (CONST oratext *)element.s, TEXT_BYTES(element_len), &ocistr));
     671                 : 
     672               3 :         if (connection->errcode != OCI_SUCCESS) {
     673               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     674               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     675               0 :                 return 1;
     676                 :         }
     677                 : 
     678               3 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAssignElem,
     679                 :                         (
     680                 :                          connection->env,
     681                 :                          connection->err,
     682                 :                          (ub4)index,
     683                 :                          (dvoid *) ocistr,
     684                 :                          (dvoid *) &new_index,
     685                 :                          (OCIColl *) collection->collection
     686                 :                          )
     687                 :         );
     688                 : 
     689               3 :         if (connection->errcode != OCI_SUCCESS) {
     690               1 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     691               1 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     692               1 :                 return 1;
     693                 :         }
     694                 : 
     695               2 :         return 0;
     696                 : } /* }}} */
     697                 : 
     698                 : /* {{{ php_oci_collection_element_set()
     699                 :  Collection element setter */
     700                 : int php_oci_collection_element_set(php_oci_collection *collection, long index, zstr value, int value_len TSRMLS_DC)
     701              20 : {
     702              20 :         if (value_len == 0) {
     703               3 :                 return php_oci_collection_element_set_null(collection, index TSRMLS_CC);
     704                 :         }
     705                 :         
     706              17 :         switch(collection->element_typecode) {
     707                 :                 case OCI_TYPECODE_DATE:
     708               3 :                         return php_oci_collection_element_set_date(collection, index, value, value_len TSRMLS_CC);
     709                 :                         break;
     710                 :                         
     711                 :                 case OCI_TYPECODE_VARCHAR2 :
     712               3 :                         return php_oci_collection_element_set_string(collection, index, value, value_len TSRMLS_CC);
     713                 :                         break;
     714                 : 
     715                 :                 case OCI_TYPECODE_UNSIGNED16 :                                           /* UNSIGNED SHORT      */
     716                 :                 case OCI_TYPECODE_UNSIGNED32 :                                            /* UNSIGNED LONG      */
     717                 :                 case OCI_TYPECODE_REAL :                                                                         /* REAL        */
     718                 :                 case OCI_TYPECODE_DOUBLE :                                                                       /* DOUBLE      */
     719                 :                 case OCI_TYPECODE_INTEGER :                                                                             /* INT  */
     720                 :                 case OCI_TYPECODE_SIGNED16 :                                                              /* SHORT      */
     721                 :                 case OCI_TYPECODE_SIGNED32 :                                                               /* LONG      */
     722                 :                 case OCI_TYPECODE_DECIMAL :                                                                     /* DECIMAL      */
     723                 :                 case OCI_TYPECODE_FLOAT :                                                                       /* FLOAT        */
     724                 :                 case OCI_TYPECODE_NUMBER :                                                                      /* NUMBER       */
     725                 :                 case OCI_TYPECODE_SMALLINT :                                                            /* SMALLINT */
     726              10 :                         return php_oci_collection_element_set_number(collection, index, value, value_len TSRMLS_CC);
     727                 :                         break;
     728                 : 
     729                 :                 default:
     730               1 :                         php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or unsupported type of element: %d", collection->element_typecode);
     731               1 :                         return 1;
     732                 :                         break;
     733                 :         }
     734                 :         /* never reached */
     735                 :         return 1;
     736                 : } /* }}} */
     737                 : 
     738                 : /* {{{ php_oci_collection_assign()
     739                 :  Assigns a value to the collection from another collection */
     740                 : int php_oci_collection_assign(php_oci_collection *collection_dest, php_oci_collection *collection_from TSRMLS_DC)
     741              11 : {
     742              11 :         php_oci_connection *connection = collection_dest->connection;
     743                 :         
     744              11 :         PHP_OCI_CALL_RETURN(connection->errcode, OCICollAssign, (connection->env, connection->err, collection_from->collection, collection_dest->collection));
     745                 : 
     746              11 :         if (connection->errcode != OCI_SUCCESS) {
     747               0 :                 connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     748               0 :                 PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     749               0 :                 return 1;
     750                 :         }
     751              11 :         return 0;
     752                 : } /* }}} */
     753                 : 
     754                 : /* {{{ php_oci_collection_close()
     755                 :  Destroy collection and all associated resources */
     756                 : void php_oci_collection_close(php_oci_collection *collection TSRMLS_DC)
     757           70053 : {
     758           70053 :         php_oci_connection *connection = collection->connection;
     759                 : 
     760           70053 :         if (collection->collection) {
     761           70047 :                 PHP_OCI_CALL_RETURN(connection->errcode, OCIObjectFree, (connection->env, connection->err, (dvoid *)collection->collection, (ub2)OCI_OBJECTFREE_FORCE));
     762                 : 
     763           70047 :                 if (connection->errcode != OCI_SUCCESS) {
     764               0 :                         connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
     765               0 :                         PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
     766                 :                 }
     767                 :         }
     768                 :         
     769           70053 :         zend_list_delete(collection->connection->rsrc_id);
     770                 :         
     771           70053 :         efree(collection);
     772                 :         return;
     773                 : } /* }}} */
     774                 : 
     775                 : #endif /* HAVE_OCI8 */
     776                 : 
     777                 : /*
     778                 :  * Local variables:
     779                 :  * tab-width: 4
     780                 :  * c-basic-offset: 4
     781                 :  * End:
     782                 :  * vim600: noet sw=4 ts=4 fdm=marker
     783                 :  * vim<600: noet sw=4 ts=4
     784                 :  */

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.