wez             Sun Apr  9 08:11:32 2006 UTC

  Modified files:              (Branch: PHP_5_1)
    /php-src/ext/pdo_mysql      mysql_driver.c 
  Log:
  Fixed Bug #36602: persistent connections don't work with MySQL 5.0.3+.
  Fixed PECL Bug #6262; correctly fallback to emulated statements
  when the server version is too old.
  
  Also include code to default to using emulated prepared statements, as these
  can take advantage of the query cache.  Since it's a bit late in the release
  process to spring this on the masses, the default has not been changed.  The
  code is included so that it doesn't get lost.
  
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/pdo_mysql/mysql_driver.c?r1=1.59.2.12&r2=1.59.2.13&diff_format=u
Index: php-src/ext/pdo_mysql/mysql_driver.c
diff -u php-src/ext/pdo_mysql/mysql_driver.c:1.59.2.12 
php-src/ext/pdo_mysql/mysql_driver.c:1.59.2.13
--- php-src/ext/pdo_mysql/mysql_driver.c:1.59.2.12      Thu Mar 23 01:24:36 2006
+++ php-src/ext/pdo_mysql/mysql_driver.c        Sun Apr  9 08:11:31 2006
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysql_driver.c,v 1.59.2.12 2006/03/23 01:24:36 pajoye Exp $ */
+/* $Id: mysql_driver.c,v 1.59.2.13 2006/04/09 08:11:31 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -163,6 +163,7 @@
        char *nsql = NULL;
        int nsql_len = 0;
        int ret;
+       int server_version;
 #endif
        
        S->H = H;
@@ -173,11 +174,11 @@
                goto end;
        }
 
-       /* TODO: add runtime check to determine if the server we are talking to 
supports
-        * prepared statements; if it doesn't, we should set 
stmt->supports_placeholders
-        * to PDO_PLACEHOLDER_NONE, and have the rest of the code look at 
S->stmt to
-        * determine if we're using real prepared statements or the PDO 
emulated version */
 #if HAVE_MYSQL_STMT_PREPARE
+       server_version = mysql_get_server_version(H->server);
+       if (server_version < 40100) {
+               goto fallback;
+       }
        stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
        ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len 
TSRMLS_CC);
 
@@ -318,6 +319,7 @@
                ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = 
Z_BVAL_P(val);
                return 1;
        case PDO_MYSQL_ATTR_DIRECT_QUERY:
+       case PDO_ATTR_EMULATE_PREPARES:
                ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = 
Z_BVAL_P(val);
                return 1;
        default:
@@ -431,6 +433,17 @@
        H->einfo.errcode = 0;
        H->einfo.errmsg = NULL;
 
+       /* at the time of writing, the mysql documentation states:
+        *      
http://mysql.localhost.net.ar/doc/refman/5.0/en/query-cache-how.html
+        *      "A query also is not cached under these conditions:
+        *      ...
+        *      It was issued as a prepared statement, even if no placeholders 
were employed."
+        *
+        * We default to emulating prepared statements
+        * in order to take advantage of the query cache
+FIXME: H->emulate_prepare = 1;   a bit risky to do this so late in the RC, so 
defer it.
+       */
+
        /* allocate an environment */
        
        /* handle for the server */
@@ -449,7 +462,12 @@
                char *init_cmd = NULL, *default_file = NULL, *default_group = 
NULL;
 
                H->buffered = pdo_attr_lval(driver_options, 
PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 0 TSRMLS_CC);
-               H->emulate_prepare = pdo_attr_lval(driver_options, 
PDO_MYSQL_ATTR_DIRECT_QUERY, 0 TSRMLS_CC);
+
+               H->emulate_prepare = pdo_attr_lval(driver_options,
+                       PDO_MYSQL_ATTR_DIRECT_QUERY, H->emulate_prepare 
TSRMLS_CC);
+               H->emulate_prepare = pdo_attr_lval(driver_options, 
+                       PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare 
TSRMLS_CC);
+
                H->max_buffer_size = pdo_attr_lval(driver_options, 
PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size TSRMLS_CC);
 
                if (mysql_options(H->server, MYSQL_OPT_CONNECT_TIMEOUT, (const 
char *)&connect_timeout)) {
@@ -462,6 +480,15 @@
                        goto cleanup;
                }
 
+#ifdef MYSQL_OPT_RECONNECT
+               /* since 5.0.3, the default for this option is 0 if not 
specified.
+                * we want the old behaviour */
+               {
+                       long reconnect = 1;
+                       mysql_options(H->server, MYSQL_OPT_RECONNECT, (const 
char*)&reconnect);
+               }
+#endif
+
                init_cmd = pdo_attr_strval(driver_options, 
PDO_MYSQL_ATTR_INIT_COMMAND, NULL TSRMLS_CC);
                if (init_cmd) {
                        if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const 
char *)init_cmd)) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to