Lines Matching refs:stmt

109   pdo_stmt_t *stmt = Z_PDO_STMT_P(getThis());	\  in ZEND_END_ARG_INFO()
110 if (!stmt->dbh) { \
114 static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_param_data *param) /*…
116 if (stmt->bound_param_map) {
126 if (stmt->named_rewrite_template) {
132 if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
136 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
140 ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
146 …pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "PDO refuses to handle repeating the same :named pa…
152 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
160 static int dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_type) /* {{{ */ in dispatch_param_event() argument
166 if (stmt->dbh->skip_param_evt & (1 << event_type)) { in dispatch_param_event()
170 if (!stmt->methods->param_hook) { in dispatch_param_event()
174 ht = stmt->bound_params; in dispatch_param_event()
179 if (!stmt->methods->param_hook(stmt, param, event_type)) { in dispatch_param_event()
186 ht = stmt->bound_columns; in dispatch_param_event()
195 int pdo_stmt_describe_columns(pdo_stmt_t *stmt) /* {{{ */ in pdo_stmt_describe_columns() argument
199 stmt->columns = ecalloc(stmt->column_count, sizeof(struct pdo_column_data)); in pdo_stmt_describe_columns()
201 for (col = 0; col < stmt->column_count; col++) { in pdo_stmt_describe_columns()
202 if (!stmt->methods->describer(stmt, col)) { in pdo_stmt_describe_columns()
207 …if (stmt->dbh->native_case != stmt->dbh->desired_case && stmt->dbh->desired_case != PDO_CASE_NATUR… in pdo_stmt_describe_columns()
208 char *s = ZSTR_VAL(stmt->columns[col].name); in pdo_stmt_describe_columns()
210 switch (stmt->dbh->desired_case) { in pdo_stmt_describe_columns()
229 if (stmt->bound_columns) { in pdo_stmt_describe_columns()
232 if ((param = zend_hash_find_ptr(stmt->bound_columns, in pdo_stmt_describe_columns()
233 stmt->columns[col].name)) != NULL) { in pdo_stmt_describe_columns()
243 static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */ in get_lazy_object() argument
245 if (Z_ISUNDEF(stmt->lazy_object_ref)) { in get_lazy_object()
247 row->stmt = stmt; in get_lazy_object()
249 ZVAL_OBJ(&stmt->lazy_object_ref, &row->std); in get_lazy_object()
251 GC_ADDREF(&stmt->std); in get_lazy_object()
254 ZVAL_COPY(return_value, &stmt->lazy_object_ref); in get_lazy_object()
263 if (param->stmt->methods->param_hook) { in param_dtor()
264 param->stmt->methods->param_hook(param->stmt, param, PDO_PARAM_EVT_FREE); in param_dtor()
282 static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_stmt_t *stmt, int is… in really_register_bound_param() argument
288 hash = is_param ? stmt->bound_params : stmt->bound_columns; in really_register_bound_param()
295 stmt->bound_params = hash; in really_register_bound_param()
297 stmt->bound_columns = hash; in really_register_bound_param()
322 param->stmt = stmt; in really_register_bound_param()
329 if (!is_param && param->name && stmt->columns) { in really_register_bound_param()
333 for (i = 0; i < stmt->column_count; i++) { in really_register_bound_param()
334 if (ZSTR_LEN(stmt->columns[i].name) == ZSTR_LEN(param->name) && in really_register_bound_param()
335 … strncmp(ZSTR_VAL(stmt->columns[i].name), ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1) == 0) { in really_register_bound_param()
346 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp); in really_register_bound_param()
362 if (is_param && !rewrite_name_to_position(stmt, param)) { in really_register_bound_param()
374 if (stmt->methods->param_hook) { in really_register_bound_param()
375 if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE in really_register_bound_param()
400 if (stmt->methods->param_hook) { in really_register_bound_param()
401 if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC in really_register_bound_param()
440 if (stmt->bound_params) { in PHP_METHOD()
441 zend_hash_destroy(stmt->bound_params); in PHP_METHOD()
442 FREE_HASHTABLE(stmt->bound_params); in PHP_METHOD()
443 stmt->bound_params = NULL; in PHP_METHOD()
467 if (!really_register_bound_param(&param, stmt, 1)) { in PHP_METHOD()
476 if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { in PHP_METHOD()
483 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
484 efree(stmt->active_query_string); in PHP_METHOD()
486 stmt->active_query_string = NULL; in PHP_METHOD()
488 ret = pdo_parse_params(stmt, stmt->query_string, stmt->query_stringlen, in PHP_METHOD()
489 &stmt->active_query_string, &stmt->active_query_stringlen); in PHP_METHOD()
493 stmt->active_query_string = stmt->query_string; in PHP_METHOD()
494 stmt->active_query_stringlen = stmt->query_stringlen; in PHP_METHOD()
501 } else if (!dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_PRE)) { in PHP_METHOD()
505 if (stmt->methods->executer(stmt)) { in PHP_METHOD()
506 if (!stmt->executed) { in PHP_METHOD()
509 if (stmt->dbh->alloc_own_columns && !stmt->columns) { in PHP_METHOD()
512 ret = pdo_stmt_describe_columns(stmt); in PHP_METHOD()
515 stmt->executed = 1; in PHP_METHOD()
518 if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) { in PHP_METHOD()
529 static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *type_override) /* {{{ … in fetch_value() argument
537 if (colno < 0 || colno >= stmt->column_count) { in fetch_value()
538 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in fetch_value()
544 col = &stmt->columns[colno]; in fetch_value()
551 stmt->methods->get_col(stmt, colno, &value, &value_len, &caller_frees); in fetch_value()
587 if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) { in fetch_value()
599 } else if (!stmt->dbh->stringify && new_type != PDO_PARAM_STR) { in fetch_value()
624 if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) { in fetch_value()
655 if (stmt->dbh->stringify) { in fetch_value()
664 if (Z_TYPE_P(dest) == IS_NULL && stmt->dbh->oracle_nulls == PDO_NULL_TO_STRING) { in fetch_value()
670 static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset, int … in do_fetch_common() argument
672 if (!stmt->executed) { in do_fetch_common()
676 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_PRE)) { in do_fetch_common()
680 if (!stmt->methods->fetcher(stmt, ori, offset)) { in do_fetch_common()
685 if (!stmt->columns && !pdo_stmt_describe_columns(stmt)) { in do_fetch_common()
689 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST)) { in do_fetch_common()
693 if (do_bind && stmt->bound_columns) { in do_fetch_common()
697 ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { in do_fetch_common()
707 fetch_value(stmt, Z_REFVAL(param->parameter), param->paramno, (int *)&param->param_type); in do_fetch_common()
721 static int do_fetch_class_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_class_prepare() argument
723 zend_class_entry *ce = stmt->fetch.cls.ce; in do_fetch_class_prepare()
724 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_class_prepare()
725 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_class_prepare()
730 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch_class_prepare()
736 fci->retval = &stmt->fetch.cls.retval; in do_fetch_class_prepare()
741 zend_fcall_info_args_ex(fci, ce->constructor, &stmt->fetch.cls.ctor_args); in do_fetch_class_prepare()
746 } else if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_class_prepare()
747 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class does not have a constructor, u… in do_fetch_class_prepare()
755 static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * fci, zend_fcall_inf… in make_callable_ex() argument
761 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error); in make_callable_ex()
764 … pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback"); in make_callable_ex()
780 static int do_fetch_func_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_func_prepare() argument
782 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_func_prepare()
783 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_func_prepare()
785 if (!make_callable_ex(stmt, &stmt->fetch.func.function, fci, fcc, stmt->column_count)) { in do_fetch_func_prepare()
788 stmt->fetch.func.values = safe_emalloc(sizeof(zval), stmt->column_count, 0); in do_fetch_func_prepare()
794 static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */ in do_fetch_opt_finish() argument
797 if (stmt->fetch.cls.fci.size && stmt->fetch.cls.fci.params) { in do_fetch_opt_finish()
798 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_opt_finish()
800 zend_fcall_info_args_clear(&stmt->fetch.cls.fci, 1); in do_fetch_opt_finish()
802 efree(stmt->fetch.cls.fci.params); in do_fetch_opt_finish()
804 stmt->fetch.cls.fci.params = NULL; in do_fetch_opt_finish()
807 stmt->fetch.cls.fci.size = 0; in do_fetch_opt_finish()
808 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args) && free_ctor_agrs) { in do_fetch_opt_finish()
809 zval_ptr_dtor(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
810 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
811 stmt->fetch.cls.fci.param_count = 0; in do_fetch_opt_finish()
813 if (stmt->fetch.func.values) { in do_fetch_opt_finish()
814 efree(stmt->fetch.func.values); in do_fetch_opt_finish()
815 stmt->fetch.func.values = NULL; in do_fetch_opt_finish()
822 static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, enum pdo_fetch_type how, enu… in do_fetch() argument
830 how = stmt->default_fetch_type; in do_fetch()
835 if (!do_fetch_common(stmt, ori, offset, do_bind)) { in do_fetch()
844 if (flags & PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
847 colno = stmt->fetch.column; in do_fetch()
854 get_lazy_object(stmt, return_value); in do_fetch()
867 array_init_size(return_value, stmt->column_count); in do_fetch()
874 if (stmt->column_count != 2) { in do_fetch()
875 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_KEY_PAIR fetch mode requires the result… in do_fetch()
884 if (colno >= 0 && colno < stmt->column_count) { in do_fetch()
885 if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
886 fetch_value(stmt, return_value, 1, NULL); in do_fetch()
888 fetch_value(stmt, return_value, 0, NULL); in do_fetch()
890 fetch_value(stmt, return_value, colno, NULL); in do_fetch()
898 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in do_fetch()
911 old_ce = stmt->fetch.cls.ce; in do_fetch()
912 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in do_fetch()
913 old_arg_count = stmt->fetch.cls.fci.param_count; in do_fetch()
914 do_fetch_opt_finish(stmt, 0); in do_fetch()
916 fetch_value(stmt, &val, i++, NULL); in do_fetch()
920 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch()
922 stmt->fetch.cls.ce = cep; in do_fetch()
926 do_fetch_class_prepare(stmt); in do_fetch()
929 ce = stmt->fetch.cls.ce; in do_fetch()
931 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified"); in do_fetch()
938 if (!stmt->fetch.cls.fci.size) { in do_fetch()
939 if (!do_fetch_class_prepare(stmt)) in do_fetch()
945 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
946 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
947 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
948 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
951 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
952 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
953 ZVAL_UNDEF(&stmt->fetch.cls.retval); in do_fetch()
961 if (Z_ISUNDEF(stmt->fetch.into)) { in do_fetch()
962 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified."); in do_fetch()
967 ZVAL_COPY(return_value, &stmt->fetch.into); in do_fetch()
975 if (Z_ISUNDEF(stmt->fetch.func.function)) { in do_fetch()
976 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch function specified"); in do_fetch()
979 if (!stmt->fetch.func.fci.size) { in do_fetch()
980 if (!do_fetch_func_prepare(stmt)) in do_fetch()
994 if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) { in do_fetch()
995 fetch_value(stmt, &grp_val, colno, NULL); in do_fetch()
997 fetch_value(stmt, &grp_val, i, NULL); in do_fetch()
1001 i = stmt->column_count; /* no more data to fetch */ in do_fetch()
1007 for (idx = 0; i < stmt->column_count; i++, idx++) { in do_fetch()
1009 fetch_value(stmt, &val, i, NULL); in do_fetch()
1013 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1019 fetch_value(stmt, &tmp, ++i, NULL); in do_fetch()
1034 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1045 if ((curr_val = zend_hash_find(Z_ARRVAL_P(return_value), stmt->columns[i].name))) { in do_fetch()
1070 zend_hash_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1082 stmt->columns[i].name, in do_fetch()
1090 stmt->columns[i].name, in do_fetch()
1099 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize data"); in do_fetch()
1107 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1111 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1122 ZVAL_COPY_VALUE(&stmt->fetch.func.values[idx], &val); in do_fetch()
1123 ZVAL_COPY_VALUE(&stmt->fetch.cls.fci.params[idx], &stmt->fetch.func.values[idx]); in do_fetch()
1128 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range"); in do_fetch()
1137 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
1138 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
1139 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
1140 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
1143 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
1144 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
1149 do_fetch_opt_finish(stmt, 0); in do_fetch()
1150 stmt->fetch.cls.ce = old_ce; in do_fetch()
1151 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in do_fetch()
1152 stmt->fetch.cls.fci.param_count = old_arg_count; in do_fetch()
1157 stmt->fetch.func.fci.param_count = idx; in do_fetch()
1158 stmt->fetch.func.fci.retval = &retval; in do_fetch()
1159 if (zend_call_function(&stmt->fetch.func.fci, &stmt->fetch.func.fcc) == FAILURE) { in do_fetch()
1160 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call user-supplied function"); in do_fetch()
1171 zval_ptr_dtor(&stmt->fetch.func.values[idx]); in do_fetch()
1201 static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, int fetch_all) /* {{{ */ in pdo_stmt_verify_mode() argument
1208 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1213 flags = stmt->default_fetch_type & PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1214 mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1220 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_FUNC is only allowed in PDOStatement::f… in pdo_stmt_verify_mode()
1227 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_LAZY can't be used with PDOStatement::f… in pdo_stmt_verify_mode()
1233 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together wit… in pdo_stmt_verify_mode()
1237 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_CLASSTYPE can only be used together wit… in pdo_stmt_verify_mode()
1241 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1270 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1274 if (!do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1303 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1307 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1308 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1309 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1311 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1315 ZVAL_ARR(&stmt->fetch.cls.ctor_args, zend_array_dup(Z_ARRVAL_P(ctor_args))); in PHP_METHOD()
1317 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1321 stmt->fetch.cls.ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1323 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1324 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class"); in PHP_METHOD()
1328 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1331 if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1337 do_fetch_opt_finish(stmt, 1); in PHP_METHOD()
1339 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1340 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1341 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()
1390 if (!pdo_stmt_verify_mode(stmt, how, 1)) { in PHP_METHOD()
1394 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1395 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1396 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1398 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1405 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1409 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in PHP_METHOD()
1419 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */ in PHP_METHOD()
1421 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1424 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)"); in PHP_METHOD()
1428 stmt->fetch.cls.ce = zend_fetch_class(Z_STR_P(arg2), ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1429 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1430 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not find user-specified class"); in PHP_METHOD()
1437 do_fetch_class_prepare(stmt); in PHP_METHOD()
1445 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); in PHP_METHOD()
1450 ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); in PHP_METHOD()
1451 if (do_fetch_func_prepare(stmt) == 0) { in PHP_METHOD()
1462 stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; in PHP_METHOD()
1466 stmt->fetch.column = Z_LVAL_P(arg2); in PHP_METHOD()
1469 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"… in PHP_METHOD()
1476 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Extraneous additional parameters"); in PHP_METHOD()
1484 flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS; in PHP_METHOD()
1485 how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in PHP_METHOD()
1491 (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR) in PHP_METHOD()
1498 if (!do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)) { in PHP_METHOD()
1504 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1505 …} else if (how == PDO_FETCH_KEY_PAIR || (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type … in PHP_METHOD()
1506 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1511 } while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, 0)); in PHP_METHOD()
1515 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1517 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1518 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1519 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1535 static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int is_param) /* {{… in register_bound_param() argument
1559 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in register_bound_param()
1568 if (!really_register_bound_param(&param, stmt, is_param)) { in register_bound_param()
1602 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in PHP_METHOD()
1607 if (!really_register_bound_param(&param, stmt, TRUE)) { in PHP_METHOD()
1623 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); in PHP_METHOD()
1632 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 0)); in PHP_METHOD()
1642 RETURN_LONG(stmt->row_count); in PHP_METHOD()
1656 if (stmt->error_code[0] == '\0') { in PHP_METHOD()
1660 RETURN_STRING(stmt->error_code); in PHP_METHOD()
1679 add_next_index_string(return_value, stmt->error_code); in PHP_METHOD()
1681 if (stmt->dbh->methods->fetch_err) { in PHP_METHOD()
1682 stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); in PHP_METHOD()
1711 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1716 if (stmt->methods->set_attribute(stmt, attr, value)) { in PHP_METHOD()
1721 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1722 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support setting attributes"); in PHP_METHOD()
1733 static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, zend_long attr) in generic_stmt_attr_get() argument
1737 RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE); in generic_stmt_attr_get()
1752 if (!stmt->methods->get_attribute) { in PHP_METHOD()
1753 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1754 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1762 switch (stmt->methods->get_attribute(stmt, attr, return_value)) { in PHP_METHOD()
1768 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1770 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1790 RETURN_LONG(stmt->column_count); in PHP_METHOD()
1807 pdo_raise_impl_error(stmt->dbh, stmt, "42P10", "column number must be non-negative"); in PHP_METHOD()
1811 if (!stmt->methods->get_column_meta) { in PHP_METHOD()
1812 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support meta data"); in PHP_METHOD()
1817 if (FAILURE == stmt->methods->get_column_meta(stmt, colno, return_value)) { in PHP_METHOD()
1823 col = &stmt->columns[colno]; in PHP_METHOD()
1837 int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int skip) in pdo_stmt_setup_fetch_mode() argument
1845 do_fetch_opt_finish(stmt, 1); in pdo_stmt_setup_fetch_mode()
1847 switch (stmt->default_fetch_type) { in pdo_stmt_setup_fetch_mode()
1849 if (!Z_ISUNDEF(stmt->fetch.into)) { in pdo_stmt_setup_fetch_mode()
1850 zval_ptr_dtor(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1851 ZVAL_UNDEF(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1858 stmt->default_fetch_type = PDO_FETCH_BOTH; in pdo_stmt_setup_fetch_mode()
1870 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "mode must be an integer"); in pdo_stmt_setup_fetch_mode()
1877 retval = pdo_stmt_verify_mode(stmt, mode, 0) ? SUCCESS : FAILURE; in pdo_stmt_setup_fetch_mode()
1899 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); in pdo_stmt_setup_fetch_mode()
1907 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the colno argument"); in pdo_stmt_setup_fetch_mode()
1909 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "colno must be an integer"); in pdo_stmt_setup_fetch_mode()
1911 stmt->fetch.column = Z_LVAL(args[skip+1]); in pdo_stmt_setup_fetch_mode()
1920 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode doesn't allow any extra arguments"); in pdo_stmt_setup_fetch_mode()
1922 stmt->fetch.cls.ce = NULL; in pdo_stmt_setup_fetch_mode()
1927 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the classname argument"); in pdo_stmt_setup_fetch_mode()
1929 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "too many arguments"); in pdo_stmt_setup_fetch_mode()
1931 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "classname must be a string"); in pdo_stmt_setup_fetch_mode()
1936 stmt->fetch.cls.ce = cep; in pdo_stmt_setup_fetch_mode()
1942 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in pdo_stmt_setup_fetch_mode()
1944 if (stmt->dbh->is_persistent) { in pdo_stmt_setup_fetch_mode()
1950 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in pdo_stmt_setup_fetch_mode()
1953 ZVAL_ARR(&stmt->fetch.cls.ctor_args, zend_array_dup(Z_ARRVAL(args[skip+2]))); in pdo_stmt_setup_fetch_mode()
1958 do_fetch_class_prepare(stmt); in pdo_stmt_setup_fetch_mode()
1966 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "fetch mode requires the object parameter"); in pdo_stmt_setup_fetch_mode()
1968 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "object must be an object"); in pdo_stmt_setup_fetch_mode()
1975 if (stmt->dbh->is_persistent) { in pdo_stmt_setup_fetch_mode()
1979 ZVAL_COPY(&stmt->fetch.into, &args[skip+1]); in pdo_stmt_setup_fetch_mode()
1985 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "Invalid fetch mode specified"); in pdo_stmt_setup_fetch_mode()
1989 stmt->default_fetch_type = mode; in pdo_stmt_setup_fetch_mode()
2012 stmt, 0) == SUCCESS ? 1 : 0 in PHP_METHOD()
2020 static int pdo_stmt_do_next_rowset(pdo_stmt_t *stmt) in pdo_stmt_do_next_rowset() argument
2023 if (stmt->columns) { in pdo_stmt_do_next_rowset()
2025 struct pdo_column_data *cols = stmt->columns; in pdo_stmt_do_next_rowset()
2027 for (i = 0; i < stmt->column_count; i++) { in pdo_stmt_do_next_rowset()
2032 efree(stmt->columns); in pdo_stmt_do_next_rowset()
2033 stmt->columns = NULL; in pdo_stmt_do_next_rowset()
2034 stmt->column_count = 0; in pdo_stmt_do_next_rowset()
2037 if (!stmt->methods->next_rowset(stmt)) { in pdo_stmt_do_next_rowset()
2039 stmt->executed = 0; in pdo_stmt_do_next_rowset()
2043 pdo_stmt_describe_columns(stmt); in pdo_stmt_do_next_rowset()
2052 if (!stmt->methods->next_rowset) { in PHP_METHOD()
2053 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver does not support multiple rowsets"); in PHP_METHOD()
2059 if (!pdo_stmt_do_next_rowset(stmt)) { in PHP_METHOD()
2074 if (!stmt->methods->cursor_closer) { in PHP_METHOD()
2077 while (stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0)) in PHP_METHOD()
2079 if (!stmt->methods->next_rowset) { in PHP_METHOD()
2083 if (!pdo_stmt_do_next_rowset(stmt)) { in PHP_METHOD()
2088 stmt->executed = 0; in PHP_METHOD()
2094 if (!stmt->methods->cursor_closer(stmt)) { in PHP_METHOD()
2098 stmt->executed = 0; in PHP_METHOD()
2116 php_stream_printf(out, "SQL: [%zd] ", stmt->query_stringlen); in PHP_METHOD()
2117 php_stream_write(out, stmt->query_string, stmt->query_stringlen); in PHP_METHOD()
2122 if (stmt->active_query_string != NULL && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
2124 php_stream_printf(out, "Sent SQL: [%zd] ", stmt->active_query_stringlen); in PHP_METHOD()
2125 php_stream_write(out, stmt->active_query_string, stmt->active_query_stringlen); in PHP_METHOD()
2130 stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0); in PHP_METHOD()
2132 if (stmt->bound_params) { in PHP_METHOD()
2135 ZEND_HASH_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { in PHP_METHOD()
2204 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_write() local
2209 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_write()
2217 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_delete() local
2222 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_delete()
2237 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(object); in dbstmt_method_get() local
2239 if (!stmt->dbh) { in dbstmt_method_get()
2244 if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2245 if (!pdo_hash_methods(Z_PDO_OBJECT_P(&stmt->database_object_handle), in dbstmt_method_get()
2247 || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2252 …if ((fbc = zend_hash_find_ptr(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT], lc_method_n… in dbstmt_method_get()
2303 PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt) in php_pdo_free_statement() argument
2305 if (stmt->bound_params) { in php_pdo_free_statement()
2306 zend_hash_destroy(stmt->bound_params); in php_pdo_free_statement()
2307 FREE_HASHTABLE(stmt->bound_params); in php_pdo_free_statement()
2308 stmt->bound_params = NULL; in php_pdo_free_statement()
2310 if (stmt->bound_param_map) { in php_pdo_free_statement()
2311 zend_hash_destroy(stmt->bound_param_map); in php_pdo_free_statement()
2312 FREE_HASHTABLE(stmt->bound_param_map); in php_pdo_free_statement()
2313 stmt->bound_param_map = NULL; in php_pdo_free_statement()
2315 if (stmt->bound_columns) { in php_pdo_free_statement()
2316 zend_hash_destroy(stmt->bound_columns); in php_pdo_free_statement()
2317 FREE_HASHTABLE(stmt->bound_columns); in php_pdo_free_statement()
2318 stmt->bound_columns = NULL; in php_pdo_free_statement()
2321 if (stmt->methods && stmt->methods->dtor) { in php_pdo_free_statement()
2322 stmt->methods->dtor(stmt); in php_pdo_free_statement()
2324 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in php_pdo_free_statement()
2325 efree(stmt->active_query_string); in php_pdo_free_statement()
2327 if (stmt->query_string) { in php_pdo_free_statement()
2328 efree(stmt->query_string); in php_pdo_free_statement()
2331 if (stmt->columns) { in php_pdo_free_statement()
2333 struct pdo_column_data *cols = stmt->columns; in php_pdo_free_statement()
2335 for (i = 0; i < stmt->column_count; i++) { in php_pdo_free_statement()
2341 efree(stmt->columns); in php_pdo_free_statement()
2342 stmt->columns = NULL; in php_pdo_free_statement()
2345 if (!Z_ISUNDEF(stmt->fetch.into) && stmt->default_fetch_type == PDO_FETCH_INTO) { in php_pdo_free_statement()
2346 zval_ptr_dtor(&stmt->fetch.into); in php_pdo_free_statement()
2347 ZVAL_UNDEF(&stmt->fetch.into); in php_pdo_free_statement()
2350 do_fetch_opt_finish(stmt, 1); in php_pdo_free_statement()
2352 if (!Z_ISUNDEF(stmt->database_object_handle)) { in php_pdo_free_statement()
2353 zval_ptr_dtor(&stmt->database_object_handle); in php_pdo_free_statement()
2355 zend_object_std_dtor(&stmt->std); in php_pdo_free_statement()
2360 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std); in pdo_dbstmt_free_storage() local
2361 php_pdo_free_statement(stmt); in pdo_dbstmt_free_storage()
2366 pdo_stmt_t *stmt; in pdo_dbstmt_new() local
2368 stmt = zend_object_alloc(sizeof(pdo_stmt_t), ce); in pdo_dbstmt_new()
2369 zend_object_std_init(&stmt->std, ce); in pdo_dbstmt_new()
2370 object_properties_init(&stmt->std, ce); in pdo_dbstmt_new()
2372 stmt->std.handlers = &pdo_dbstmt_object_handlers; in pdo_dbstmt_new()
2374 return &stmt->std; in pdo_dbstmt_new()
2430 pdo_stmt_t *stmt = Z_PDO_STMT_P(&I->iter.data); /* for PDO_HANDLE_STMT_ERR() */ in pdo_stmt_iter_move_forwards() local
2436 if (!do_fetch(stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_move_forwards()
2461 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in pdo_stmt_iter_get() local
2474 if (!do_fetch(stmt, 1, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_get()
2495 pdo_stmt_t *stmt = row->stmt; in row_prop_read() local
2501 if (stmt) { in row_prop_read()
2503 if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) { in row_prop_read()
2504 fetch_value(stmt, rv, Z_LVAL_P(member), NULL); in row_prop_read()
2508 if (lval >= 0 && lval < stmt->column_count) { in row_prop_read()
2509 fetch_value(stmt, rv, lval, NULL); in row_prop_read()
2515 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_read()
2516 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_read()
2517 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_read()
2518 fetch_value(stmt, rv, colno, NULL); in row_prop_read()
2523 ZVAL_OBJ(&zobj, &stmt->std); in row_prop_read()
2551 pdo_stmt_t *stmt = row->stmt; in row_prop_exists() local
2555 if (stmt) { in row_prop_exists()
2557 return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count; in row_prop_exists()
2560 return lval >=0 && lval < stmt->column_count; in row_prop_exists()
2568 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_exists()
2569 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_exists()
2570 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_exists()
2574 fetch_value(stmt, &val, colno, NULL); in row_prop_exists()
2604 pdo_stmt_t *stmt = row->stmt; in row_get_properties() local
2607 if (stmt == NULL) { in row_get_properties()
2611 if (!stmt->std.properties) { in row_get_properties()
2612 rebuild_object_properties(&stmt->std); in row_get_properties()
2614 for (i = 0; i < stmt->column_count; i++) { in row_get_properties()
2616 fetch_value(stmt, &val, i, NULL); in row_get_properties()
2618 zend_hash_update(stmt->std.properties, stmt->columns[i].name, &val); in row_get_properties()
2621 return stmt->std.properties; in row_get_properties()
2698 if (row->stmt) { in pdo_row_free_storage()
2699 ZVAL_UNDEF(&row->stmt->lazy_object_ref); in pdo_row_free_storage()
2700 OBJ_RELEASE(&row->stmt->std); in pdo_row_free_storage()