Lines Matching refs:stmt
111 pdo_stmt_t *stmt = Z_PDO_STMT_P(getThis()); \ in ZEND_END_ARG_INFO()
112 if (!stmt->dbh) { \
116 static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_param_data *param) /*…
118 if (stmt->bound_param_map) {
128 if (stmt->named_rewrite_template) {
134 if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
138 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
142 ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
148 …pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "PDO refuses to handle repeating the same :named pa…
154 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
162 static int dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_type) /* {{{ */ in dispatch_param_event() argument
168 if (!stmt->methods->param_hook) { in dispatch_param_event()
172 ht = stmt->bound_params; in dispatch_param_event()
177 if (!stmt->methods->param_hook(stmt, param, event_type)) { in dispatch_param_event()
184 ht = stmt->bound_columns; in dispatch_param_event()
193 int pdo_stmt_describe_columns(pdo_stmt_t *stmt) /* {{{ */ in pdo_stmt_describe_columns() argument
197 stmt->columns = ecalloc(stmt->column_count, sizeof(struct pdo_column_data)); in pdo_stmt_describe_columns()
199 for (col = 0; col < stmt->column_count; col++) { in pdo_stmt_describe_columns()
200 if (!stmt->methods->describer(stmt, col)) { in pdo_stmt_describe_columns()
205 …if (stmt->dbh->native_case != stmt->dbh->desired_case && stmt->dbh->desired_case != PDO_CASE_NATUR… in pdo_stmt_describe_columns()
206 char *s = ZSTR_VAL(stmt->columns[col].name); in pdo_stmt_describe_columns()
208 switch (stmt->dbh->desired_case) { in pdo_stmt_describe_columns()
228 if (stmt->bound_params) { in pdo_stmt_describe_columns()
231 if (SUCCESS == zend_hash_find(stmt->bound_params, stmt->columns[col].name, in pdo_stmt_describe_columns()
232 stmt->columns[col].namelen, (void**)¶m)) { in pdo_stmt_describe_columns()
237 if (stmt->bound_columns) { in pdo_stmt_describe_columns()
240 if ((param = zend_hash_find_ptr(stmt->bound_columns, in pdo_stmt_describe_columns()
241 stmt->columns[col].name)) != NULL) { in pdo_stmt_describe_columns()
251 static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */ in get_lazy_object() argument
253 if (Z_ISUNDEF(stmt->lazy_object_ref)) { in get_lazy_object()
255 row->stmt = stmt; in get_lazy_object()
257 ZVAL_OBJ(&stmt->lazy_object_ref, &row->std); in get_lazy_object()
259 GC_REFCOUNT(&stmt->std)++; in get_lazy_object()
262 ZVAL_COPY(return_value, &stmt->lazy_object_ref); in get_lazy_object()
271 if (param->stmt->methods->param_hook) { in param_dtor()
272 param->stmt->methods->param_hook(param->stmt, param, PDO_PARAM_EVT_FREE); in param_dtor()
290 static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_stmt_t *stmt, int is… in really_register_bound_param() argument
296 hash = is_param ? stmt->bound_params : stmt->bound_columns; in really_register_bound_param()
303 stmt->bound_params = hash; in really_register_bound_param()
305 stmt->bound_columns = hash; in really_register_bound_param()
330 param->stmt = stmt; in really_register_bound_param()
337 if (!is_param && param->name && stmt->columns) { in really_register_bound_param()
341 for (i = 0; i < stmt->column_count; i++) { in really_register_bound_param()
342 if (ZSTR_LEN(stmt->columns[i].name) == ZSTR_LEN(param->name) && in really_register_bound_param()
343 … strncmp(ZSTR_VAL(stmt->columns[i].name), ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1) == 0) { in really_register_bound_param()
354 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp); in really_register_bound_param()
370 if (is_param && !rewrite_name_to_position(stmt, param)) { in really_register_bound_param()
382 if (stmt->methods->param_hook) { in really_register_bound_param()
383 if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE in really_register_bound_param()
408 if (stmt->methods->param_hook) { in really_register_bound_param()
409 if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC in really_register_bound_param()
447 if (stmt->bound_params) { in PHP_METHOD()
448 zend_hash_destroy(stmt->bound_params); in PHP_METHOD()
449 FREE_HASHTABLE(stmt->bound_params); in PHP_METHOD()
450 stmt->bound_params = NULL; in PHP_METHOD()
474 if (!really_register_bound_param(¶m, stmt, 1)) { in PHP_METHOD()
483 if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { in PHP_METHOD()
489 ret = pdo_parse_params(stmt, stmt->query_string, stmt->query_stringlen, in PHP_METHOD()
490 &stmt->active_query_string, &stmt->active_query_stringlen); in PHP_METHOD()
494 stmt->active_query_string = stmt->query_string; in PHP_METHOD()
495 stmt->active_query_stringlen = stmt->query_stringlen; in PHP_METHOD()
502 } else if (!dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_PRE)) { in PHP_METHOD()
506 if (stmt->methods->executer(stmt)) { in PHP_METHOD()
507 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
508 efree(stmt->active_query_string); in PHP_METHOD()
510 stmt->active_query_string = NULL; in PHP_METHOD()
511 if (!stmt->executed) { in PHP_METHOD()
514 if (stmt->dbh->alloc_own_columns && !stmt->columns) { in PHP_METHOD()
517 ret = pdo_stmt_describe_columns(stmt); in PHP_METHOD()
520 stmt->executed = 1; in PHP_METHOD()
523 if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) { in PHP_METHOD()
529 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
530 efree(stmt->active_query_string); in PHP_METHOD()
532 stmt->active_query_string = NULL; in PHP_METHOD()
538 static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *type_override) /* {{{ … in fetch_value() argument
546 col = &stmt->columns[colno]; in fetch_value()
553 stmt->methods->get_col(stmt, colno, &value, &value_len, &caller_frees); in fetch_value()
589 if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) { in fetch_value()
601 } else if (!stmt->dbh->stringify && new_type != PDO_PARAM_STR) { in fetch_value()
626 if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) { in fetch_value()
657 if (stmt->dbh->stringify) { in fetch_value()
666 if (Z_TYPE_P(dest) == IS_NULL && stmt->dbh->oracle_nulls == PDO_NULL_TO_STRING) { in fetch_value()
672 static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset, int … in do_fetch_common() argument
674 if (!stmt->executed) { in do_fetch_common()
678 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_PRE)) { in do_fetch_common()
682 if (!stmt->methods->fetcher(stmt, ori, offset)) { in do_fetch_common()
687 if (!stmt->columns && !pdo_stmt_describe_columns(stmt)) { in do_fetch_common()
691 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST)) { in do_fetch_common()
695 if (do_bind && stmt->bound_columns) { in do_fetch_common()
699 ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { in do_fetch_common()
709 fetch_value(stmt, Z_REFVAL(param->parameter), param->paramno, (int *)¶m->param_type); in do_fetch_common()
723 static int do_fetch_class_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_class_prepare() argument
725 zend_class_entry *ce = stmt->fetch.cls.ce; in do_fetch_class_prepare()
726 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_class_prepare()
727 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_class_prepare()
732 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch_class_prepare()
738 fci->retval = &stmt->fetch.cls.retval; in do_fetch_class_prepare()
743 zend_fcall_info_args_ex(fci, ce->constructor, &stmt->fetch.cls.ctor_args); in do_fetch_class_prepare()
750 } else if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_class_prepare()
751 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class does not have a constructor, u… in do_fetch_class_prepare()
759 static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * fci, zend_fcall_inf… in make_callable_ex() argument
765 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error); in make_callable_ex()
768 … pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback"); in make_callable_ex()
784 static int do_fetch_func_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_func_prepare() argument
786 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_func_prepare()
787 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_func_prepare()
789 if (!make_callable_ex(stmt, &stmt->fetch.func.function, fci, fcc, stmt->column_count)) { in do_fetch_func_prepare()
792 stmt->fetch.func.values = safe_emalloc(sizeof(zval), stmt->column_count, 0); in do_fetch_func_prepare()
798 static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */ in do_fetch_opt_finish() argument
801 if (stmt->fetch.cls.fci.size && stmt->fetch.cls.fci.params) { in do_fetch_opt_finish()
802 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_opt_finish()
804 zend_fcall_info_args_clear(&stmt->fetch.cls.fci, 1); in do_fetch_opt_finish()
806 efree(stmt->fetch.cls.fci.params); in do_fetch_opt_finish()
808 stmt->fetch.cls.fci.params = NULL; in do_fetch_opt_finish()
811 stmt->fetch.cls.fci.size = 0; in do_fetch_opt_finish()
812 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args) && free_ctor_agrs) { in do_fetch_opt_finish()
813 zval_ptr_dtor(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
814 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
815 stmt->fetch.cls.fci.param_count = 0; in do_fetch_opt_finish()
817 if (stmt->fetch.func.values) { in do_fetch_opt_finish()
818 efree(stmt->fetch.func.values); in do_fetch_opt_finish()
819 stmt->fetch.func.values = NULL; in do_fetch_opt_finish()
826 static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, enum pdo_fetch_type how, enu… in do_fetch() argument
834 how = stmt->default_fetch_type; in do_fetch()
839 if (!do_fetch_common(stmt, ori, offset, do_bind)) { in do_fetch()
848 if (flags & PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
851 colno = stmt->fetch.column; in do_fetch()
858 get_lazy_object(stmt, return_value); in do_fetch()
872 zend_hash_init(Z_ARRVAL_P(return_value), stmt->column_count, NULL, ZVAL_PTR_DTOR, 0);; in do_fetch()
879 if (stmt->column_count != 2) { in do_fetch()
880 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_KEY_PAIR fetch mode requires the result… in do_fetch()
889 if (colno >= 0 && colno < stmt->column_count) { in do_fetch()
890 if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
891 fetch_value(stmt, return_value, 1, NULL); in do_fetch()
893 fetch_value(stmt, return_value, 0, NULL); in do_fetch()
895 fetch_value(stmt, return_value, colno, NULL); in do_fetch()
903 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in do_fetch()
916 old_ce = stmt->fetch.cls.ce; in do_fetch()
917 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in do_fetch()
918 old_arg_count = stmt->fetch.cls.fci.param_count; in do_fetch()
919 do_fetch_opt_finish(stmt, 0); in do_fetch()
921 fetch_value(stmt, &val, i++, NULL); in do_fetch()
925 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch()
927 stmt->fetch.cls.ce = cep; in do_fetch()
931 do_fetch_class_prepare(stmt); in do_fetch()
934 ce = stmt->fetch.cls.ce; in do_fetch()
936 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified"); in do_fetch()
943 if (!stmt->fetch.cls.fci.size) { in do_fetch()
944 if (!do_fetch_class_prepare(stmt)) in do_fetch()
950 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
951 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
952 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
953 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
956 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
957 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
958 ZVAL_UNDEF(&stmt->fetch.cls.retval); in do_fetch()
966 if (Z_ISUNDEF(stmt->fetch.into)) { in do_fetch()
967 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified."); in do_fetch()
972 ZVAL_COPY(return_value, &stmt->fetch.into); in do_fetch()
980 if (Z_ISUNDEF(stmt->fetch.func.function)) { in do_fetch()
981 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch function specified"); in do_fetch()
984 if (!stmt->fetch.func.fci.size) { in do_fetch()
985 if (!do_fetch_func_prepare(stmt)) in do_fetch()
999 if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) { in do_fetch()
1000 fetch_value(stmt, &grp_val, colno, NULL); in do_fetch()
1002 fetch_value(stmt, &grp_val, i, NULL); in do_fetch()
1006 i = stmt->column_count; /* no more data to fetch */ in do_fetch()
1012 for (idx = 0; i < stmt->column_count; i++, idx++) { in do_fetch()
1014 fetch_value(stmt, &val, i, NULL); in do_fetch()
1018 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1024 fetch_value(stmt, &tmp, ++i, NULL); in do_fetch()
1039 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1050 if ((curr_val = zend_hash_find(Z_ARRVAL_P(return_value), stmt->columns[i].name))) { in do_fetch()
1075 zend_hash_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1087 stmt->columns[i].name, in do_fetch()
1095 stmt->columns[i].name, in do_fetch()
1104 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize data"); in do_fetch()
1112 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1116 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1127 ZVAL_COPY_VALUE(&stmt->fetch.func.values[idx], &val); in do_fetch()
1128 ZVAL_COPY_VALUE(&stmt->fetch.cls.fci.params[idx], &stmt->fetch.func.values[idx]); in do_fetch()
1133 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range"); in do_fetch()
1142 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
1143 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
1144 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
1145 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
1148 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
1149 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
1154 do_fetch_opt_finish(stmt, 0); in do_fetch()
1155 stmt->fetch.cls.ce = old_ce; in do_fetch()
1156 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in do_fetch()
1157 stmt->fetch.cls.fci.param_count = old_arg_count; in do_fetch()
1162 stmt->fetch.func.fci.param_count = idx; in do_fetch()
1163 stmt->fetch.func.fci.retval = &retval; in do_fetch()
1164 if (zend_call_function(&stmt->fetch.func.fci, &stmt->fetch.func.fcc) == FAILURE) { in do_fetch()
1165 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call user-supplied function"); in do_fetch()
1176 zval_ptr_dtor(&stmt->fetch.func.values[idx]); in do_fetch()
1206 static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, int fetch_all) /* {{{ */ in pdo_stmt_verify_mode() argument
1213 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1218 flags = stmt->default_fetch_type & PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1219 mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1225 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_FUNC is only allowed in PDOStatement::f… in pdo_stmt_verify_mode()
1232 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_LAZY can't be used with PDOStatement::f… in pdo_stmt_verify_mode()
1238 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together wit… in pdo_stmt_verify_mode()
1242 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_CLASSTYPE can only be used together wit… in pdo_stmt_verify_mode()
1246 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1273 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1277 if (!do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1304 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1308 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1309 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1310 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1312 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1316 ZVAL_DUP(&stmt->fetch.cls.ctor_args, ctor_args); in PHP_METHOD()
1318 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1322 stmt->fetch.cls.ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1324 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1325 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class"); in PHP_METHOD()
1329 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1332 if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1338 do_fetch_opt_finish(stmt, 1); in PHP_METHOD()
1340 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1341 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1342 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1362 if (!do_fetch_common(stmt, PDO_FETCH_ORI_NEXT, 0, TRUE)) { in PHP_METHOD()
1367 fetch_value(stmt, return_value, col_n, NULL); in PHP_METHOD()
1387 if (!pdo_stmt_verify_mode(stmt, how, 1)) { in PHP_METHOD()
1391 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1392 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1393 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1395 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1402 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1406 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in PHP_METHOD()
1416 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */ in PHP_METHOD()
1418 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1421 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)"); in PHP_METHOD()
1425 stmt->fetch.cls.ce = zend_fetch_class(Z_STR_P(arg2), ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1426 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1427 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not find user-specified class"); in PHP_METHOD()
1434 do_fetch_class_prepare(stmt); in PHP_METHOD()
1442 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); in PHP_METHOD()
1447 ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); in PHP_METHOD()
1448 if (do_fetch_func_prepare(stmt) == 0) { in PHP_METHOD()
1459 stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; in PHP_METHOD()
1463 stmt->fetch.column = Z_LVAL_P(arg2); in PHP_METHOD()
1466 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"… in PHP_METHOD()
1473 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Extraneous additional parameters"); in PHP_METHOD()
1481 flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS; in PHP_METHOD()
1482 how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in PHP_METHOD()
1488 (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR) in PHP_METHOD()
1495 if (!do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)) { in PHP_METHOD()
1501 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1502 …} else if (how == PDO_FETCH_KEY_PAIR || (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type … in PHP_METHOD()
1503 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1508 } while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, 0)); in PHP_METHOD()
1512 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1514 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1515 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1516 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1532 static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int is_param) /* {{… in register_bound_param() argument
1556 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in register_bound_param()
1565 if (!really_register_bound_param(¶m, stmt, is_param)) { in register_bound_param()
1599 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in PHP_METHOD()
1604 if (!really_register_bound_param(¶m, stmt, TRUE)) { in PHP_METHOD()
1620 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); in PHP_METHOD()
1629 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 0)); in PHP_METHOD()
1639 RETURN_LONG(stmt->row_count); in PHP_METHOD()
1653 if (stmt->error_code[0] == '\0') { in PHP_METHOD()
1657 RETURN_STRING(stmt->error_code); in PHP_METHOD()
1676 add_next_index_string(return_value, stmt->error_code); in PHP_METHOD()
1678 if (stmt->dbh->methods->fetch_err) { in PHP_METHOD()
1679 stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); in PHP_METHOD()
1707 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1712 if (stmt->methods->set_attribute(stmt, attr, value)) { in PHP_METHOD()
1717 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1718 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support setting attributes"); in PHP_METHOD()
1729 static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, zend_long attr) in generic_stmt_attr_get() argument
1733 RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE); in generic_stmt_attr_get()
1748 if (!stmt->methods->get_attribute) { in PHP_METHOD()
1749 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1750 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1758 switch (stmt->methods->get_attribute(stmt, attr, return_value)) { in PHP_METHOD()
1764 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1766 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1786 RETURN_LONG(stmt->column_count); in PHP_METHOD()
1802 pdo_raise_impl_error(stmt->dbh, stmt, "42P10", "column number must be non-negative"); in PHP_METHOD()
1806 if (!stmt->methods->get_column_meta) { in PHP_METHOD()
1807 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support meta data"); in PHP_METHOD()
1812 if (FAILURE == stmt->methods->get_column_meta(stmt, colno, return_value)) { in PHP_METHOD()
1818 col = &stmt->columns[colno]; in PHP_METHOD()
1832 int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int skip) in pdo_stmt_setup_fetch_mode() argument
1840 do_fetch_opt_finish(stmt, 1); in pdo_stmt_setup_fetch_mode()
1842 switch (stmt->default_fetch_type) { in pdo_stmt_setup_fetch_mode()
1844 if (!Z_ISUNDEF(stmt->fetch.into)) { in pdo_stmt_setup_fetch_mode()
1845 zval_ptr_dtor(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1846 ZVAL_UNDEF(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1853 stmt->default_fetch_type = PDO_FETCH_BOTH; in pdo_stmt_setup_fetch_mode()
1865 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "mode must be an integer"); in pdo_stmt_setup_fetch_mode()
1871 retval = pdo_stmt_verify_mode(stmt, mode, 0); in pdo_stmt_setup_fetch_mode()
1893 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); in pdo_stmt_setup_fetch_mode()
1901 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the colno argument"); in pdo_stmt_setup_fetch_mode()
1903 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "colno must be an integer"); in pdo_stmt_setup_fetch_mode()
1905 stmt->fetch.column = Z_LVAL(args[skip+1]); in pdo_stmt_setup_fetch_mode()
1914 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); in pdo_stmt_setup_fetch_mode()
1916 stmt->fetch.cls.ce = NULL; in pdo_stmt_setup_fetch_mode()
1921 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the classname argument"); in pdo_stmt_setup_fetch_mode()
1923 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "too many arguments"); in pdo_stmt_setup_fetch_mode()
1925 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "classname must be a string"); in pdo_stmt_setup_fetch_mode()
1930 stmt->fetch.cls.ce = cep; in pdo_stmt_setup_fetch_mode()
1936 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in pdo_stmt_setup_fetch_mode()
1938 if (stmt->dbh->is_persistent) { in pdo_stmt_setup_fetch_mode()
1944 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in pdo_stmt_setup_fetch_mode()
1947 ZVAL_DUP(&stmt->fetch.cls.ctor_args, &args[skip+2]); in pdo_stmt_setup_fetch_mode()
1952 do_fetch_class_prepare(stmt); in pdo_stmt_setup_fetch_mode()
1960 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the object parameter"); in pdo_stmt_setup_fetch_mode()
1962 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "object must be an object"); in pdo_stmt_setup_fetch_mode()
1969 if (stmt->dbh->is_persistent) { in pdo_stmt_setup_fetch_mode()
1973 ZVAL_COPY(&stmt->fetch.into, &args[skip+1]); in pdo_stmt_setup_fetch_mode()
1979 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "Invalid fetch mode specified"); in pdo_stmt_setup_fetch_mode()
1983 stmt->default_fetch_type = mode; in pdo_stmt_setup_fetch_mode()
2006 stmt, 0) == SUCCESS ? 1 : 0 in PHP_METHOD()
2014 static int pdo_stmt_do_next_rowset(pdo_stmt_t *stmt) in pdo_stmt_do_next_rowset() argument
2017 if (stmt->columns) { in pdo_stmt_do_next_rowset()
2019 struct pdo_column_data *cols = stmt->columns; in pdo_stmt_do_next_rowset()
2021 for (i = 0; i < stmt->column_count; i++) { in pdo_stmt_do_next_rowset()
2026 efree(stmt->columns); in pdo_stmt_do_next_rowset()
2027 stmt->columns = NULL; in pdo_stmt_do_next_rowset()
2028 stmt->column_count = 0; in pdo_stmt_do_next_rowset()
2031 if (!stmt->methods->next_rowset(stmt)) { in pdo_stmt_do_next_rowset()
2033 stmt->executed = 0; in pdo_stmt_do_next_rowset()
2037 pdo_stmt_describe_columns(stmt); in pdo_stmt_do_next_rowset()
2046 if (!stmt->methods->next_rowset) { in PHP_METHOD()
2047 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver does not support multiple rowsets"); in PHP_METHOD()
2053 if (!pdo_stmt_do_next_rowset(stmt)) { in PHP_METHOD()
2068 if (!stmt->methods->cursor_closer) { in PHP_METHOD()
2071 while (stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0)) in PHP_METHOD()
2073 if (!stmt->methods->next_rowset) { in PHP_METHOD()
2077 if (!pdo_stmt_do_next_rowset(stmt)) { in PHP_METHOD()
2082 stmt->executed = 0; in PHP_METHOD()
2088 if (!stmt->methods->cursor_closer(stmt)) { in PHP_METHOD()
2092 stmt->executed = 0; in PHP_METHOD()
2110 php_stream_printf(out, "SQL: [%zd] ", stmt->query_stringlen); in PHP_METHOD()
2111 php_stream_write(out, stmt->query_string, stmt->query_stringlen); in PHP_METHOD()
2115 stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0); in PHP_METHOD()
2117 if (stmt->bound_params) { in PHP_METHOD()
2120 ZEND_HASH_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { in PHP_METHOD()
2185 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_write() local
2190 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_write()
2198 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_delete() local
2203 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_delete()
2220 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(object); in dbstmt_method_get() local
2222 if (!stmt->dbh) { in dbstmt_method_get()
2227 if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2228 if (!pdo_hash_methods(Z_PDO_OBJECT_P(&stmt->database_object_handle), in dbstmt_method_get()
2230 || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2235 …if ((fbc = zend_hash_find_ptr(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT], lc_method_n… in dbstmt_method_get()
2256 pdo_stmt_t *stmt; in dbstmt_clone_obj() local
2259 stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(Z_OBJCE_P(zobject))); in dbstmt_clone_obj()
2260 zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject)); in dbstmt_clone_obj()
2261 object_properties_init(&stmt->std, Z_OBJCE_P(zobject)); in dbstmt_clone_obj()
2265 zend_objects_clone_members(&stmt->std, &old_stmt->std); in dbstmt_clone_obj()
2267 return &stmt->std; in dbstmt_clone_obj()
2302 PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt) in php_pdo_free_statement() argument
2304 if (stmt->bound_params) { in php_pdo_free_statement()
2305 zend_hash_destroy(stmt->bound_params); in php_pdo_free_statement()
2306 FREE_HASHTABLE(stmt->bound_params); in php_pdo_free_statement()
2307 stmt->bound_params = NULL; in php_pdo_free_statement()
2309 if (stmt->bound_param_map) { in php_pdo_free_statement()
2310 zend_hash_destroy(stmt->bound_param_map); in php_pdo_free_statement()
2311 FREE_HASHTABLE(stmt->bound_param_map); in php_pdo_free_statement()
2312 stmt->bound_param_map = NULL; in php_pdo_free_statement()
2314 if (stmt->bound_columns) { in php_pdo_free_statement()
2315 zend_hash_destroy(stmt->bound_columns); in php_pdo_free_statement()
2316 FREE_HASHTABLE(stmt->bound_columns); in php_pdo_free_statement()
2317 stmt->bound_columns = NULL; in php_pdo_free_statement()
2320 if (stmt->methods && stmt->methods->dtor) { in php_pdo_free_statement()
2321 stmt->methods->dtor(stmt); in php_pdo_free_statement()
2323 if (stmt->query_string) { in php_pdo_free_statement()
2324 efree(stmt->query_string); in php_pdo_free_statement()
2327 if (stmt->columns) { in php_pdo_free_statement()
2329 struct pdo_column_data *cols = stmt->columns; in php_pdo_free_statement()
2331 for (i = 0; i < stmt->column_count; i++) { in php_pdo_free_statement()
2337 efree(stmt->columns); in php_pdo_free_statement()
2338 stmt->columns = NULL; in php_pdo_free_statement()
2341 if (!Z_ISUNDEF(stmt->fetch.into) && stmt->default_fetch_type == PDO_FETCH_INTO) { in php_pdo_free_statement()
2342 zval_ptr_dtor(&stmt->fetch.into); in php_pdo_free_statement()
2343 ZVAL_UNDEF(&stmt->fetch.into); in php_pdo_free_statement()
2346 do_fetch_opt_finish(stmt, 1); in php_pdo_free_statement()
2348 if (!Z_ISUNDEF(stmt->database_object_handle)) { in php_pdo_free_statement()
2349 zval_ptr_dtor(&stmt->database_object_handle); in php_pdo_free_statement()
2351 zend_object_std_dtor(&stmt->std); in php_pdo_free_statement()
2356 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std); in pdo_dbstmt_free_storage() local
2357 php_pdo_free_statement(stmt); in pdo_dbstmt_free_storage()
2362 pdo_stmt_t *stmt; in pdo_dbstmt_new() local
2364 stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(ce)); in pdo_dbstmt_new()
2365 zend_object_std_init(&stmt->std, ce); in pdo_dbstmt_new()
2366 object_properties_init(&stmt->std, ce); in pdo_dbstmt_new()
2368 stmt->std.handlers = &pdo_dbstmt_object_handlers; in pdo_dbstmt_new()
2370 return &stmt->std; in pdo_dbstmt_new()
2426 pdo_stmt_t *stmt = Z_PDO_STMT_P(&I->iter.data); /* for PDO_HANDLE_STMT_ERR() */ in pdo_stmt_iter_move_forwards() local
2432 if (!do_fetch(stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_move_forwards()
2457 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in pdo_stmt_iter_get() local
2469 if (!do_fetch(stmt, 1, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_get()
2490 pdo_stmt_t *stmt = row->stmt; in row_prop_read() local
2496 if (stmt) { in row_prop_read()
2498 if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) { in row_prop_read()
2499 fetch_value(stmt, rv, Z_LVAL_P(member), NULL); in row_prop_read()
2503 if (lval >= 0 && lval < stmt->column_count) { in row_prop_read()
2504 fetch_value(stmt, rv, lval, NULL); in row_prop_read()
2510 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_read()
2511 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_read()
2512 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_read()
2513 fetch_value(stmt, rv, colno, NULL); in row_prop_read()
2518 ZVAL_OBJ(&zobj, &stmt->std); in row_prop_read()
2546 pdo_stmt_t *stmt = row->stmt; in row_prop_exists() local
2550 if (stmt) { in row_prop_exists()
2552 return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count; in row_prop_exists()
2555 return lval >=0 && lval < stmt->column_count; in row_prop_exists()
2563 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_exists()
2564 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_exists()
2565 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_exists()
2569 fetch_value(stmt, &val, colno, NULL); in row_prop_exists()
2599 pdo_stmt_t *stmt = row->stmt; in row_get_properties() local
2602 if (stmt == NULL) { in row_get_properties()
2606 if (!stmt->std.properties) { in row_get_properties()
2607 rebuild_object_properties(&stmt->std); in row_get_properties()
2609 for (i = 0; i < stmt->column_count; i++) { in row_get_properties()
2611 fetch_value(stmt, &val, i, NULL); in row_get_properties()
2613 zend_hash_update(stmt->std.properties, stmt->columns[i].name, &val); in row_get_properties()
2616 return stmt->std.properties; in row_get_properties()
2694 if (row->stmt) { in pdo_row_free_storage()
2695 ZVAL_UNDEF(&row->stmt->lazy_object_ref); in pdo_row_free_storage()
2696 OBJ_RELEASE(&row->stmt->std); in pdo_row_free_storage()