diff options
author | rooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68> | 2006-03-08 20:28:15 +0000 |
---|---|---|
committer | rooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68> | 2006-03-08 20:28:15 +0000 |
commit | 8b1491f514a5332d741c5b01d3afebe3e7f59cfc (patch) | |
tree | 0b430123b4bdf093a23a93ccdcfeae268f0d1c5f /dbd/apr_dbd_sqlite3.c | |
parent | 34445d8714f7a12f408b957a41cd227c6649f4a4 (diff) | |
download | libapr-util-8b1491f514a5332d741c5b01d3afebe3e7f59cfc.tar.gz |
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.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@384320 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dbd/apr_dbd_sqlite3.c')
-rw-r--r-- | dbd/apr_dbd_sqlite3.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/dbd/apr_dbd_sqlite3.c b/dbd/apr_dbd_sqlite3.c index 0f8930b5..c01891b7 100644 --- a/dbd/apr_dbd_sqlite3.c +++ b/dbd/apr_dbd_sqlite3.c @@ -64,6 +64,7 @@ struct apr_dbd_results_t { apr_dbd_row_t *next_row; size_t sz; int tuples; + char **col_names; }; struct apr_dbd_prepared_t { @@ -108,6 +109,8 @@ static int dbd_sqlite3_select(apr_pool_t * pool, apr_dbd_t * sql, apr_dbd_result (*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) { @@ -131,7 +134,13 @@ static int dbd_sqlite3_select(apr_pool_t * pool, apr_dbd_t * sql, apr_dbd_result 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; |