]> granicus.if.org Git - php/commitdiff
Experimental support for queries returning multiple rowsets under mysql 5.0.
authorWez Furlong <wez@php.net>
Sat, 2 Jul 2005 21:01:38 +0000 (21:01 +0000)
committerWez Furlong <wez@php.net>
Sat, 2 Jul 2005 21:01:38 +0000 (21:01 +0000)
Patch from Guy Harrison (guy dot a dot harrison (at) gmail dot com)

ext/pdo_mysql/config.m4
ext/pdo_mysql/mysql_driver.c
ext/pdo_mysql/mysql_statement.c

index 4ea134621ce68749451ea860eea1d5a16ce91821..c38e970f2d0f3c925c58e1530ed20e27c9eca2b5 100755 (executable)
@@ -58,7 +58,7 @@ Note that the MySQL client library is not bundled anymore!])
 
   _SAVE_LDFLAGS=$LDFLAGS
   LDFLAGS="$LDFLAGS $PDO_MYSQL_LIBS"
-  AC_CHECK_FUNCS([mysql_commit mysql_stmt_prepare])    
+  AC_CHECK_FUNCS([mysql_commit mysql_stmt_prepare mysql_next_result]) 
   LDFLAGS=$_SAVE_LDFLAGS
 
   PHP_CHECK_PDO_INCLUDES
index 8d15cf35a0db19855df6a8942e34b21fd4f8f71b..a0f7ac07c1239a28130187b5cde3359460a7b74e 100755 (executable)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
-  | Copyright (c) 1997-2004 The PHP Group                                |
+  | Copyright (c) 1997-2005 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.0 of the PHP license,       |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -305,6 +305,14 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
                { "port",   "3306",     0 },
                { "unix_socket",  PDO_MYSQL_UNIX_ADDR,  0 },
        };
+       int connect_opts = 0
+#ifdef CLIENT_MULTI_RESULTS
+               |CLIENT_MULTI_RESULTS
+#endif
+#ifdef CLIENT_MULTI_STATEMENTS
+               |CLIENT_MULTI_STATEMENTS
+#endif
+               ;
 
        php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 4);
 
@@ -337,7 +345,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
                port = atoi(vars[3].optval); 
        }
        dbname = vars[1].optval;
-       if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, 0) == NULL) {
+       if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) {
                pdo_mysql_error(dbh);
                goto cleanup;
        }
index 564418c69565c7dcd90f9f217d869e894867c203..a88eb15b8d094f0f60bafd0b0f97b7bed51c805e 100755 (executable)
@@ -93,6 +93,46 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
        return 1;
 }
 
+#if HAVE_MYSQL_NEXT_RESULT
+static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC)
+{
+       pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
+       pdo_mysql_db_handle *H = S->H;
+       my_ulonglong row_count;
+       int debug=0;
+       int ret;
+
+       /* ensure that we free any previous unfetched results */
+       if (S->result) {
+               mysql_free_result(S->result);
+               S->result = NULL;
+       }
+
+       ret = mysql_next_result(H->server);
+
+       if (ret > 0) {
+               pdo_mysql_error_stmt(stmt);
+               return 0;
+       } else if (ret < 0) {
+               /* No more results */
+               return 0;
+       } else {
+               row_count = mysql_affected_rows(H->server);
+               S->result = mysql_use_result(H->server);
+
+               if (NULL == S->result) {
+                       return 0;
+               }
+
+               stmt->row_count = row_count;
+               stmt->column_count = (int) mysql_num_fields(S->result);
+               S->fields = mysql_fetch_fields(S->result);
+               return 1;
+       }
+}
+#endif
+
+
 static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param,
                enum pdo_param_event event_type TSRMLS_DC)
 {
@@ -256,7 +296,10 @@ struct pdo_stmt_methods mysql_stmt_methods = {
        pdo_mysql_stmt_param_hook,
        NULL, /* set_attr */
        NULL, /* get_attr */
-       pdo_mysql_stmt_col_meta
+       pdo_mysql_stmt_col_meta,
+#if HAVE_MYSQL_NEXT_RESULT
+       pdo_mysql_stmt_next_rowset
+#endif
 };
 
 /*