From: Wez Furlong Date: Fri, 8 Jul 2005 04:13:00 +0000 (+0000) Subject: Add a PDO_ATTR_STRINGIFY_FETCHES attribute, which is used to convert integer or X-Git-Tag: php-5.1.0b3~107 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49c18828374846d369e1b14a77baa320da2126ee;p=php Add a PDO_ATTR_STRINGIFY_FETCHES attribute, which is used to convert integer or floating point values into strings during fetch. This is a compatibility hack for drivers that return native types rather than string representations. We use this flag in the test suite to persuade postgres tests to pass. --- diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index d48ada98b1..ddb9d871ce 100755 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -337,6 +337,7 @@ PHP_MINIT_FUNCTION(pdo) REGISTER_LONG_CONSTANT("PDO_ATTR_FETCH_TABLE_NAMES", (long)PDO_ATTR_FETCH_TABLE_NAMES, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ATTR_FETCH_CATALOG_NAMES", (long)PDO_ATTR_FETCH_CATALOG_NAMES, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ATTR_DRIVER_NAME", (long)PDO_ATTR_DRIVER_NAME, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PDO_ATTR_STRINGIFY_FETCHES",(long)PDO_ATTR_STRINGIFY_FETCHES, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ERRMODE_SILENT", (long)PDO_ERRMODE_SILENT, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PDO_ERRMODE_WARNING", (long)PDO_ERRMODE_WARNING, CONST_CS|CONST_PERSISTENT); diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index cbab10d908..be7deed2e7 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -693,6 +693,11 @@ static PHP_METHOD(PDO, setAttribute) convert_to_long(value); dbh->oracle_nulls = Z_LVAL_P(value) ? 1 : 0; RETURN_TRUE; + + case PDO_ATTR_STRINGIFY_FETCHES: + convert_to_long(value); + dbh->stringify = Z_LVAL_P(value) ? 1 : 0; + RETURN_TRUE; default: ; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index b365c96a77..4676395f0b 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -481,6 +481,15 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno TSRMLS_DC if (caller_frees && value) { efree(value); } + + if (stmt->dbh->stringify) { + switch (Z_TYPE_P(dest)) { + case IS_LONG: + case IS_DOUBLE: + convert_to_string(dest); + break; + } + } } /* }}} */ diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 4857953bde..24f885b1be 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 20050707 +#define PDO_DRIVER_API 20050708 enum pdo_param_type { PDO_PARAM_NULL, @@ -127,6 +127,7 @@ enum pdo_attribute_type { PDO_ATTR_FETCH_TABLE_NAMES, /* include table names in the column names, where available */ PDO_ATTR_FETCH_CATALOG_NAMES, /* include the catalog/db name names in the column names, where available */ 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 */ /* this defines the start of the range for driver specific options. * Drivers should define their own attribute constants beginning with this @@ -432,9 +433,12 @@ struct _pdo_dbh_t { /* when set, convert empty strings to NULL */ unsigned oracle_nulls:1; + /* when set, convert int/floats to strings */ + unsigned stringify:1; + /* the sum of the number of bits here and the bit fields preceeding should * equal 32 */ - unsigned _reserved_flags:23; + unsigned _reserved_flags:22; /* data source string used to open this handle */ const char *data_source; diff --git a/ext/pdo/tests/pdo_test.inc b/ext/pdo/tests/pdo_test.inc index 457c25050d..e941dc35ce 100644 --- a/ext/pdo/tests/pdo_test.inc +++ b/ext/pdo/tests/pdo_test.inc @@ -29,6 +29,7 @@ class PDOTest { $db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_WARNING); $db->setAttribute(PDO_ATTR_CASE, PDO_CASE_LOWER); + $db->setAttribute(PDO_ATTR_STRINGIFY_FETCHES, true); return $db; }