]> granicus.if.org Git - php/commitdiff
Add a PDO_ATTR_STRINGIFY_FETCHES attribute, which is used to convert integer or
authorWez Furlong <wez@php.net>
Fri, 8 Jul 2005 04:13:00 +0000 (04:13 +0000)
committerWez Furlong <wez@php.net>
Fri, 8 Jul 2005 04:13:00 +0000 (04:13 +0000)
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.

ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h
ext/pdo/tests/pdo_test.inc

index d48ada98b1479b01a2964846b29d02462880b8a5..ddb9d871ce5dbf3f41a58e556bc8f1153c4d7547 100755 (executable)
@@ -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);
index cbab10d908fb7b7c5ca593dc3ca129d1d4aa0182..be7deed2e792f813c2c9597be356b8f6c059d5b5 100755 (executable)
@@ -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:
                        ;
index b365c96a77162169b7e22fdce09a88a6ac2836e4..4676395f0b4cb61e98d16199e750c084c07856be 100755 (executable)
@@ -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;
+               }
+       }
 }
 /* }}} */
 
index 4857953bdef5e21ef6306e1487c49ee455ba678c..24f885b1bebb1bb920fc4e725e5bcf1655cddd56 100755 (executable)
@@ -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;
index 457c25050dcd0d0d0ed3567b88a89aa89bb47bbb..e941dc35cedaab269f525d466e6958dcd9da5f47 100644 (file)
@@ -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;
        }