On Sun, 2007-13-05 at 18:31 +1000, Ian Holsman wrote:
> Hi Guys,
> 
> One of the 'new' features of mysql (in 5.0) is the support of multiple 
> result sets being returned to the client, and the ability to send 
> multiple statements in 1 shot by setting a flag when you open the 
> connection. Multiple result sets are also required if you intent to call 
> stored procs.
> 
> I plan on using it to pipeline SQL requests, and to call stored procs in 
> mysql.
> 
> So.. 2 questions.
> 
> Is this functionality interesting for the APR DBD library in general,

+1 usefulness from me. I'd love this implemented properly. 

It's been very useful for me with mod_dbd and another module in keeping
my big sql queries out of the apache config. Plus having to restart the
web server constantly to change the query.

In case anyone else needs something now here's my quick fix to allow
calling a MySQL stored procedure without returning an error. It only
handles the first result set. Against latest apr_dbd_mysql.c
-- 
Matthew Kent \ SA \ bravenet.com
--- apr_dbd_mysql.c.orig	2007-05-14 15:03:22.000000000 -0700
+++ apr_dbd_mysql.c	2007-05-14 15:04:53.000000000 -0700
@@ -260,6 +260,9 @@
                             apr_dbd_results_t **results,
                             const char *query, int seek)
 {
+#if MYSQL_VERSION_ID >= 50000
+    MYSQL_RES *tmp;
+#endif
     int sz;
     int ret;
     if (sql->trans && sql->trans->errnum) {
@@ -282,6 +285,16 @@
             else {
                 (*results)->res = mysql_use_result(sql->conn);
             }
+#if MYSQL_VERSION_ID >= 50000
+            /* for now just take any extra results and dump them */
+            while (!mysql_next_result(sql->conn)) {
+                /* erk, bad */
+                if (!(tmp = mysql_store_result(sql->conn))) {
+                    ret = mysql_errno(sql->conn);
+                }
+                mysql_free_result(tmp);
+            }
+#endif
             apr_pool_cleanup_register(pool, (*results)->res,
                                       free_result,apr_pool_cleanup_null);
         }
@@ -1496,8 +1509,15 @@
     }
     if (fields[6].value != NULL &&
         !strcmp(fields[6].value, "CLIENT_FOUND_ROWS")) {
-        flags |= CLIENT_FOUND_ROWS; /* only option we know */
+        flags |= CLIENT_FOUND_ROWS;
     }
+#if MYSQL_VERSION_ID >= 50000
+    /* allow calling of stored procedures, although we only handle the first result */
+    if (fields[6].value != NULL &&
+        !strcmp(fields[6].value, "CLIENT_MULTI_RESULTS")) {
+        flags |= CLIENT_MULTI_RESULTS;
+    }
+#endif
     if (fields[7].value != NULL) {
         sql->fldsz = atol(fields[7].value);
     }

Reply via email to