andrey                                   Fri, 18 Mar 2011 13:35:33 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=309382

Log:
new function/methods - mysqlnd_stmt_flush. Removing
code duplication

Changed paths:
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.h     2011-03-18 12:33:17 UTC (rev 
309381)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.h     2011-03-18 13:35:33 UTC (rev 
309382)
@@ -261,6 +261,7 @@
 #define        mysqlnd_stmt_free_result(stmt)          
(stmt)->m->free_result((stmt) TSRMLS_CC)
 #define        mysqlnd_stmt_close(stmt, implicit)      (stmt)->m->dtor((stmt), 
(implicit) TSRMLS_CC)
 #define        mysqlnd_stmt_reset(stmt)                        
(stmt)->m->reset((stmt) TSRMLS_CC)
+#define        mysqlnd_stmt_flush(stmt)                        
(stmt)->m->flush((stmt) TSRMLS_CC)


 #define mysqlnd_stmt_attr_get(stmt, attr, value)       
(stmt)->m->get_attribute((stmt), (attr), (value) TSRMLS_CC)

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c  2011-03-18 12:33:17 UTC (rev 
309381)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c  2011-03-18 13:35:33 UTC (rev 
309382)
@@ -628,28 +628,8 @@
                }
 #endif

-               /*
-                 If right after execute() we have to call the appropriate
-                 use_result() or store_result() and clean.
-               */
-               if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) {
-                       DBG_INF("fetching result set header");
-                       /* Do implicit use_result and then flush the result */
-                       stmt->default_rset_handler = s->m->use_result;
-                       stmt->default_rset_handler(s TSRMLS_CC);
-               }
+               s->m->flush(s TSRMLS_CC);

-               if (stmt->state > MYSQLND_STMT_WAITING_USE_OR_STORE) {
-                       DBG_INF("skipping result");
-                       /* Flush if anything is left and unbuffered set */
-                       stmt->result->m.skip_result(stmt->result TSRMLS_CC);
-               }
-
-               if (stmt->state > MYSQLND_STMT_PREPARED) {
-                       /* As the buffers have been freed, we should go back to 
PREPARED */
-                       stmt->state = MYSQLND_STMT_PREPARED;
-               }
-
                /*
                  Executed, but the user hasn't started to fetch
                  This will clean also the metadata, but after the EXECUTE call 
we will
@@ -1228,7 +1208,46 @@
                        }
                }

+               s->m->flush(s TSRMLS_CC);
+
                /*
+                 Don't free now, let the result be usable. When the stmt will 
again be
+                 executed then the result set will be cleaned, the bound 
variables will
+                 be separated before that.
+               */
+
+               int4store(cmd_buf, stmt->stmt_id);
+               if (CONN_GET_STATE(conn) == CONN_READY &&
+                       FAIL == (ret = conn->m->simple_command(conn, 
COM_STMT_RESET, cmd_buf,
+                                                                               
                  sizeof(cmd_buf), PROT_OK_PACKET,
+                                                                               
                  FALSE, TRUE TSRMLS_CC))) {
+                       stmt->error_info = conn->error_info;
+               }
+               stmt->upsert_status = conn->upsert_status;
+
+               stmt->state = MYSQLND_STMT_PREPARED;
+       }
+       DBG_INF(ret == PASS? "PASS":"FAIL");
+       DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_stmt::flush */
+static enum_func_status
+MYSQLND_METHOD(mysqlnd_stmt, flush)(MYSQLND_STMT * const s TSRMLS_DC)
+{
+       MYSQLND_STMT_DATA * stmt = s? s->data:NULL;
+       enum_func_status ret = PASS;
+
+       DBG_ENTER("mysqlnd_stmt::flush");
+       if (!stmt || !stmt->conn) {
+               DBG_RETURN(FAIL);
+       }
+       DBG_INF_FMT("stmt=%lu", stmt->stmt_id);
+
+       if (stmt->stmt_id) {
+               /*
                  If the user decided to close the statement right after 
execute()
                  We have to call the appropriate use_result() or 
store_result() and
                  clean.
@@ -1246,21 +1265,6 @@
                        }
                } while (mysqlnd_stmt_more_results(s) && 
mysqlnd_stmt_next_result(s) == PASS);

-               /*
-                 Don't free now, let the result be usable. When the stmt will 
again be
-                 executed then the result set will be cleaned, the bound 
variables will
-                 be separated before that.
-               */
-
-               int4store(cmd_buf, stmt->stmt_id);
-               if (CONN_GET_STATE(conn) == CONN_READY &&
-                       FAIL == (ret = conn->m->simple_command(conn, 
COM_STMT_RESET, cmd_buf,
-                                                                               
                  sizeof(cmd_buf), PROT_OK_PACKET,
-                                                                               
                  FALSE, TRUE TSRMLS_CC))) {
-                       stmt->error_info = conn->error_info;
-               }
-               stmt->upsert_status = conn->upsert_status;
-
                stmt->state = MYSQLND_STMT_PREPARED;
        }
        DBG_INF(ret == PASS? "PASS":"FAIL");
@@ -2335,7 +2339,8 @@
        MYSQLND_METHOD(mysqlnd_stmt, server_status),
        mysqlnd_stmt_execute_generate_request,
        mysqlnd_stmt_execute_parse_response,
-       MYSQLND_METHOD(mysqlnd_stmt, free_stmt_content)
+       MYSQLND_METHOD(mysqlnd_stmt, free_stmt_content),
+       MYSQLND_METHOD(mysqlnd_stmt, flush)
 MYSQLND_CLASS_METHODS_END;



Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h     2011-03-18 12:33:17 UTC 
(rev 309381)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h     2011-03-18 13:35:33 UTC 
(rev 309382)
@@ -641,6 +641,7 @@
 typedef enum_func_status       
(*func_mysqlnd_stmt__generate_execute_request)(MYSQLND_STMT * const s, 
zend_uchar ** request, size_t *request_len, zend_bool * free_buffer TSRMLS_DC);
 typedef enum_func_status       
(*func_mysqlnd_stmt__parse_execute_response)(MYSQLND_STMT * const s TSRMLS_DC);
 typedef void                           
(*func_mysqlnd_stmt__free_stmt_content)(MYSQLND_STMT * const s TSRMLS_DC);
+typedef enum_func_status       (*func_mysqlnd_stmt__flush)(MYSQLND_STMT * 
const stmt TSRMLS_DC);

 struct st_mysqlnd_stmt_methods
 {
@@ -694,6 +695,8 @@
        func_mysqlnd_stmt__parse_execute_response parse_execute_response;

        func_mysqlnd_stmt__free_stmt_content free_stmt_content;
+
+       func_mysqlnd_stmt__flush flush;
 };



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

Reply via email to