]> granicus.if.org Git - php/commitdiff
Add "ATTR_EMULATE_PREPARES" general attribute to replace the custom
authorWez Furlong <wez@php.net>
Sun, 9 Apr 2006 08:05:01 +0000 (08:05 +0000)
committerWez Furlong <wez@php.net>
Sun, 9 Apr 2006 08:05:01 +0000 (08:05 +0000)
attributes employed by mysql and postgres drivers.
No functional change.

ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h

index 458a36bcf6f5a91a8b5d10b875e65be581e44dfb..8454a8d6d84edd8a855856814c1bf76c8fbb143e 100755 (executable)
@@ -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);
index 4217e4b81f504d45c2c8b05702a2999fc0b79050..b764f6608eb2a516afcd4317f4a614d2cf5c36f2 100755 (executable)
@@ -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;
index 2b9d947a6a6d7a3cff328672c6370a66f96805d8..8444db0ace55715d09638b430d73c88f7ddc51dd 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 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