apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r385976 - /apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c
Date Wed, 15 Mar 2006 06:03:33 GMT
Author: rooneg
Date: Tue Mar 14 22:03:31 2006
New Revision: 385976

URL: http://svn.apache.org/viewcvs?rev=385976&view=rev
Log:
Merge r384320 from trunk into the 1.2.x branch.

Original log message:

Correct allocate space for column names in the sqlite3 dbd implementation.

Submitted by: Bojan Smojver <bojan rexursive.com>

* dbd/apr_dbd_sqlite3.c
  (apr_dbd_results_t): Add col_names member.
  (dbd_sqlite3_select): Initialize col_names and copy the names of the
   columns into it.

Modified:
    apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c

Modified: apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c?rev=385976&r1=385975&r2=385976&view=diff
==============================================================================
--- apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c (original)
+++ apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c Tue Mar 14 22:03:31 2006
@@ -65,6 +65,7 @@
     apr_dbd_row_t *next_row;
     size_t sz;
     int tuples;
+    char **col_names;
 };
 
 struct apr_dbd_prepared_t {
@@ -109,6 +110,8 @@
         (*results)->random = seek;
         (*results)->next_row = 0;
         (*results)->tuples = 0;
+        (*results)->col_names = apr_pcalloc(pool,
+                                            column_count * sizeof(char *));
         do {
             ret = sqlite3_step((*results)->stmt);
             if (ret == SQLITE_BUSY) {
@@ -132,7 +135,13 @@
                 for (i = 0; i < (*results)->sz; i++) {
                     column = apr_palloc(pool, sizeof(apr_dbd_column_t));
                     row->columns[i] = column;
-                    column->name = (char *) sqlite3_column_name((*results)->stmt, i);
+                    /* copy column name once only */
+                    if ((*results)->col_names[i] == NULL) {
+                      (*results)->col_names[i] =
+                          apr_pstrdup(pool,
+                                      sqlite3_column_name((*results)->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->value = NULL;



Mime
View raw message