php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysqli_result_iterator.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Georg Richter <georg@php.net> |
14 | Andrey Hristov <andrey@php.net> |
15 | Ulf Wendel <uw@php.net> |
16 +----------------------------------------------------------------------+
17*/
18
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23#include <signal.h>
24
25#include "php.h"
26#include "php_mysqli_structs.h"
27#include "mysqli_priv.h"
28#include "zend_interfaces.h"
29
30
32
39
40
41/* {{{ */
43{
45
46 if (by_ref) {
47 zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
48 return NULL;
49 }
50
51 iterator = ecalloc(1, sizeof(php_mysqli_result_iterator));
52 zend_iterator_init(&iterator->intern);
53
54 Z_ADDREF_P(object);
55 ZVAL_OBJ(&iterator->intern.data, Z_OBJ_P(object));
57 iterator->result = Z_MYSQLI_P(object);
58 iterator->row_num = -1;
59
60 return &iterator->intern;
61}
62/* }}} */
63
64/* {{{ */
65static void php_mysqli_result_iterator_dtor(zend_object_iterator *iter)
66{
68
69 /* cleanup handled in sxe_object_dtor as we don't always have an iterator wrapper */
70 zval_ptr_dtor(&iterator->intern.data);
71 zval_ptr_dtor(&iterator->current_row);
72}
73/* }}} */
74
75/* {{{ */
76static zend_result php_mysqli_result_iterator_valid(zend_object_iterator *iter)
77{
79
80 return Z_TYPE(iterator->current_row) == IS_ARRAY ? SUCCESS : FAILURE;
81}
82/* }}} */
83
84/* {{{ */
85static zval *php_mysqli_result_iterator_current_data(zend_object_iterator *iter)
86{
88
89 return &iterator->current_row;
90}
91/* }}} */
92
93/* {{{ */
94static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter)
95{
96
98 mysqli_object *intern = iterator->result;
100
102
103 zval_ptr_dtor(&iterator->current_row);
105 if (Z_TYPE(iterator->current_row) == IS_ARRAY) {
106 iterator->row_num++;
107 }
108}
109/* }}} */
110
111/* {{{ */
112static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter)
113{
115 mysqli_object *intern = iterator->result;
117
119
121 if (result->unbuf->eof_reached) {
122 zend_error(E_WARNING, "Data fetched with MYSQLI_USE_RESULT can be iterated only once");
123 return;
124 }
125 } else {
127 }
128 iterator->row_num = -1;
129 php_mysqli_result_iterator_move_forward(iter);
130}
131/* }}} */
132
133/* {{{ php_mysqli_result_iterator_current_key */
134static void php_mysqli_result_iterator_current_key(zend_object_iterator *iter, zval *key)
135{
137
138 ZVAL_LONG(key, iterator->row_num);
139}
140/* }}} */
141
142/* {{{ php_mysqli_result_iterator_funcs */
144 php_mysqli_result_iterator_dtor,
145 php_mysqli_result_iterator_valid,
146 php_mysqli_result_iterator_current_data,
147 php_mysqli_result_iterator_current_key,
148 php_mysqli_result_iterator_move_forward,
149 php_mysqli_result_iterator_rewind,
150 NULL,
151 NULL, /* get_gc */
152};
153/* }}} */
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES *result, zend_long fetchtype)
Definition mysqli.c:727
#define mysqli_result_is_unbuffered(r)
#define MYSQLI_ASSOC
Definition mysqli_priv.h:94
zend_object_iterator * php_mysqli_result_get_iterator(zend_class_entry *ce, zval *object, int by_ref)
const zend_object_iterator_funcs php_mysqli_result_iterator_funcs
#define MYSQL_RES
#define mysql_data_seek(r, o)
#define Z_MYSQLI_P(zv)
int64_t my_longlong
struct _mysqli_object mysqli_object
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check)
@ MYSQLI_STATUS_VALID
unsigned char key[REFLECTION_KEY_LEN]
const zend_object_iterator_funcs * funcs
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API ZEND_COLD void zend_error(int type, const char *format,...)
Definition zend.c:1666
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
struct _zval_struct zval
#define E_WARNING
Definition zend_errors.h:24
ZEND_API void zend_iterator_init(zend_object_iterator *iter)
struct _zend_object_iterator zend_object_iterator
struct _zend_object_iterator_funcs zend_object_iterator_funcs
struct _zend_class_entry zend_class_entry
#define ZVAL_LONG(z, l)
#define Z_OBJ_P(zval_p)
Definition zend_types.h:990
#define IS_ARRAY
Definition zend_types.h:607
#define Z_ADDREF_P(pz)
#define ZVAL_OBJ(z, o)
@ FAILURE
Definition zend_types.h:61
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
#define Z_TYPE(zval)
Definition zend_types.h:659
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
bool result