pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
return 0;
}
-
+
zend_hash_internal_pointer_reset(stmt->bound_param_map);
while (SUCCESS == zend_hash_get_current_data(stmt->bound_param_map, (void**)&name)) {
if (strcmp(name, param->name)) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
return 0;
}
- return 1;
+ return 1;
}
/* }}} */
ret = 0;
break;
}
-
+
zend_hash_move_forward(ht);
}
}
}
PDO_STMT_CLEAR_ERR();
-
+
if (input_params) {
struct pdo_bound_param_data param;
zval **tmp;
uint str_length;
ulong num_index;
-
- if (stmt->bound_params) {
+
+ if (stmt->bound_params) {
zend_hash_destroy(stmt->bound_params);
FREE_HASHTABLE(stmt->bound_params);
stmt->bound_params = NULL;
if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) {
/* handle the emulated parameter binding,
- * stmt->active_query_string holds the query with binds expanded and
+ * stmt->active_query_string holds the query with binds expanded and
* quoted.
*/
if (ret && !dispatch_param_event(stmt, PDO_PARAM_EVT_EXEC_POST TSRMLS_CC)) {
RETURN_FALSE;
}
-
+
RETURN_BOOL(ret);
}
if (stmt->active_query_string && stmt->active_query_string != stmt->query_string) {
} else {
ZVAL_NULL(dest);
}
-
+
if (Z_TYPE_P(dest) == IS_NULL) {
type = new_type;
}
break;
-
+
case PDO_PARAM_INT:
if (value && value_len == sizeof(long)) {
ZVAL_LONG(dest, *(long*)value);
}
}
break;
-
+
case PDO_PARAM_STR:
if (value && !(value_len == 0 && stmt->dbh->oracle_nulls == PDO_NULL_EMPTY_STRING)) {
ZVAL_STRINGL(dest, value, value_len, !caller_frees);
;
}
}
-
+
if (caller_frees && value) {
efree(value);
}
if (!stmt->columns && !pdo_stmt_describe_columns(stmt TSRMLS_CC)) {
return 0;
}
-
+
if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_POST TSRMLS_CC)) {
return 0;
}
stmt->fetch.cls.ce = ZEND_STANDARD_CLASS_DEF_PTR;
ce = ZEND_STANDARD_CLASS_DEF_PTR;
}
-
+
if (ce->constructor) {
fci->function_table = &ce->function_table;
fci->function_name = NULL;
{
char *is_callable_error = NULL;
- if (zend_fcall_info_init(callable, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) {
+ if (zend_fcall_info_init(callable, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) {
if (is_callable_error) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error TSRMLS_CC);
efree(is_callable_error);
/* Possible E_STRICT error message */
efree(is_callable_error);
}
-
+
fci->param_count = num_args; /* probably less */
fci->params = safe_emalloc(sizeof(zval**), num_args, 0);
-
+
return 1;
}
/* }}} */
} else if (flags == PDO_FETCH_GROUP && colno) {
fetch_value(stmt, return_value, 0, NULL TSRMLS_CC);
} else {
- fetch_value(stmt, return_value, colno, NULL TSRMLS_CC);
+ fetch_value(stmt, return_value, colno, NULL TSRMLS_CC);
}
if (!return_all) {
return 1;
}
}
break;
-
+
case PDO_FETCH_INTO:
if (!stmt->fetch.into) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified." TSRMLS_CC);
}
}
break;
-
+
default:
/* shouldn't happen */
return 0;
}
-
+
if (return_all && how != PDO_FETCH_KEY_PAIR) {
INIT_PZVAL(&grp_val);
if (flags == PDO_FETCH_GROUP && how == PDO_FETCH_COLUMN && stmt->fetch.column > 0) {
case PDO_FETCH_ASSOC:
add_assoc_zval(return_value, stmt->columns[i].name, val);
break;
-
+
case PDO_FETCH_KEY_PAIR:
{
zval *tmp;
}
}
break;
-
+
case PDO_FETCH_FUNC:
stmt->fetch.func.values[idx] = val;
stmt->fetch.cls.fci.params[idx] = &stmt->fetch.func.values[idx];
break;
-
+
default:
zval_ptr_dtor(&val);
pdo_raise_impl_error(stmt->dbh, stmt, "22003", "mode is out of range" TSRMLS_CC);
break;
}
}
-
+
switch (how) {
case PDO_FETCH_CLASS:
if (ce->constructor && !(flags & (PDO_FETCH_PROPS_LATE | PDO_FETCH_SERIALIZE))) {
zval_ptr_dtor(&stmt->fetch.func.values[idx]);
}
break;
-
+
default:
break;
}
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "invalid fetch mode" TSRMLS_CC);
return 0;
}
-
+
if (mode == PDO_FETCH_USE_DEFAULT) {
flags = stmt->default_fetch_type & PDO_FETCH_FLAGS;
mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS;
return 0;
}
/* fall through */
-
+
default:
if ((flags & PDO_FETCH_SERIALIZE) == PDO_FETCH_SERIALIZE) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "PDO::FETCH_SERIALIZE can only be used together with PDO::FETCH_CLASS" TSRMLS_CC);
old_ce = stmt->fetch.cls.ce;
old_ctor_args = stmt->fetch.cls.ctor_args;
old_arg_count = stmt->fetch.cls.fci.param_count;
-
+
do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
if (ctor_args) {
zend_class_entry *old_ce;
zval *old_ctor_args, *ctor_args = NULL;
int error = 0, flags, old_arg_count;
- PHP_STMT_GET_OBJ;
+ PHP_STMT_GET_OBJ;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lzz", &how, &arg2, &ctor_args)) {
RETURN_FALSE;
break;
}
break;
-
+
case PDO_FETCH_COLUMN:
switch(ZEND_NUM_ARGS()) {
case 0:
}
flags = how & PDO_FETCH_FLAGS;
-
+
if ((how & ~PDO_FETCH_FLAGS) == PDO_FETCH_USE_DEFAULT) {
flags |= stmt->default_fetch_type & PDO_FETCH_FLAGS;
how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS;
if (!error) {
PDO_STMT_CLEAR_ERR();
MAKE_STD_ZVAL(data);
- if ( (how & PDO_FETCH_GROUP) || how == PDO_FETCH_KEY_PAIR ||
+ if ( (how & PDO_FETCH_GROUP) || how == PDO_FETCH_KEY_PAIR ||
(how == PDO_FETCH_USE_DEFAULT && stmt->default_fetch_type == PDO_FETCH_KEY_PAIR)
) {
array_init(return_value);
}
FREE_ZVAL(data);
}
-
+
do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
stmt->fetch.cls.ce = old_ce;
stmt->fetch.cls.ctor_args = old_ctor_args;
stmt->fetch.cls.fci.param_count = old_arg_count;
-
+
if (error) {
PDO_HANDLE_STMT_ERR();
if (error != 2) {
"lz|llz!", ¶m.paramno, ¶m.parameter, ¶m_type, ¶m.max_value_len,
¶m.driver_params)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|llz!", ¶m.name,
- ¶m.namelen, ¶m.parameter, ¶m_type, ¶m.max_value_len,
+ ¶m.namelen, ¶m.parameter, ¶m_type, ¶m.max_value_len,
¶m.driver_params)) {
return 0;
- }
+ }
}
-
+
param.param_type = (int) param_type;
-
+
if (param.paramno > 0) {
--param.paramno; /* make it zero-based internally */
} else if (!param.name) {
PHP_STMT_GET_OBJ;
param.paramno = -1;
-
+
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"lz/|l", ¶m.paramno, ¶m.parameter, ¶m_type)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|l", ¶m.name,
}
param.param_type = (int) param_type;
-
+
if (param.paramno > 0) {
--param.paramno; /* make it zero-based internally */
} else if (!param.name) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "Columns/Parameters are 1-based" TSRMLS_CC);
RETURN_FALSE;
}
-
+
Z_ADDREF_P(param.parameter);
if (!really_register_bound_param(¶m, stmt, TRUE TSRMLS_CC)) {
if (param.parameter) {
}
return 0;
}
-
+
static PHP_METHOD(PDOStatement, getAttribute)
{
long attr;
zval ***args;
zend_class_entry **cep;
int retval;
-
+
do_fetch_opt_finish(stmt, 1 TSRMLS_CC);
switch (stmt->default_fetch_type) {
default:
;
}
-
+
stmt->default_fetch_type = PDO_FETCH_BOTH;
if (argc == 0) {
args = safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval*), 0);
retval = zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args);
-
+
if (SUCCESS == retval) {
if (Z_TYPE_PP(args[skip]) != IS_LONG) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "mode must be an integer" TSRMLS_CC);
} else {
mode = Z_LVAL_PP(args[skip]);
flags = mode & PDO_FETCH_FLAGS;
-
+
retval = pdo_stmt_verify_mode(stmt, mode, 0 TSRMLS_CC);
}
}
-
+
if (FAILURE == retval) {
PDO_STMT_CLEAR_ERR();
efree(args);
do_fetch_class_prepare(stmt TSRMLS_CC);
}
}
-
+
break;
case PDO_FETCH_INTO:
} else {
retval = SUCCESS;
}
-
+
if (SUCCESS == retval) {
#ifdef ilia_0 /* we'll only need this when we have persistent statements, if ever */
if (stmt->dbh->is_persistent) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP might crash if you don't call $stmt->setFetchMode() to reset to defaults on this persistent statement. This will be fixed in a later release");
}
-#endif
+#endif
MAKE_STD_ZVAL(stmt->fetch.into);
Z_TYPE_P(stmt->fetch.into) = IS_OBJECT;
Z_OBJ_HT_P(stmt->fetch.into) = Z_OBJ_HT_PP(args[skip+1]);
zend_objects_store_add_ref(stmt->fetch.into TSRMLS_CC);
}
-
+
break;
-
+
default:
pdo_raise_impl_error(stmt->dbh, stmt, "22003", "Invalid fetch mode specified" TSRMLS_CC);
}
PDO_STMT_CLEAR_ERR();
efree(args);
-
+
return retval;
}
-
+
static PHP_METHOD(PDOStatement, setFetchMode)
{
PHP_STMT_GET_OBJ;
if (stmt->columns) {
int i;
struct pdo_column_data *cols = stmt->columns;
-
+
for (i = 0; i < stmt->column_count; i++) {
efree(cols[i].name);
}
}
PDO_STMT_CLEAR_ERR();
-
+
if (!pdo_stmt_do_next_rowset(stmt TSRMLS_CC)) {
PDO_HANDLE_STMT_ERR();
RETURN_FALSE;
if (!pdo_stmt_do_next_rowset(stmt TSRMLS_CC)) {
break;
}
-
+
} while (1);
stmt->executed = 0;
RETURN_TRUE;
if (out == NULL) {
RETURN_FALSE;
}
-
+
php_stream_printf(out TSRMLS_CC, "SQL: [%d] %.*s\n",
stmt->query_stringlen,
stmt->query_stringlen, stmt->query_string);
php_stream_printf(out TSRMLS_CC, "Params: %d\n",
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0);
-
+
if (stmt->bound_params) {
zend_hash_internal_pointer_reset_ex(stmt->bound_params, &pos);
while (SUCCESS == zend_hash_get_current_data_ex(stmt->bound_params,
param->paramno, param->namelen, param->namelen, param->name ? param->name : "",
param->is_param,
param->param_type);
-
+
zend_hash_move_forward_ex(stmt->bound_params, &pos);
}
}
}
static union _zend_function *dbstmt_method_get(
-#if PHP_API_VERSION >= 20041225
zval **object_pp,
-#else
- zval *object,
-#endif
char *method_name, int method_len, const zend_literal *key TSRMLS_DC)
{
zend_function *fbc = NULL;
char *lc_method_name;
-#if PHP_API_VERSION >= 20041225
zval *object = *object_pp;
-#endif
+ zend_function *fbc_fallback = NULL;
lc_method_name = emalloc(method_len + 1);
zend_str_tolower_copy(lc_method_name, method_name, method_len);
- if (zend_hash_find(&Z_OBJCE_P(object)->function_table, lc_method_name,
+ if (zend_hash_find(&Z_OBJCE_P(object)->function_table, lc_method_name,
method_len+1, (void**)&fbc) == FAILURE) {
+
+ /* Prepare fallback by running standard method for functions.
+ * If the function does not find a method to instanciate it will return this fallback method. */
+ fbc_fallback = std_object_handlers.get_method(object_pp, method_name, method_len, key TSRMLS_CC);
+
pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(object TSRMLS_CC);
/* instance not created by PDO object */
if (!stmt->dbh) {
+ fbc = fbc_fallback;
goto out;
}
/* not a pre-defined method, nor a user-defined method; check
* the driver specific methods */
if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) {
- if (!pdo_hash_methods(stmt->dbh,
+ if (!pdo_hash_methods(stmt->dbh,
PDO_DBH_DRIVER_METHOD_KIND_STMT TSRMLS_CC)
|| !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) {
+
+ fbc = fbc_fallback;
goto out;
}
}
if (zend_hash_find(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT],
lc_method_name, method_len+1, (void**)&fbc) == FAILURE) {
- fbc = NULL;
+
+ fbc = fbc_fallback;
goto out;
}
/* got it */
}
-
+
out:
efree(lc_method_name);
return fbc;
stmt->refcount = 1;
old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC);
-
+
retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC);
retval.handlers = Z_OBJ_HT_P(zobject);
zend_objects_clone_members((zend_object *)stmt, retval, (zend_object *)old_stmt, handle TSRMLS_CC);
-
+
zend_objects_store_add_ref(&old_stmt->database_object_handle TSRMLS_CC);
stmt->database_object_handle = old_stmt->database_object_handle;
-
+
return retval;
}
pdo_dbstmt_ce = zend_register_internal_class(&ce TSRMLS_CC);
pdo_dbstmt_ce->get_iterator = pdo_stmt_iter_get;
pdo_dbstmt_ce->create_object = pdo_dbstmt_new;
- zend_class_implements(pdo_dbstmt_ce TSRMLS_CC, 1, zend_ce_traversable);
+ zend_class_implements(pdo_dbstmt_ce TSRMLS_CC, 1, zend_ce_traversable);
zend_declare_property_null(pdo_dbstmt_ce, "queryString", sizeof("queryString")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
memcpy(&pdo_dbstmt_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
FREE_ZVAL(stmt->fetch.into);
stmt->fetch.into = NULL;
}
-
+
do_fetch_opt_finish(stmt, 1 TSRMLS_CC);
zend_objects_store_del_ref(&stmt->database_object_handle TSRMLS_CC);
if (--I->stmt->refcount == 0) {
free_statement(I->stmt TSRMLS_CC);
}
-
+
if (I->fetch_ahead) {
zval_ptr_dtor(&I->fetch_ahead);
}
Z_SET_REFCOUNT_P(return_value, 0);
Z_UNSET_ISREF_P(return_value);
-
+
return return_value;
}
if (stmt == NULL) {
return NULL;
}
-
+
if (!stmt->std.properties) {
rebuild_object_properties(&stmt->std);
}
}
static union _zend_function *row_method_get(
-#if PHP_API_VERSION >= 20041225
zval **object_pp,
-#else
- zval *object,
-#endif
char *method_name, int method_len, const zend_literal *key TSRMLS_DC)
{
zend_function *fbc;
efree(lc_method_name);
return NULL;
}
-
+
efree(lc_method_name);
return fbc;
}
{
if (stmt) {
ZVAL_NULL(&stmt->lazy_object_ref);
-
+
if (--stmt->refcount == 0) {
free_statement(stmt TSRMLS_CC);
}