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

LCOV - code coverage report
Current view: top level - ext/mysqli - mysqli_result_iterator.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 39 44 88.6 %
Date: 2014-12-13 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2014 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: Georg Richter <georg@php.net>                               |
      16             :   |          Andrey Hristov <andrey@php.net>                             |
      17             :   |          Ulf Wendel <uw@php.net>                                     |
      18             :   +----------------------------------------------------------------------+
      19             : 
      20             :   $Id: mysqli.c 299335 2010-05-13 11:05:09Z andrey $
      21             : */
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include <signal.h>
      28             : 
      29             : #include "php.h"
      30             : #include "php_ini.h"
      31             : #include "php_mysqli_structs.h"
      32             : #include "mysqli_priv.h"
      33             : #include "zend_interfaces.h"
      34             : 
      35             : 
      36             : extern zend_object_iterator_funcs php_mysqli_result_iterator_funcs;
      37             : 
      38             : typedef struct {
      39             :         zend_object_iterator  intern;
      40             :         mysqli_object *result;
      41             :         zval current_row;
      42             :         my_longlong row_num;
      43             : } php_mysqli_result_iterator;
      44             : 
      45             : 
      46             : /* {{{ */
      47           7 : zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC)
      48             : {
      49             :         php_mysqli_result_iterator *iterator;
      50             : 
      51           7 :         if (by_ref) {
      52           0 :                 zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
      53             :         }
      54           7 :         iterator = ecalloc(1, sizeof(php_mysqli_result_iterator));
      55           7 :         zend_iterator_init(&iterator->intern TSRMLS_CC);
      56             : 
      57           7 :         ZVAL_COPY(&iterator->intern.data, object);
      58           7 :         iterator->intern.funcs = &php_mysqli_result_iterator_funcs;
      59           7 :         iterator->result = Z_MYSQLI_P(object);
      60           7 :         iterator->row_num = -1;
      61             : 
      62           7 :         return &iterator->intern;
      63             : }
      64             : /* }}} */
      65             : 
      66             : /* {{{ */
      67           7 : static void php_mysqli_result_iterator_dtor(zend_object_iterator *iter TSRMLS_DC)
      68             : {
      69           7 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*)iter;
      70             : 
      71             :         /* cleanup handled in sxe_object_dtor as we dont always have an iterator wrapper */
      72           7 :         zval_ptr_dtor(&iterator->intern.data);
      73           7 :         zval_ptr_dtor(&iterator->current_row);
      74           7 : }
      75             : /* }}} */
      76             : 
      77             : /* {{{ */
      78          37 : static int php_mysqli_result_iterator_valid(zend_object_iterator *iter TSRMLS_DC)
      79             : {
      80          37 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
      81             : 
      82          74 :         return Z_TYPE(iterator->current_row) == IS_ARRAY ? SUCCESS : FAILURE;
      83             : }
      84             : /* }}} */
      85             : 
      86             : /* {{{ */
      87          30 : static zval *php_mysqli_result_iterator_current_data(zend_object_iterator *iter TSRMLS_DC)
      88             : {
      89          30 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
      90             : 
      91          30 :         return &iterator->current_row;
      92             : }
      93             : /* }}} */
      94             : 
      95             : /* {{{ */
      96          35 : static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC)
      97             : {
      98             : 
      99          35 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
     100          35 :         mysqli_object *intern = iterator->result;
     101             :         MYSQL_RES       *result;
     102             : 
     103          35 :         MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
     104             : 
     105          35 :         zval_ptr_dtor(&iterator->current_row);
     106          35 :         php_mysqli_fetch_into_hash_aux(&iterator->current_row, result, MYSQLI_ASSOC TSRMLS_CC);
     107          70 :         if (Z_TYPE(iterator->current_row) == IS_ARRAY) {
     108          30 :                 iterator->row_num++;
     109             :         }
     110             : }
     111             : /* }}} */
     112             : 
     113             : /* {{{ */
     114           7 : static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter TSRMLS_DC)
     115             : {
     116           7 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
     117           7 :         mysqli_object *intern = iterator->result;
     118             :         MYSQL_RES       *result;
     119             : 
     120           7 :         MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
     121             : 
     122           6 :         if (mysqli_result_is_unbuffered(result)) {
     123             : #if MYSQLI_USE_MYSQLND
     124           2 :                 if (result->unbuf->eof_reached) {
     125             : #else
     126             :                 if (result->eof) {
     127             : #endif
     128           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data fetched with MYSQLI_USE_RESULT can be iterated only once");
     129           1 :                         return;
     130             :                 }
     131             :         } else {
     132           4 :                 mysql_data_seek(result, 0);
     133             :         }
     134           5 :         iterator->row_num = -1;
     135           5 :         php_mysqli_result_iterator_move_forward(iter TSRMLS_CC);
     136             : }
     137             : /* }}} */
     138             : 
     139             : /* {{{ php_mysqli_result_iterator_current_key */
     140           0 : static void php_mysqli_result_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
     141             : {
     142           0 :         php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
     143             : 
     144           0 :         ZVAL_LONG(key, iterator->row_num);
     145           0 : }
     146             : /* }}} */
     147             : 
     148             : /* {{{ php_mysqli_result_iterator_funcs */
     149             : zend_object_iterator_funcs php_mysqli_result_iterator_funcs = {
     150             :         php_mysqli_result_iterator_dtor,
     151             :         php_mysqli_result_iterator_valid,
     152             :         php_mysqli_result_iterator_current_data,
     153             :         php_mysqli_result_iterator_current_key,
     154             :         php_mysqli_result_iterator_move_forward,
     155             :         php_mysqli_result_iterator_rewind,
     156             : };
     157             : /* }}} */
     158             : 
     159             : /*
     160             :  * Local variables:
     161             :  * tab-width: 4
     162             :  * c-basic-offset: 4
     163             :  * End:
     164             :  * vim600: noet sw=4 ts=4 fdm=marker
     165             :  * vim<600: noet sw=4 ts=4
     166             :  */

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:16 +0000 (9 days ago)

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