You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2006/05/13 06:01:55 UTC

svn commit: r406009 - /apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c

Author: bojan
Date: Fri May 12 21:01:54 2006
New Revision: 406009

URL: http://svn.apache.org/viewcvs?rev=406009&view=rev
Log:
Reset prepared statements post execution, to avoid transactions going haywire.
Remove unnecessary statement assignment in select/pselect.
Use stmt instead of (*results)->stmt throughout select/pselect.

Modified:
    apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c

Modified: apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c?rev=406009&r1=406008&r2=406009&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c Fri May 12 21:01:54 2006
@@ -114,7 +114,7 @@
         (*results)->col_names = apr_pcalloc(pool,
                                             column_count * sizeof(char *));
         do {
-            ret = sqlite3_step((*results)->stmt);
+            ret = sqlite3_step(stmt);
             if (ret == SQLITE_BUSY) {
                 if (retry_count++ > MAX_RETRY_COUNT) {
                     ret = SQLITE_ERROR;
@@ -128,7 +128,6 @@
                 apr_dbd_column_t *col;
                 row = apr_palloc(pool, sizeof(apr_dbd_row_t));
                 row->res = *results;
-                row->res->stmt = (*results)->stmt;
                 increment = sizeof(apr_dbd_column_t *);
                 length = increment * (*results)->sz;
                 row->columns = apr_palloc(pool, length);
@@ -139,19 +138,18 @@
                     /* copy column name once only */
                     if ((*results)->col_names[i] == NULL) {
                       (*results)->col_names[i] =
-                          apr_pstrdup(pool,
-                                      sqlite3_column_name((*results)->stmt, i));
+                          apr_pstrdup(pool, sqlite3_column_name(stmt, i));
                     }
                     column->name = (*results)->col_names[i];
-                    column->size = sqlite3_column_bytes((*results)->stmt, i);
-                    column->type = sqlite3_column_type((*results)->stmt, i);
+                    column->size = sqlite3_column_bytes(stmt, i);
+                    column->type = sqlite3_column_type(stmt, i);
                     column->value = NULL;
                     switch (column->type) {
                     case SQLITE_FLOAT:
                     case SQLITE_INTEGER:
                     case SQLITE_TEXT:
                         hold = NULL;
-                        hold = (char *) sqlite3_column_text((*results)->stmt, i);
+                        hold = (char *) sqlite3_column_text(stmt, i);
                         if (hold) {
                             column->value = apr_palloc(pool, column->size + 1);
                             strncpy(column->value, hold, column->size + 1);
@@ -381,6 +379,8 @@
         }
 
         *nrows = sqlite3_changes(sql->conn);
+
+        sqlite3_reset(stmt);
     }
 
     if (dbd_sqlite3_is_success(ret)) {
@@ -457,7 +457,7 @@
         (*results)->col_names = apr_pcalloc(pool,
                                             column_count * sizeof(char *));
         do {
-            ret = sqlite3_step((*results)->stmt);
+            ret = sqlite3_step(stmt);
             if (ret == SQLITE_BUSY) {
                 if (retry_count++ > MAX_RETRY_COUNT) {
                     ret = SQLITE_ERROR;
@@ -471,7 +471,6 @@
                 apr_dbd_column_t *col;
                 row = apr_palloc(pool, sizeof(apr_dbd_row_t));
                 row->res = *results;
-                row->res->stmt = (*results)->stmt;
                 increment = sizeof(apr_dbd_column_t *);
                 length = increment * (*results)->sz;
                 row->columns = apr_palloc(pool, length);
@@ -482,19 +481,18 @@
                     /* copy column name once only */
                     if ((*results)->col_names[i] == NULL) {
                       (*results)->col_names[i] =
-                          apr_pstrdup(pool,
-                                      sqlite3_column_name((*results)->stmt, i));
+                          apr_pstrdup(pool, sqlite3_column_name(stmt, i));
                     }
                     column->name = (*results)->col_names[i];
-                    column->size = sqlite3_column_bytes((*results)->stmt, i);
-                    column->type = sqlite3_column_type((*results)->stmt, i);
+                    column->size = sqlite3_column_bytes(stmt, i);
+                    column->type = sqlite3_column_type(stmt, i);
                     column->value = NULL;
                     switch (column->type) {
                     case SQLITE_FLOAT:
                     case SQLITE_INTEGER:
                     case SQLITE_TEXT:
                         hold = NULL;
-                        hold = (char *) sqlite3_column_text((*results)->stmt, i);
+                        hold = (char *) sqlite3_column_text(stmt, i);
                         if (hold) {
                             column->value = apr_palloc(pool, column->size + 1);
                             strncpy(column->value, hold, column->size + 1);
@@ -521,6 +519,8 @@
                 ret = SQLITE_OK;
             }
         } while (ret == SQLITE_ROW || ret == SQLITE_BUSY);
+
+        sqlite3_reset(stmt);
     }
     apr_dbd_mutex_unlock();