From: Wez Furlong Date: Sun, 9 Apr 2006 08:05:01 +0000 (+0000) Subject: Add "ATTR_EMULATE_PREPARES" general attribute to replace the custom X-Git-Tag: php-5.1.3RC3~69 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=687e6ffc582291149f38cae628d24a5f426d846e;p=php Add "ATTR_EMULATE_PREPARES" general attribute to replace the custom attributes employed by mysql and postgres drivers. No functional change. --- diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 458a36bcf6..8454a8d6d8 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -1287,6 +1287,7 @@ void pdo_dbh_init(TSRMLS_D) REGISTER_PDO_CLASS_CONST_LONG("ATTR_DRIVER_NAME", (long)PDO_ATTR_DRIVER_NAME); REGISTER_PDO_CLASS_CONST_LONG("ATTR_STRINGIFY_FETCHES",(long)PDO_ATTR_STRINGIFY_FETCHES); REGISTER_PDO_CLASS_CONST_LONG("ATTR_MAX_COLUMN_LEN",(long)PDO_ATTR_MAX_COLUMN_LEN); + REGISTER_PDO_CLASS_CONST_LONG("ATTR_EMULATE_PREPARES",(long)PDO_ATTR_EMULATE_PREPARES); REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT); REGISTER_PDO_CLASS_CONST_LONG("ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 4217e4b81f..b764f6608e 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -1633,6 +1633,17 @@ fail: /* {{{ proto mixed PDOStatement::getAttribute(long attribute) Get an attribute */ + +static int generic_stmt_attr_get(pdo_stmt_t *stmt, zval *return_value, long attr) +{ + switch (attr) { + case PDO_ATTR_EMULATE_PREPARES: + RETVAL_BOOL(stmt->supports_placeholders == PDO_PLACEHOLDER_NONE); + return 1; + } + return 0; +} + static PHP_METHOD(PDOStatement, getAttribute) { long attr; @@ -1643,8 +1654,12 @@ static PHP_METHOD(PDOStatement, getAttribute) } if (!stmt->methods->get_attribute) { - pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "This driver doesn't support getting attributes" TSRMLS_CC); - RETURN_FALSE; + if (!generic_stmt_attr_get(stmt, return_value, attr)) { + pdo_raise_impl_error(stmt->dbh, stmt, "IM001", + "This driver doesn't support getting attributes" TSRMLS_CC); + RETURN_FALSE; + } + return; } PDO_STMT_CLEAR_ERR(); @@ -1654,9 +1669,13 @@ static PHP_METHOD(PDOStatement, getAttribute) RETURN_FALSE; case 0: - /* XXX: should do something better here */ - pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver doesn't support getting that attribute" TSRMLS_CC); - RETURN_FALSE; + if (!generic_stmt_attr_get(stmt, return_value, attr)) { + /* XXX: should do something better here */ + pdo_raise_impl_error(stmt->dbh, stmt, "IM001", + "driver doesn't support getting that attribute" TSRMLS_CC); + RETURN_FALSE; + } + return; default: return; diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 2b9d947a6a..8444db0ace 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC); # define FALSE 0 #endif -#define PDO_DRIVER_API 20060327 +#define PDO_DRIVER_API 20060409 enum pdo_param_type { PDO_PARAM_NULL, @@ -129,6 +129,7 @@ enum pdo_attribute_type { PDO_ATTR_DRIVER_NAME, /* name of the driver (as used in the constructor) */ PDO_ATTR_STRINGIFY_FETCHES, /* converts integer/float types to strings during fetch */ PDO_ATTR_MAX_COLUMN_LEN, /* make database calculate maximum length of data found in a column */ + PDO_ATTR_EMULATE_PREPARES, /* use query emulation rather than native */ /* this defines the start of the range for driver specific options. * Drivers should define their own attribute constants beginning with this