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()
227 if (stmt->bound_columns) { in pdo_stmt_describe_columns()
230 if ((param = zend_hash_find_ptr(stmt->bound_columns, in pdo_stmt_describe_columns()
231 stmt->columns[col].name)) != NULL) { in pdo_stmt_describe_columns()
241 static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */ in get_lazy_object() argument
243 if (Z_ISUNDEF(stmt->lazy_object_ref)) { in get_lazy_object()
245 row->stmt = stmt; in get_lazy_object()
247 ZVAL_OBJ(&stmt->lazy_object_ref, &row->std); in get_lazy_object()
249 GC_REFCOUNT(&stmt->std)++; in get_lazy_object()
252 ZVAL_COPY(return_value, &stmt->lazy_object_ref); in get_lazy_object()
261 if (param->stmt->methods->param_hook) { in param_dtor()
262 param->stmt->methods->param_hook(param->stmt, param, PDO_PARAM_EVT_FREE); in param_dtor()
280 static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_stmt_t *stmt, int is… in really_register_bound_param() argument
286 hash = is_param ? stmt->bound_params : stmt->bound_columns; in really_register_bound_param()
293 stmt->bound_params = hash; in really_register_bound_param()
295 stmt->bound_columns = hash; in really_register_bound_param()
320 param->stmt = stmt; in really_register_bound_param()
327 if (!is_param && param->name && stmt->columns) { in really_register_bound_param()
331 for (i = 0; i < stmt->column_count; i++) { in really_register_bound_param()
332 if (ZSTR_LEN(stmt->columns[i].name) == ZSTR_LEN(param->name) && in really_register_bound_param()
333 … strncmp(ZSTR_VAL(stmt->columns[i].name), ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1) == 0) { in really_register_bound_param()
344 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", tmp); in really_register_bound_param()
360 if (is_param && !rewrite_name_to_position(stmt, param)) { in really_register_bound_param()
372 if (stmt->methods->param_hook) { in really_register_bound_param()
373 if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE in really_register_bound_param()
398 if (stmt->methods->param_hook) { in really_register_bound_param()
399 if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC in really_register_bound_param()
438 if (stmt->bound_params) { in PHP_METHOD()
439 zend_hash_destroy(stmt->bound_params); in PHP_METHOD()
440 FREE_HASHTABLE(stmt->bound_params); in PHP_METHOD()
441 stmt->bound_params = NULL; in PHP_METHOD()
465 if (!really_register_bound_param(¶m, stmt, 1)) { in PHP_METHOD()
474 if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { in PHP_METHOD()
481 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in PHP_METHOD()
482 efree(stmt->active_query_string); in PHP_METHOD()
484 stmt->active_query_string = NULL; in PHP_METHOD()
486 ret = pdo_parse_params(stmt, stmt->query_string, stmt->query_stringlen, in PHP_METHOD()
487 &stmt->active_query_string, &stmt->active_query_stringlen); in PHP_METHOD()
491 stmt->active_query_string = stmt->query_string; in PHP_METHOD()
492 stmt->active_query_stringlen = stmt->query_stringlen; in PHP_METHOD()
499 } else if (!dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_PRE)) { in PHP_METHOD()
503 if (stmt->methods->executer(stmt)) { in PHP_METHOD()
504 if (!stmt->executed) { in PHP_METHOD()
507 if (stmt->dbh->alloc_own_columns && !stmt->columns) { in PHP_METHOD()
510 ret = pdo_stmt_describe_columns(stmt); in PHP_METHOD()
513 stmt->executed = 1; in PHP_METHOD()
516 if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST)) { in PHP_METHOD()
527 static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *type_override) /* {{{ … in fetch_value() argument
535 if (colno < 0 || colno >= stmt->column_count) { in fetch_value()
536 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in fetch_value()
542 col = &stmt->columns[colno]; in fetch_value()
549 stmt->methods->get_col(stmt, colno, &value, &value_len, &caller_frees); in fetch_value()
585 if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) { in fetch_value()
597 } else if (!stmt->dbh->stringify && new_type != PDO_PARAM_STR) { in fetch_value()
622 if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) { in fetch_value()
653 if (stmt->dbh->stringify) { in fetch_value()
662 if (Z_TYPE_P(dest) == IS_NULL && stmt->dbh->oracle_nulls == PDO_NULL_TO_STRING) { in fetch_value()
668 static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset, int … in do_fetch_common() argument
670 if (!stmt->executed) { in do_fetch_common()
674 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_PRE)) { in do_fetch_common()
678 if (!stmt->methods->fetcher(stmt, ori, offset)) { in do_fetch_common()
683 if (!stmt->columns && !pdo_stmt_describe_columns(stmt)) { in do_fetch_common()
687 if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST)) { in do_fetch_common()
691 if (do_bind && stmt->bound_columns) { in do_fetch_common()
695 ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { in do_fetch_common()
705 fetch_value(stmt, Z_REFVAL(param->parameter), param->paramno, (int *)¶m->param_type); in do_fetch_common()
719 static int do_fetch_class_prepare(pdo_stmt_t *stmt) /* {{{ */ in do_fetch_class_prepare() argument
721 zend_class_entry *ce = stmt->fetch.cls.ce; in do_fetch_class_prepare()
722 zend_fcall_info *fci = &stmt->fetch.cls.fci; in do_fetch_class_prepare()
723 zend_fcall_info_cache *fcc = &stmt->fetch.cls.fcc; in do_fetch_class_prepare()
728 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch_class_prepare()
734 fci->retval = &stmt->fetch.cls.retval; in do_fetch_class_prepare()
739 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()
868 zend_hash_init(Z_ARRVAL_P(return_value), stmt->column_count, NULL, ZVAL_PTR_DTOR, 0); in do_fetch()
875 if (stmt->column_count != 2) { in do_fetch()
876 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_KEY_PAIR fetch mode requires the result… in do_fetch()
885 if (colno >= 0 && colno < stmt->column_count) { in do_fetch()
886 if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) { in do_fetch()
887 fetch_value(stmt, return_value, 1, NULL); in do_fetch()
889 fetch_value(stmt, return_value, 0, NULL); in do_fetch()
891 fetch_value(stmt, return_value, colno, NULL); in do_fetch()
899 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid column index"); in do_fetch()
912 old_ce = stmt->fetch.cls.ce; in do_fetch()
913 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in do_fetch()
914 old_arg_count = stmt->fetch.cls.fci.param_count; in do_fetch()
915 do_fetch_opt_finish(stmt, 0); in do_fetch()
917 fetch_value(stmt, &val, i++, NULL); in do_fetch()
921 stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR; in do_fetch()
923 stmt->fetch.cls.ce = cep; in do_fetch()
927 do_fetch_class_prepare(stmt); in do_fetch()
930 ce = stmt->fetch.cls.ce; in do_fetch()
932 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified"); in do_fetch()
939 if (!stmt->fetch.cls.fci.size) { in do_fetch()
940 if (!do_fetch_class_prepare(stmt)) in do_fetch()
946 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
947 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
948 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
949 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
952 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
953 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
954 ZVAL_UNDEF(&stmt->fetch.cls.retval); in do_fetch()
962 if (Z_ISUNDEF(stmt->fetch.into)) { in do_fetch()
963 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified."); in do_fetch()
968 ZVAL_COPY(return_value, &stmt->fetch.into); in do_fetch()
976 if (Z_ISUNDEF(stmt->fetch.func.function)) { in do_fetch()
977 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch function specified"); in do_fetch()
980 if (!stmt->fetch.func.fci.size) { in do_fetch()
981 if (!do_fetch_func_prepare(stmt)) in do_fetch()
995 if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) { in do_fetch()
996 fetch_value(stmt, &grp_val, colno, NULL); in do_fetch()
998 fetch_value(stmt, &grp_val, i, NULL); in do_fetch()
1002 i = stmt->column_count; /* no more data to fetch */ in do_fetch()
1008 for (idx = 0; i < stmt->column_count; i++, idx++) { in do_fetch()
1010 fetch_value(stmt, &val, i, NULL); in do_fetch()
1014 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1020 fetch_value(stmt, &tmp, ++i, NULL); in do_fetch()
1035 zend_symtable_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1046 if ((curr_val = zend_hash_find(Z_ARRVAL_P(return_value), stmt->columns[i].name))) { in do_fetch()
1071 zend_hash_update(Z_ARRVAL_P(return_value), stmt->columns[i].name, &val); in do_fetch()
1083 stmt->columns[i].name, in do_fetch()
1091 stmt->columns[i].name, in do_fetch()
1100 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize data"); in do_fetch()
1108 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1112 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "cannot unserialize class"); in do_fetch()
1123 ZVAL_COPY_VALUE(&stmt->fetch.func.values[idx], &val); in do_fetch()
1124 ZVAL_COPY_VALUE(&stmt->fetch.cls.fci.params[idx], &stmt->fetch.func.values[idx]); in do_fetch()
1129 pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range"); in do_fetch()
1138 stmt->fetch.cls.fci.object = Z_OBJ_P(return_value); in do_fetch()
1139 stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value); in do_fetch()
1140 if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) { in do_fetch()
1141 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor"); in do_fetch()
1144 if (!Z_ISUNDEF(stmt->fetch.cls.retval)) { in do_fetch()
1145 zval_ptr_dtor(&stmt->fetch.cls.retval); in do_fetch()
1150 do_fetch_opt_finish(stmt, 0); in do_fetch()
1151 stmt->fetch.cls.ce = old_ce; in do_fetch()
1152 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in do_fetch()
1153 stmt->fetch.cls.fci.param_count = old_arg_count; in do_fetch()
1158 stmt->fetch.func.fci.param_count = idx; in do_fetch()
1159 stmt->fetch.func.fci.retval = &retval; in do_fetch()
1160 if (zend_call_function(&stmt->fetch.func.fci, &stmt->fetch.func.fcc) == FAILURE) { in do_fetch()
1161 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call user-supplied function"); in do_fetch()
1172 zval_ptr_dtor(&stmt->fetch.func.values[idx]); in do_fetch()
1202 static int pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, int fetch_all) /* {{{ */ in pdo_stmt_verify_mode() argument
1209 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1214 flags = stmt->default_fetch_type & PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1215 mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in pdo_stmt_verify_mode()
1221 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_FUNC is only allowed in PDOStatement::f… in pdo_stmt_verify_mode()
1228 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_LAZY can't be used with PDOStatement::f… in pdo_stmt_verify_mode()
1234 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together wit… in pdo_stmt_verify_mode()
1238 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_CLASSTYPE can only be used together wit… in pdo_stmt_verify_mode()
1242 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode"); in pdo_stmt_verify_mode()
1271 if (!pdo_stmt_verify_mode(stmt, how, 0)) { in PHP_METHOD()
1275 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()
1363 if (!do_fetch_common(stmt, PDO_FETCH_ORI_NEXT, 0, TRUE)) { in PHP_METHOD()
1368 fetch_value(stmt, return_value, col_n, NULL); in PHP_METHOD()
1391 if (!pdo_stmt_verify_mode(stmt, how, 1)) { in PHP_METHOD()
1395 old_ce = stmt->fetch.cls.ce; in PHP_METHOD()
1396 ZVAL_COPY_VALUE(&old_ctor_args, &stmt->fetch.cls.ctor_args); in PHP_METHOD()
1397 old_arg_count = stmt->fetch.cls.fci.param_count; in PHP_METHOD()
1399 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1406 stmt->fetch.cls.ce = zend_standard_class_def; in PHP_METHOD()
1410 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array"); in PHP_METHOD()
1420 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, ctor_args); /* we're not going to free these */ in PHP_METHOD()
1422 ZVAL_UNDEF(&stmt->fetch.cls.ctor_args); in PHP_METHOD()
1425 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Invalid class name (should be a string)"); in PHP_METHOD()
1429 stmt->fetch.cls.ce = zend_fetch_class(Z_STR_P(arg2), ZEND_FETCH_CLASS_AUTO); in PHP_METHOD()
1430 if (!stmt->fetch.cls.ce) { in PHP_METHOD()
1431 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not find user-specified class"); in PHP_METHOD()
1438 do_fetch_class_prepare(stmt); in PHP_METHOD()
1446 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "no fetch function specified"); in PHP_METHOD()
1451 ZVAL_COPY_VALUE(&stmt->fetch.func.function, arg2); in PHP_METHOD()
1452 if (do_fetch_func_prepare(stmt) == 0) { in PHP_METHOD()
1463 stmt->fetch.column = how & PDO_FETCH_GROUP ? -1 : 0; in PHP_METHOD()
1467 stmt->fetch.column = Z_LVAL_P(arg2); in PHP_METHOD()
1470 …pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Third parameter not allowed for PDO::FETCH_COLUMN"… in PHP_METHOD()
1477 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Extraneous additional parameters"); in PHP_METHOD()
1485 flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS; in PHP_METHOD()
1486 how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS; in PHP_METHOD()
1492 (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR) in PHP_METHOD()
1499 if (!do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)) { in PHP_METHOD()
1505 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1506 …} else if (how == PDO_FETCH_KEY_PAIR || (how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type … in PHP_METHOD()
1507 while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, return_all)); in PHP_METHOD()
1512 } while (do_fetch(stmt, 1, &data, how | flags, PDO_FETCH_ORI_NEXT, 0, 0)); in PHP_METHOD()
1516 do_fetch_opt_finish(stmt, 0); in PHP_METHOD()
1518 stmt->fetch.cls.ce = old_ce; in PHP_METHOD()
1519 ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args); in PHP_METHOD()
1520 stmt->fetch.cls.fci.param_count = old_arg_count; in PHP_METHOD()
1536 static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int is_param) /* {{… in register_bound_param() argument
1560 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in register_bound_param()
1569 if (!really_register_bound_param(¶m, stmt, is_param)) { in register_bound_param()
1603 pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based"); in PHP_METHOD()
1608 if (!really_register_bound_param(¶m, stmt, TRUE)) { in PHP_METHOD()
1624 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); in PHP_METHOD()
1633 RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 0)); in PHP_METHOD()
1643 RETURN_LONG(stmt->row_count); in PHP_METHOD()
1657 if (stmt->error_code[0] == '\0') { in PHP_METHOD()
1661 RETURN_STRING(stmt->error_code); in PHP_METHOD()
1680 add_next_index_string(return_value, stmt->error_code); in PHP_METHOD()
1682 if (stmt->dbh->methods->fetch_err) { in PHP_METHOD()
1683 stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); in PHP_METHOD()
1712 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1717 if (stmt->methods->set_attribute(stmt, attr, value)) { in PHP_METHOD()
1722 if (!stmt->methods->set_attribute) { in PHP_METHOD()
1723 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support setting attributes"); in PHP_METHOD()
1734 static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, zend_long attr) in generic_stmt_attr_get() argument
1738 RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE); in generic_stmt_attr_get()
1753 if (!stmt->methods->get_attribute) { in PHP_METHOD()
1754 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1755 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1763 switch (stmt->methods->get_attribute(stmt, attr, return_value)) { in PHP_METHOD()
1769 if (!generic_stmt_attr_get(stmt, return_value, attr)) { in PHP_METHOD()
1771 pdo_raise_impl_error(stmt->dbh, stmt, "IM001", in PHP_METHOD()
1791 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()
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()
2200 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_write() local
2205 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_write()
2213 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in dbstmt_prop_delete() local
2218 pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "property queryString is read only"); in dbstmt_prop_delete()
2235 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(object); in dbstmt_method_get() local
2237 if (!stmt->dbh) { in dbstmt_method_get()
2242 if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2243 if (!pdo_hash_methods(Z_PDO_OBJECT_P(&stmt->database_object_handle), in dbstmt_method_get()
2245 || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { in dbstmt_method_get()
2250 …if ((fbc = zend_hash_find_ptr(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT], lc_method_n… in dbstmt_method_get()
2301 PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt) in php_pdo_free_statement() argument
2303 if (stmt->bound_params) { in php_pdo_free_statement()
2304 zend_hash_destroy(stmt->bound_params); in php_pdo_free_statement()
2305 FREE_HASHTABLE(stmt->bound_params); in php_pdo_free_statement()
2306 stmt->bound_params = NULL; in php_pdo_free_statement()
2308 if (stmt->bound_param_map) { in php_pdo_free_statement()
2309 zend_hash_destroy(stmt->bound_param_map); in php_pdo_free_statement()
2310 FREE_HASHTABLE(stmt->bound_param_map); in php_pdo_free_statement()
2311 stmt->bound_param_map = NULL; in php_pdo_free_statement()
2313 if (stmt->bound_columns) { in php_pdo_free_statement()
2314 zend_hash_destroy(stmt->bound_columns); in php_pdo_free_statement()
2315 FREE_HASHTABLE(stmt->bound_columns); in php_pdo_free_statement()
2316 stmt->bound_columns = NULL; in php_pdo_free_statement()
2319 if (stmt->methods && stmt->methods->dtor) { in php_pdo_free_statement()
2320 stmt->methods->dtor(stmt); in php_pdo_free_statement()
2322 if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) { in php_pdo_free_statement()
2323 efree(stmt->active_query_string); in php_pdo_free_statement()
2325 if (stmt->query_string) { in php_pdo_free_statement()
2326 efree(stmt->query_string); in php_pdo_free_statement()
2329 if (stmt->columns) { in php_pdo_free_statement()
2331 struct pdo_column_data *cols = stmt->columns; in php_pdo_free_statement()
2333 for (i = 0; i < stmt->column_count; i++) { in php_pdo_free_statement()
2339 efree(stmt->columns); in php_pdo_free_statement()
2340 stmt->columns = NULL; in php_pdo_free_statement()
2343 if (!Z_ISUNDEF(stmt->fetch.into) && stmt->default_fetch_type == PDO_FETCH_INTO) { in php_pdo_free_statement()
2344 zval_ptr_dtor(&stmt->fetch.into); in php_pdo_free_statement()
2345 ZVAL_UNDEF(&stmt->fetch.into); in php_pdo_free_statement()
2348 do_fetch_opt_finish(stmt, 1); in php_pdo_free_statement()
2350 if (!Z_ISUNDEF(stmt->database_object_handle)) { in php_pdo_free_statement()
2351 zval_ptr_dtor(&stmt->database_object_handle); in php_pdo_free_statement()
2353 zend_object_std_dtor(&stmt->std); in php_pdo_free_statement()
2358 pdo_stmt_t *stmt = php_pdo_stmt_fetch_object(std); in pdo_dbstmt_free_storage() local
2359 php_pdo_free_statement(stmt); in pdo_dbstmt_free_storage()
2364 pdo_stmt_t *stmt; in pdo_dbstmt_new() local
2366 stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(ce)); in pdo_dbstmt_new()
2367 zend_object_std_init(&stmt->std, ce); in pdo_dbstmt_new()
2368 object_properties_init(&stmt->std, ce); in pdo_dbstmt_new()
2370 stmt->std.handlers = &pdo_dbstmt_object_handlers; in pdo_dbstmt_new()
2372 return &stmt->std; in pdo_dbstmt_new()
2428 pdo_stmt_t *stmt = Z_PDO_STMT_P(&I->iter.data); /* for PDO_HANDLE_STMT_ERR() */ in pdo_stmt_iter_move_forwards() local
2434 if (!do_fetch(stmt, TRUE, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_move_forwards()
2459 pdo_stmt_t *stmt = Z_PDO_STMT_P(object); in pdo_stmt_iter_get() local
2471 if (!do_fetch(stmt, 1, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT, in pdo_stmt_iter_get()
2492 pdo_stmt_t *stmt = row->stmt; in row_prop_read() local
2498 if (stmt) { in row_prop_read()
2500 if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count) { in row_prop_read()
2501 fetch_value(stmt, rv, Z_LVAL_P(member), NULL); in row_prop_read()
2505 if (lval >= 0 && lval < stmt->column_count) { in row_prop_read()
2506 fetch_value(stmt, rv, lval, NULL); in row_prop_read()
2512 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_read()
2513 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_read()
2514 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_read()
2515 fetch_value(stmt, rv, colno, NULL); in row_prop_read()
2520 ZVAL_OBJ(&zobj, &stmt->std); in row_prop_read()
2548 pdo_stmt_t *stmt = row->stmt; in row_prop_exists() local
2552 if (stmt) { in row_prop_exists()
2554 return Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < stmt->column_count; in row_prop_exists()
2557 return lval >=0 && lval < stmt->column_count; in row_prop_exists()
2565 for (colno = 0; colno < stmt->column_count; colno++) { in row_prop_exists()
2566 if (ZSTR_LEN(stmt->columns[colno].name) == Z_STRLEN_P(member) && in row_prop_exists()
2567 strncmp(ZSTR_VAL(stmt->columns[colno].name), Z_STRVAL_P(member), Z_STRLEN_P(member)) == 0) { in row_prop_exists()
2571 fetch_value(stmt, &val, colno, NULL); in row_prop_exists()
2601 pdo_stmt_t *stmt = row->stmt; in row_get_properties() local
2604 if (stmt == NULL) { in row_get_properties()
2608 if (!stmt->std.properties) { in row_get_properties()
2609 rebuild_object_properties(&stmt->std); in row_get_properties()
2611 for (i = 0; i < stmt->column_count; i++) { in row_get_properties()
2613 fetch_value(stmt, &val, i, NULL); in row_get_properties()
2615 zend_hash_update(stmt->std.properties, stmt->columns[i].name, &val); in row_get_properties()
2618 return stmt->std.properties; in row_get_properties()
2696 if (row->stmt) { in pdo_row_free_storage()
2697 ZVAL_UNDEF(&row->stmt->lazy_object_ref); in pdo_row_free_storage()
2698 OBJ_RELEASE(&row->stmt->std); in pdo_row_free_storage()