Lines Matching refs:stmt

111   pdo_stmt_t *stmt = Z_PDO_STMT_P(getThis());	\  in ZEND_END_ARG_INFO()
112 if (!stmt->dbh) { \
122 static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_param_data *param) /*… in rewrite_name_to_position() argument
124 if (stmt->bound_param_map) { in rewrite_name_to_position()
134 if (stmt->named_rewrite_template) { in rewrite_name_to_position()
140 if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) { in rewrite_name_to_position()
144 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); in rewrite_name_to_position()
148 ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) { in rewrite_name_to_position()
154 …pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "PDO refuses to handle repeating the same :named pa… in rewrite_name_to_position()
160 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); in rewrite_name_to_position()
168 static int dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_type) /* {{{ */ in dispatch_param_event() argument
174 if (!stmt->methods->param_hook) { in dispatch_param_event()
178 ht = stmt->bound_params; in dispatch_param_event()
183 if (!stmt->methods->param_hook(stmt, param, event_type)) { in dispatch_param_event()
190 ht = stmt->bound_columns; in dispatch_param_event()
199 int pdo_stmt_describe_columns(pdo_stmt_t *stmt) /* {{{ */ in pdo_stmt_describe_columns() argument
203 stmt->columns = ecalloc(stmt->column_count, sizeof(struct pdo_column_data)); in pdo_stmt_describe_columns()
205 for (col = 0; col < stmt->column_count; col++) { in pdo_stmt_describe_columns()
206 if (!stmt->methods->describer(stmt, col)) { in pdo_stmt_describe_columns()
211 …if (stmt->dbh->native_case != stmt->dbh->desired_case && stmt->dbh->desired_case != PDO_CASE_NATUR… in pdo_stmt_describe_columns()
212 char *s = ZSTR_VAL(stmt->columns[col].name); in pdo_stmt_describe_columns()
214 switch (stmt->dbh->desired_case) { in pdo_stmt_describe_columns()
234 if (stmt->bound_params) { in pdo_stmt_describe_columns()
237 if (SUCCESS == zend_hash_find(stmt->bound_params, stmt->columns[col].name, in pdo_stmt_describe_columns()
238 stmt->columns[col].namelen, (void**)&param)) { in pdo_stmt_describe_columns()
243 if (stmt->bound_columns) { in pdo_stmt_describe_columns()
246 if ((param = zend_hash_find_ptr(stmt->bound_columns, in pdo_stmt_describe_columns()
247 stmt->columns[col].name)) != NULL) { in pdo_stmt_describe_columns()
257 static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */ in get_lazy_object() argument
259 if (Z_ISUNDEF(stmt->lazy_object_ref)) { in get_lazy_object()
261 row->stmt = stmt; in get_lazy_object()
263 ZVAL_OBJ(&stmt->lazy_object_ref, &row->std); in get_lazy_object()
265 GC_REFCOUNT(&stmt->std)++; in get_lazy_object()
268 ZVAL_COPY(return_value, &stmt->lazy_object_ref); in get_lazy_object()
277 if (param->stmt->methods->param_hook) { in param_dtor()
278 param->stmt->methods->param_hook(param->stmt, param, PDO_PARAM_EVT_FREE); in param_dtor()
296 static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_stmt_t *stmt, int is… in really_register_bound_param() argument
302 hash = is_param ? stmt->bound_params : stmt->bound_columns; in really_register_bound_param()
309 stmt->bound_params = hash; in really_register_bound_param()
311 stmt->bound_columns = hash; in really_register_bound_param()
336 param->stmt = stmt; in really_register_bound_param()
343 if (!is_param && param->name && stmt->columns) { in really_register_bound_param()
347 for (i = 0; i < stmt->column_count; i++) { in really_register_bound_param()
348 if (ZSTR_LEN(stmt->columns[i].name) == ZSTR_LEN(param->name) && in really_register_bound_param()
349 … strncmp(ZSTR_VAL(stmt->columns[i].name), ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1) == 0) { in really_register_bound_param()
360 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp); in really_register_bound_param()
376 if (is_param && !rewrite_name_to_position(stmt, param)) { in really_register_bound_param()
388 if (stmt->methods->param_hook) { in really_register_bound_param()
389 if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE in really_register_bound_param()
414 if (stmt->methods->param_hook) { in really_register_bound_param()
415 if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC in really_register_bound_param()
453 if (stmt->bound_params) { in PHP_METHOD()
454 zend_hash_destroy(stmt->bound_params); in PHP_METHOD()
455 FREE_HASHTABLE(stmt->bound_params); in PHP_METHOD()
456 stmt->bound_params = NULL; in PHP_METHOD()
480 if (!really_register_bound_param(&param, stmt, 1)) { in PHP_METHOD()
489 if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { in PHP_METHOD()
495 ret = pdo_parse_params(stmt, stmt->query_string, stmt->query_stringlen, in PHP_METHOD()
496 &stmt->active_query_string, &stmt->active_query_stringlen); in PHP_METHOD()
500 stmt->active_query_string = stmt->query_string; in PHP_METHOD()
501 stmt->active_query_stringlen = stmt->query_stringlen; in PHP_METHOD()
508 } else if (!dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_PRE)) { in PHP_METHOD()
512 if (stmt->methods->executer(stmt)) { in PHP_METHOD()
513 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
514 efree(stmt->active_query_string); in PHP_METHOD()
516 stmt->active_query_string = NULL; in PHP_METHOD()
517 if (!stmt->executed) { in PHP_METHOD()
520 if (stmt->dbh->alloc_own_columns && !stmt->columns) { in PHP_METHOD()
523 ret = pdo_stmt_describe_columns(stmt); in PHP_METHOD()
526 stmt->executed = 1; in PHP_METHOD()
529 if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) { in PHP_METHOD()
535 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
536 efree(stmt->active_query_string); in PHP_METHOD()
538 stmt->active_query_string = NULL; in PHP_METHOD()
544 static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *type_override) /* {{{ … in fetch_value() argument
552 col = &stmt->columns[colno]; in fetch_value()
559 stmt->methods->get_col(stmt, colno, &value, &value_len, &caller_frees); in fetch_value()
595 if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) { in fetch_value()
607 } else if (!stmt->dbh->stringify && new_type != PDO_PARAM_STR) { in fetch_value()
632 if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) { in fetch_value()
663 if (stmt->dbh->stringify) { in fetch_value()
672 if (Z_TYPE_P(dest) == IS_NULL && stmt->dbh->oracle_nulls == PDO_NULL_TO_STRING) { in fetch_value()
678 static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset, int … in do_fetch_common() argument
680 if (!stmt->executed) { in do_fetch_common()
684 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_PRE)) { in do_fetch_common()
688 if (!stmt->methods->fetcher(stmt, ori, offset)) { in do_fetch_common()
693 if (!stmt->columns && !pdo_stmt_describe_columns(stmt)) { in do_fetch_common()
697 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST)) { in do_fetch_common()
701 if (do_bind && stmt->bound_columns) { in do_fetch_common()
705 ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { in do_fetch_common()
715 fetch_value(stmt, Z_REFVAL(param->parameter), param->paramno, (int *)&param->param_type); in do_fetch_common()
729 static int do_fetch_class_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_class_prepare() argument
731 zend_class_entry *ce = stmt->fetch.cls.ce; in do_fetch_class_prepare()
732 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_class_prepare()
733 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_class_prepare()
738 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch_class_prepare()
746 fci->retval = &stmt->fetch.cls.retval; in do_fetch_class_prepare()
751 zend_fcall_info_args_ex(fci, ce->constructor, &stmt->fetch.cls.ctor_args); in do_fetch_class_prepare()
758 } else if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_class_prepare()
759 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class does not have a constructor, u… in do_fetch_class_prepare()
767 static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * fci, zend_fcall_inf… in make_callable_ex() argument
773 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error); in make_callable_ex()
776 … pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback"); in make_callable_ex()
792 static int do_fetch_func_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_func_prepare() argument
794 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_func_prepare()
795 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_func_prepare()
797 if (!make_callable_ex(stmt, &stmt->fetch.func.function, fci, fcc, stmt->column_count)) { in do_fetch_func_prepare()
800 stmt->fetch.func.values = safe_emalloc(sizeof(zval), stmt->column_count, 0); in do_fetch_func_prepare()
806 static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */ in do_fetch_opt_finish() argument
809 if (stmt->fetch.cls.fci.size && stmt->fetch.cls.fci.params) { in do_fetch_opt_finish()
810 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args)) { in do_fetch_opt_finish()
812 zend_fcall_info_args_clear(&stmt->fetch.cls.fci, 1); in do_fetch_opt_finish()
814 efree(stmt->fetch.cls.fci.params); in do_fetch_opt_finish()
816 stmt->fetch.cls.fci.params = NULL; in do_fetch_opt_finish()
819 stmt->fetch.cls.fci.size = 0; in do_fetch_opt_finish()
820 if (!Z_ISUNDEF(stmt->fetch.cls.ctor_args) && free_ctor_agrs) { in do_fetch_opt_finish()
821 zval_ptr_dtor(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
822 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in do_fetch_opt_finish()
823 stmt->fetch.cls.fci.param_count = 0; in do_fetch_opt_finish()
825 if (stmt->fetch.func.values) { in do_fetch_opt_finish()
826 efree(stmt->fetch.func.values); in do_fetch_opt_finish()
827 stmt->fetch.func.values = NULL; in do_fetch_opt_finish()
834 static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, enum pdo_fetch_type how, enu… in do_fetch() argument
842 how = stmt->default_fetch_type; in do_fetch()
847 if (!do_fetch_common(stmt, ori, offset, do_bind)) { in do_fetch()
856 if (flags & PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
859 colno = stmt->fetch.column; in do_fetch()
866 get_lazy_object(stmt, return_value); in do_fetch()
880 zend_hash_init(Z_ARRVAL_P(return_value), stmt->column_count, NULL, ZVAL_PTR_DTOR, 0);; in do_fetch()
887 if (stmt->column_count != 2) { in do_fetch()
888 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_KEY_PAIR fetch mode requires the result… in do_fetch()
897 if (colno >= 0 && colno < stmt->column_count) { in do_fetch()
898 if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
899 fetch_value(stmt, return_value, 1, NULL); in do_fetch()
901 fetch_value(stmt, return_value, 0, NULL); in do_fetch()
903 fetch_value(stmt, return_value, colno, NULL); in do_fetch()
911 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in do_fetch()
924 old_ce = stmt->fetch.cls.ce; in do_fetch()
925 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in do_fetch()
926 old_arg_count = stmt->fetch.cls.fci.param_count; in do_fetch()
927 do_fetch_opt_finish(stmt, 0); in do_fetch()
929 fetch_value(stmt, &val, i++, NULL); in do_fetch()
933 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch()
935 stmt->fetch.cls.ce = cep; in do_fetch()
939 do_fetch_class_prepare(stmt); in do_fetch()
942 ce = stmt->fetch.cls.ce; in do_fetch()
944 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified"); in do_fetch()
951 if (!stmt->fetch.cls.fci.size) { in do_fetch()
952 if (!do_fetch_class_prepare(stmt)) in do_fetch()
958 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
959 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
960 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
961 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
964 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
965 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
966 ZVAL_UNDEF(&stmt->fetch.cls.retval); in do_fetch()
974 if (Z_ISUNDEF(stmt->fetch.into)) { in do_fetch()
975 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified."); in do_fetch()
980 ZVAL_COPY(return_value, &stmt->fetch.into); in do_fetch()
988 if (Z_ISUNDEF(stmt->fetch.func.function)) { in do_fetch()
989 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch function specified"); in do_fetch()
992 if (!stmt->fetch.func.fci.size) { in do_fetch()
993 if (!do_fetch_func_prepare(stmt)) in do_fetch()
1007 if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) { in do_fetch()
1008 fetch_value(stmt, &grp_val, colno, NULL); in do_fetch()
1010 fetch_value(stmt, &grp_val, i, NULL); in do_fetch()
1014 i = stmt->column_count; /* no more data to fetch */ in do_fetch()
1020 for (idx = 0; i < stmt->column_count; i++, idx++) { in do_fetch()
1022 fetch_value(stmt, &val, i, NULL); in do_fetch()
1026 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1032 fetch_value(stmt, &tmp, ++i, NULL); in do_fetch()
1047 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1058 if ((curr_val = zend_hash_find(Z_ARRVAL_P(return_value), stmt->columns[i].name))) { in do_fetch()
1083 zend_hash_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1095 stmt->columns[i].name, in do_fetch()
1103 stmt->columns[i].name, in do_fetch()
1112 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize data"); in do_fetch()
1120 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1124 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1135 ZVAL_COPY_VALUE(&stmt->fetch.func.values[idx], &val); in do_fetch()
1136 ZVAL_COPY_VALUE(&stmt->fetch.cls.fci.params[idx], &stmt->fetch.func.values[idx]); in do_fetch()
1141 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range"); in do_fetch()
1150 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
1151 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
1152 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
1153 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
1156 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
1157 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
1162 do_fetch_opt_finish(stmt, 0); in do_fetch()
1163 stmt->fetch.cls.ce = old_ce; in do_fetch()
1164 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in do_fetch()
1165 stmt->fetch.cls.fci.param_count = old_arg_count; in do_fetch()
1170 stmt->fetch.func.fci.param_count = idx; in do_fetch()
1171 stmt->fetch.func.fci.retval = &retval; in do_fetch()
1172 if (zend_call_function(&stmt->fetch.func.fci, &stmt->fetch.func.fcc) == FAILURE) { in do_fetch()
1173 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call user-supplied function"); in do_fetch()
1184 zval_ptr_dtor(&stmt->fetch.func.values[idx]); in do_fetch()
1214 static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, int fetch_all) /* {{{ */ in pdo_stmt_verify_mode() argument
1221 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1226 flags = stmt->default_fetch_type & PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1227 mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1233 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_FUNC is only allowed in PDOStatement::f… in pdo_stmt_verify_mode()
1240 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_LAZY can't be used with PDOStatement::f… in pdo_stmt_verify_mode()
1246 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together wit… in pdo_stmt_verify_mode()
1250 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_CLASSTYPE can only be used together wit… in pdo_stmt_verify_mode()
1254 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1281 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1285 if (!do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1312 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1316 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1317 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1318 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1320 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1324 ZVAL_DUP(&stmt->fetch.cls.ctor_args, ctor_args); in PHP_METHOD()
1326 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1330 stmt->fetch.cls.ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1332 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1333 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class"); in PHP_METHOD()
1337 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1340 if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) { in PHP_METHOD()
1346 do_fetch_opt_finish(stmt, 1); in PHP_METHOD()
1348 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1349 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1350 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1370 if (!do_fetch_common(stmt, PDO_FETCH_ORI_NEXT, 0, TRUE)) { in PHP_METHOD()
1375 fetch_value(stmt, return_value, col_n, NULL); in PHP_METHOD()
1395 if (!pdo_stmt_verify_mode(stmt, how, 1)) { in PHP_METHOD()
1399 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1400 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1401 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1403 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1410 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1414 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in PHP_METHOD()
1424 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */ in PHP_METHOD()
1426 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1429 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)"); in PHP_METHOD()
1433 stmt->fetch.cls.ce = zend_fetch_class(Z_STR_P(arg2), ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1434 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1435 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not find user-specified class"); in PHP_METHOD()
1442 do_fetch_class_prepare(stmt); in PHP_METHOD()
1450 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); in PHP_METHOD()
1455 ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); in PHP_METHOD()
1456 if (do_fetch_func_prepare(stmt) == 0) { in PHP_METHOD()
1467 stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; in PHP_METHOD()
1471 stmt->fetch.column = Z_LVAL_P(arg2); in PHP_METHOD()
1474 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"… in PHP_METHOD()
1481 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Extraneous additional parameters"); in PHP_METHOD()
1489 flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS; in PHP_METHOD()
1490 how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in PHP_METHOD()
1496 (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR) in PHP_METHOD()
1503 if (!do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)) { in PHP_METHOD()
1509 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1510 …} else if (how == PDO_FETCH_KEY_PAIR || (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type … in PHP_METHOD()
1511 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1516 } while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, 0)); in PHP_METHOD()
1520 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1522 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1523 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1524 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1540 static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int is_param) /* {{… in register_bound_param() argument
1563 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in register_bound_param()
1572 if (!really_register_bound_param(&param, stmt, is_param)) { in register_bound_param()
1605 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in PHP_METHOD()
1610 if (!really_register_bound_param(&param, stmt, TRUE)) { in PHP_METHOD()
1626 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); in PHP_METHOD()
1635 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 0)); in PHP_METHOD()
1645 RETURN_LONG(stmt->row_count); in PHP_METHOD()
1659 if (stmt->error_code[0] == '\0') { in PHP_METHOD()
1663 RETURN_STRING(stmt->error_code); in PHP_METHOD()
1682 add_next_index_string(return_value, stmt->error_code); in PHP_METHOD()
1684 if (stmt->dbh->methods->fetch_err) { in PHP_METHOD()
1685 stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); in PHP_METHOD()
1713 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1718 if (stmt->methods->set_attribute(stmt, attr, value)) { in PHP_METHOD()
1723 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1724 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support setting attributes"); in PHP_METHOD()
1735 static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, zend_long attr) in generic_stmt_attr_get() argument
1739 RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE); in generic_stmt_attr_get()
1754 if (!stmt->methods->get_attribute) { in PHP_METHOD()
1755 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1756 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1764 switch (stmt->methods->get_attribute(stmt, attr, return_value)) { in PHP_METHOD()
1770 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1772 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1792 RETURN_LONG(stmt->column_count); in PHP_METHOD()
1808 pdo_raise_impl_error(stmt->dbh, stmt, "42P10", "column number must be non-negative"); in PHP_METHOD()
1812 if (!stmt->methods->get_column_meta) { in PHP_METHOD()
1813 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support meta data"); in PHP_METHOD()
1818 if (FAILURE == stmt->methods->get_column_meta(stmt, colno, return_value)) { in PHP_METHOD()
1824 col = &stmt->columns[colno]; in PHP_METHOD()
1838 int pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int skip) in pdo_stmt_setup_fetch_mode() argument
1846 do_fetch_opt_finish(stmt, 1); in pdo_stmt_setup_fetch_mode()
1848 switch (stmt->default_fetch_type) { in pdo_stmt_setup_fetch_mode()
1850 if (!Z_ISUNDEF(stmt->fetch.into)) { in pdo_stmt_setup_fetch_mode()
1851 zval_ptr_dtor(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1852 ZVAL_UNDEF(&stmt->fetch.into); in pdo_stmt_setup_fetch_mode()
1859 stmt->default_fetch_type = PDO_FETCH_BOTH; in pdo_stmt_setup_fetch_mode()
1871 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); 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_DUP(&stmt->fetch.cls.ctor_args, &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()
2121 stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0); in PHP_METHOD()
2123 if (stmt->bound_params) { in PHP_METHOD()
2126 ZEND_HASH_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { in PHP_METHOD()
2191 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_write() local
2196 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_write()
2204 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_delete() local
2209 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_delete()
2226 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(object); in dbstmt_method_get() local
2228 if (!stmt->dbh) { in dbstmt_method_get()
2233 if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2234 if (!pdo_hash_methods(Z_PDO_OBJECT_P(&stmt->database_object_handle), in dbstmt_method_get()
2236 || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2241 …if ((fbc = zend_hash_find_ptr(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT], lc_method_n… in dbstmt_method_get()
2262 pdo_stmt_t *stmt; in dbstmt_clone_obj() local
2265 stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(Z_OBJCE_P(zobject))); in dbstmt_clone_obj()
2266 zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject)); in dbstmt_clone_obj()
2267 object_properties_init(&stmt->std, Z_OBJCE_P(zobject)); in dbstmt_clone_obj()
2271 zend_objects_clone_members(&stmt->std, &old_stmt->std); in dbstmt_clone_obj()
2273 return &stmt->std; in dbstmt_clone_obj()
2308 PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt) in php_pdo_free_statement() argument
2310 if (stmt->bound_params) { in php_pdo_free_statement()
2311 zend_hash_destroy(stmt->bound_params); in php_pdo_free_statement()
2312 FREE_HASHTABLE(stmt->bound_params); in php_pdo_free_statement()
2313 stmt->bound_params = NULL; in php_pdo_free_statement()
2315 if (stmt->bound_param_map) { in php_pdo_free_statement()
2316 zend_hash_destroy(stmt->bound_param_map); in php_pdo_free_statement()
2317 FREE_HASHTABLE(stmt->bound_param_map); in php_pdo_free_statement()
2318 stmt->bound_param_map = NULL; in php_pdo_free_statement()
2320 if (stmt->bound_columns) { in php_pdo_free_statement()
2321 zend_hash_destroy(stmt->bound_columns); in php_pdo_free_statement()
2322 FREE_HASHTABLE(stmt->bound_columns); in php_pdo_free_statement()
2323 stmt->bound_columns = NULL; in php_pdo_free_statement()
2326 if (stmt->methods && stmt->methods->dtor) { in php_pdo_free_statement()
2327 stmt->methods->dtor(stmt); in php_pdo_free_statement()
2329 if (stmt->query_string) { in php_pdo_free_statement()
2330 efree(stmt->query_string); in php_pdo_free_statement()
2333 if (stmt->columns) { in php_pdo_free_statement()
2335 struct pdo_column_data *cols = stmt->columns; in php_pdo_free_statement()
2337 for (i = 0; i < stmt->column_count; i++) { in php_pdo_free_statement()
2343 efree(stmt->columns); in php_pdo_free_statement()
2344 stmt->columns = NULL; in php_pdo_free_statement()
2347 if (!Z_ISUNDEF(stmt->fetch.into) && stmt->default_fetch_type == PDO_FETCH_INTO) { in php_pdo_free_statement()
2348 zval_ptr_dtor(&stmt->fetch.into); in php_pdo_free_statement()
2349 ZVAL_UNDEF(&stmt->fetch.into); in php_pdo_free_statement()
2352 do_fetch_opt_finish(stmt, 1); in php_pdo_free_statement()
2354 if (!Z_ISUNDEF(stmt->database_object_handle)) { in php_pdo_free_statement()
2355 zval_ptr_dtor(&stmt->database_object_handle); in php_pdo_free_statement()
2357 zend_object_std_dtor(&stmt->std); in php_pdo_free_statement()
2362 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std); in pdo_dbstmt_free_storage() local
2363 php_pdo_free_statement(stmt); in pdo_dbstmt_free_storage()
2368 pdo_stmt_t *stmt; in pdo_dbstmt_new() local
2370 stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(ce)); in pdo_dbstmt_new()
2371 zend_object_std_init(&stmt->std, ce); in pdo_dbstmt_new()
2372 object_properties_init(&stmt->std, ce); in pdo_dbstmt_new()
2374 stmt->std.handlers = &pdo_dbstmt_object_handlers; in pdo_dbstmt_new()
2376 return &stmt->std; in pdo_dbstmt_new()
2432 pdo_stmt_t *stmt = Z_PDO_STMT_P(&I->iter.data); /* for PDO_HANDLE_STMT_ERR() */ in pdo_stmt_iter_move_forwards() local
2438 if (!do_fetch(stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_move_forwards()
2462 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()
2701 if (row->stmt) { in pdo_row_free_storage()
2702 ZVAL_UNDEF(&row->stmt->lazy_object_ref); in pdo_row_free_storage()
2703 OBJ_RELEASE(&row->stmt->std); in pdo_row_free_storage()