]> granicus.if.org Git - php/commitdiff
Allow drivers to select bind emulation on a per statement basis
authorWez Furlong <wez@php.net>
Tue, 18 Jan 2005 04:58:50 +0000 (04:58 +0000)
committerWez Furlong <wez@php.net>
Tue, 18 Jan 2005 04:58:50 +0000 (04:58 +0000)
ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h
ext/pdo_dblib/dblib_driver.c
ext/pdo_firebird/firebird_driver.c
ext/pdo_mysql/mysql_driver.c
ext/pdo_oci/oci_driver.c
ext/pdo_odbc/odbc_driver.c
ext/pdo_pgsql/pgsql_driver.c
ext/pdo_sqlite/sqlite_driver.c

index 67c11f47554d72e7a68b98edd4f5e83525bd204d..a16b5c2365a300553e397a941bb1afd00d07e80b 100755 (executable)
@@ -315,7 +315,8 @@ static PHP_METHOD(PDOStatement, execute)
                }
        }
 
-       if (!stmt->dbh->supports_placeholders) {
+       /* TODO: handle the non-native types too... doh. */
+       if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) {
                int error_pos;
                /* handle the emulated parameter binding,
          * stmt->active_query_string holds the query with binds expanded and 
index cefa08ee60d6c51891f248b641093931a7773ad8..1560a3268c9c0c3b6c181d1715ad875151502c27 100755 (executable)
@@ -35,7 +35,7 @@ struct pdo_bound_param_data;
 # define FALSE 0
 #endif
 
-#define PDO_DRIVER_API 20050111
+#define PDO_DRIVER_API 20050117
 
 enum pdo_param_type {
        PDO_PARAM_NULL,
@@ -326,6 +326,12 @@ typedef int (*pdo_stmt_get_attr_func)(pdo_stmt_t *stmt, long attr, zval *val TSR
  */
 typedef int (*pdo_stmt_get_column_meta_func)(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC);
 
+/* advances the statement to the next rowset of the batch.
+ * If it returns 1, PDO will tear down its idea of columns
+ * and meta data.  If it returns 0, PDO will indicate an error
+ * to the caller. */
+typedef int (*pdo_stmt_next_rowset_func)(pdo_stmt_t *stmt TSRMLS_DC);
+
 struct pdo_stmt_methods {
        pdo_stmt_dtor_func                      dtor;
        pdo_stmt_execute_func           executer;
@@ -336,6 +342,7 @@ struct pdo_stmt_methods {
        pdo_stmt_set_attr_func          set_attribute;
        pdo_stmt_get_attr_func          get_attribute;
        pdo_stmt_get_column_meta_func get_column_meta;
+       pdo_stmt_next_rowset_func               next_rowset;
 };
 
 /* }}} */
@@ -382,11 +389,6 @@ struct _pdo_dbh_t {
         * the columns that are returned */
        unsigned alloc_own_columns:1;
 
-       /* if true, the driver supports placeholders and can implement
-        * 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;
 
@@ -398,7 +400,7 @@ struct _pdo_dbh_t {
 
        /* the sum of the number of bits here and the bit fields preceeding should
         * equal 32 */
-       unsigned _reserved_flags:21;
+       unsigned _reserved_flags:23;
 
        /* data source string used to open this handle */
        const char *data_source;
@@ -456,7 +458,12 @@ struct _pdo_stmt_t {
        /* if true, we've already successfully executed this statement at least
         * once */
        unsigned executed:1;
-       unsigned _reserved:31;
+       /* if true, the statement supports placeholders and can implement
+        * bindParam() for its prepared statements, if false, PDO should
+        * emulate prepare and bind on its behalf */
+       unsigned supports_placeholders:2;
+
+       unsigned _reserved:29;
 
        /* the number of columns in the result set; not valid until after
         * the statement has been executed at least once.  In some cases, might
index 5ec37948761d0a280cee37725e072e8a6f27f601..2bb40ce88f02569c6f3a7a42980e68ba91a41dc0 100644 (file)
@@ -91,6 +91,7 @@ static int dblib_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
        S->H = H;
        stmt->driver_data = S;
        stmt->methods = &dblib_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
        S->err.sqlstate = stmt->error_code;
 
        return 1;
@@ -220,7 +221,6 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
        }
 
        ret = 1;
-       dbh->supports_placeholders = 0;
        dbh->max_escaped_char_length = 2;
        dbh->alloc_own_columns = 1;
 
index ccc8550f743846157a39eb34adcac525fe5dd763..3dce6aea84b6c2278a99339c9887c4c897048d3a 100644 (file)
@@ -182,6 +182,7 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_le
        
                stmt->driver_data = S;
                stmt->methods = &firebird_stmt_methods;
+               stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
        
                return 1;
 
@@ -626,7 +627,6 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRM
                }
                
                dbh->methods = &firebird_methods;
-               dbh->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
                dbh->native_case = PDO_CASE_UPPER;
                dbh->alloc_own_columns = 1;
 
index f0f0da3398104d81f87628fbad2aa56840835946..5f7b573b7be716042ae9d4647b909da2640958e4 100755 (executable)
@@ -143,6 +143,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
        S->H = H;
        stmt->driver_data = S;
        stmt->methods = &mysql_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
        
        return 1;
 }
@@ -287,7 +288,6 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
        H->attached = 1;
 
        dbh->alloc_own_columns = 1;
-       dbh->supports_placeholders = 0;
        dbh->max_escaped_char_length = 2;
        dbh->methods = &mysql_methods;
 
index 01a79c1699bf17d8e9545367b749cc201a0979ec..1e17ae7511dc61bf7b245fd30f972b36b415cad0 100755 (executable)
@@ -240,6 +240,7 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pd
 
        stmt->driver_data = S;
        stmt->methods = &oci_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_NAMED;
        
        return 1;
 }
@@ -472,7 +473,6 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC
        
        dbh->methods = &oci_methods;
        dbh->alloc_own_columns = 1;
-       dbh->supports_placeholders = PDO_PLACEHOLDER_NAMED;
        dbh->native_case = PDO_CASE_UPPER;
 
        ret = 1;
index 889067f37d6df28c25987e56fa54b05947502e25..cdd55223f19b58409f50c7ef2c54b31b6a4fd54b 100755 (executable)
@@ -171,6 +171,7 @@ static int odbc_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, p
        
        stmt->driver_data = S;
        stmt->methods = &odbc_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
        
        return 1;
 }
@@ -357,7 +358,6 @@ static int pdo_odbc_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_D
 
        dbh->methods = &odbc_methods;
        dbh->alloc_own_columns = 1;
-       dbh->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
        
        return 1;
 }
index e60fbc1f87ed189b8927da202fa36902f80356a5..21c3be737596468f264a9fd98091cbcf99a25344 100644 (file)
@@ -130,6 +130,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
        S->H = H;
        stmt->driver_data = S;
        stmt->methods = &pgsql_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
 
        scrollable = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR,
                PDO_CURSOR_FWDONLY TSRMLS_CC) == PDO_CURSOR_SCROLL;
@@ -375,7 +376,6 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
 
        dbh->methods = &pgsql_methods;
        dbh->alloc_own_columns = 1;
-       dbh->supports_placeholders = PDO_PLACEHOLDER_NONE;
        dbh->max_escaped_char_length = 2;
 
        ret = 1;
index 391132e6190ff6ce1d590c41af71d3b954d0fdb8..845acc0856bb3fa0731916eaa09cd8ecd3d87c99 100644 (file)
@@ -122,6 +122,7 @@ static int sqlite_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
        S->H = H;
        stmt->driver_data = S;
        stmt->methods = &sqlite_stmt_methods;
+       stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
 
        if (PDO_CURSOR_FWDONLY != pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY TSRMLS_CC)) {
                H->einfo.errcode = SQLITE_ERROR;
@@ -356,7 +357,6 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS
        sqlite3_busy_timeout(H->db, timeout * 1000);
 
        dbh->alloc_own_columns = 1;
-       dbh->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
        dbh->max_escaped_char_length = 2;
 
        ret = 1;