From ed83c5bee55640ccd435da3c3b5d0c4ed8a8beec Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 21 May 2004 14:09:51 +0000 Subject: [PATCH] Tidy up placeholder flags --- ext/pdo/pdo_stmt.c | 41 ++++++++++++---------------------------- ext/pdo/php_pdo_driver.h | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 5ba5241d16..91a41b1ca4 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -142,7 +142,7 @@ static int describe_columns(pdo_stmt_t *stmt TSRMLS_DC) } /* update the column index on named bound parameters */ - if (stmt->dbh->placeholders_can_be_strings && stmt->bound_params) { + if (stmt->bound_params) { struct pdo_bound_param_data *param; if (SUCCESS == zend_hash_find(stmt->bound_params, stmt->columns[col].name, @@ -284,11 +284,6 @@ static PHP_METHOD(PDOStatement, execute) ¶m.name, &str_length, &num_index, 0, NULL)) { param.namelen = str_length; param.paramno = -1; - - if (!stmt->dbh->placeholders_can_be_strings) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver doesn't support named placeholders"); - RETURN_FALSE; - } } else { /* we're okay to be zero based here */ if (num_index < 0) { @@ -309,7 +304,7 @@ static PHP_METHOD(PDOStatement, execute) } } - if (stmt->dbh->emulate_prepare) { + if (!stmt->dbh->supports_placeholders) { int error_pos; /* handle the emulated parameter binding, * stmt->active_query_string holds the query with binds expanded and @@ -550,22 +545,18 @@ static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, param.paramno = -1; param.param_type = PDO_PARAM_STR; - if (stmt->dbh->placeholders_can_be_strings || !is_param) { - if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, - ZEND_NUM_ARGS() TSRMLS_CC, "sz|llz!", - ¶m.name, &name_strlen, ¶m.parameter, ¶m.param_type, - ¶m.max_value_len, - ¶m.driver_params)) { - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|llz!", ¶m.paramno, + if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, + ZEND_NUM_ARGS() TSRMLS_CC, "sz|llz!", + ¶m.name, &name_strlen, ¶m.parameter, ¶m.param_type, + ¶m.max_value_len, + ¶m.driver_params)) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|llz!", ¶m.paramno, ¶m.parameter, ¶m.param_type, ¶m.max_value_len, ¶m.driver_params)) { - return 0; - } - } + return 0; + } + } else { /* since we're hashing this, we need the null byte too */ param.namelen = name_strlen + 1; - } else if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|llz!", ¶m.paramno, - ¶m.parameter, ¶m.param_type, ¶m.max_value_len, ¶m.driver_params)) { - return 0; } if (param.paramno > 0) { @@ -583,14 +574,7 @@ static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, static PHP_METHOD(PDOStatement, bindParam) { pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!stmt->dbh->supports_placeholders) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "This driver doesn't support placeholders"); - RETURN_FALSE; - } - RETURN_BOOL(register_bound_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, TRUE)); - } /* }}} */ @@ -673,8 +657,7 @@ static zval *dbstmt_prop_read(zval *object, zval *member, int type TSRMLS_DC) if(strcmp(Z_STRVAL_P(member), "queryString") == 0) { MAKE_STD_ZVAL(return_value); ZVAL_STRINGL(return_value, stmt->query_string, stmt->query_stringlen, 1); - } - else { + } else { MAKE_STD_ZVAL(return_value); ZVAL_NULL(return_value); } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index e43a8976cd..058bee253a 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -218,6 +218,12 @@ struct pdo_stmt_methods { /* }}} */ +enum pdo_placeholder_support { + PDO_PLACEHOLDER_NONE=0, + PDO_PLACEHOLDER_NAMED=1, + PDO_PLACEHOLDER_POSITIONAL=2 +}; + /* represents a connection to a database */ struct _pdo_dbh_t { /* driver specific methods */ @@ -245,25 +251,19 @@ struct _pdo_dbh_t { unsigned alloc_own_columns:1; /* if true, the driver supports placeholders and can implement - * bindParam() for its prepared statements */ - unsigned supports_placeholders:1; - - /* if true, the driver allows named placeholders */ - unsigned placeholders_can_be_strings:1; + * bindParam() for its prepared statements, if false, PDO should + * emulate prepare and bind on its behalf */ + unsigned supports_placeholders:2; /* if true, commit or rollBack is allowed to be called */ unsigned in_txn:1; - /* if true, PDO should emulate prepare() and bound input parameters for - * the driver */ - unsigned emulate_prepare:1; - /* max length a single character can become after correct quoting */ unsigned max_escaped_char_length:3; /* the sum of the number of bits here and the bit fields preceeding should * equal 32 */ - unsigned _reserved_flags:21; + unsigned _reserved_flags:22; /* data source string used to open this handle */ const char *data_source; -- 2.50.1