apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r414126 - in /apr/apr-util/branches/1.2.x/dbd: apr_dbd_pgsql.c apr_dbd_sqlite3.c
Date Wed, 14 Jun 2006 06:55:07 GMT
Author: bojan
Date: Tue Jun 13 23:55:06 2006
New Revision: 414126

URL: http://svn.apache.org/viewvc?rev=414126&view=rev
Log:
Merge r413798 and r414125 from trunk to 1.2.x branch.
Original message:
Don't expect variable argument list to end with NULL
for PostgreSQL and SQLite3 DBD drivers. Count instead.

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

Modified: apr/apr-util/branches/1.2.x/dbd/apr_dbd_pgsql.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.2.x/dbd/apr_dbd_pgsql.c?rev=414126&r1=414125&r2=414126&view=diff
==============================================================================
--- apr/apr-util/branches/1.2.x/dbd/apr_dbd_pgsql.c (original)
+++ apr/apr-util/branches/1.2.x/dbd/apr_dbd_pgsql.c Tue Jun 13 23:55:06 2006
@@ -63,6 +63,7 @@
 struct apr_dbd_prepared_t {
     const char *name;
     int prepared;
+    int nargs;
 };
 
 #define dbd_pgsql_is_success(x) (((x) == PGRES_EMPTY_QUERY) \
@@ -247,7 +248,6 @@
     size_t i = 0;
     const char *args[QUERY_MAX_ARGS];
     size_t alen;
-    int nargs = 0;
     int ret;
     PGresult *res;
     char *pgquery;
@@ -256,11 +256,12 @@
     if (!*statement) {
         *statement = apr_palloc(pool, sizeof(apr_dbd_prepared_t));
     }
+    (*statement)->nargs = 0;
     /* Translate from apr_dbd to native query format */
     for (sqlptr = (char*)query; *sqlptr; ++sqlptr) {
         if (sqlptr[0] == '%') {
             if (isalpha(sqlptr[1])) {
-                ++nargs;
+                ++(*statement)->nargs;
             }
             else if (sqlptr[1] == '%') {
                 ++sqlptr;
@@ -268,8 +269,8 @@
         }
     }
     length = strlen(query) + 1;
-    if (nargs > 8) {
-        length += nargs - 8;
+    if ((*statement)->nargs > 8) {
+        length += (*statement)->nargs - 8;
     }
     pgptr = pgquery = apr_palloc(pool, length) ;
 
@@ -324,10 +325,10 @@
     length = strlen(label);
     memcpy(sqlptr, label, length);
     sqlptr += length;
-    if (nargs > 0) {
+    if ((*statement)->nargs > 0) {
         memcpy(sqlptr, " (",2);
         sqlptr += 2;
-        for (i=0; i<nargs; ++i) {
+        for (i=0; i < (*statement)->nargs; ++i) {
             alen = strlen(args[i]);
             memcpy(sqlptr, args[i], alen);
             sqlptr += alen;
@@ -399,22 +400,21 @@
                              int *nrows, apr_dbd_prepared_t *statement,
                              va_list args)
 {
-    const char *arg;
-    int nargs = 0;
-    const char *values[QUERY_MAX_ARGS];
+    const char **values;
+    int i;
 
     if (sql->trans && sql->trans->errnum) {
         return sql->trans->errnum;
     }
-    while ( arg = va_arg(args, const char*), arg ) {
-        if ( nargs >= QUERY_MAX_ARGS) {
-            va_end(args);
-            return -1;
-        }
-        values[nargs++] = apr_pstrdup(pool, arg);
+
+    values = apr_palloc(pool, sizeof(*values) * statement->nargs);
+
+    for (i = 0; i < statement->nargs; i++) {
+        values[i] = apr_pstrdup(pool, va_arg(args, const char*));
     }
-    values[nargs] = NULL;
-    return dbd_pgsql_pquery(pool, sql, nrows, statement, nargs, values);
+
+    return dbd_pgsql_pquery(pool, sql, nrows, statement,
+                            statement->nargs, values);
 }
 
 static int dbd_pgsql_pselect(apr_pool_t *pool, apr_dbd_t *sql,
@@ -500,23 +500,21 @@
                               apr_dbd_prepared_t *statement,
                               int seek, va_list args)
 {
-    const char *arg;
-    int nargs = 0;
-    const char *values[QUERY_MAX_ARGS];
+    const char **values;
+    int i;
 
     if (sql->trans && sql->trans->errnum) {
         return sql->trans->errnum;
     }
 
-    while (arg = va_arg(args, const char*), arg) {
-        if ( nargs >= QUERY_MAX_ARGS) {
-            va_end(args);
-            return -1;
-        }
-        values[nargs++] = apr_pstrdup(pool, arg);
+    values = apr_palloc(pool, sizeof(*values) * statement->nargs);
+
+    for (i = 0; i < statement->nargs; i++) {
+        values[i] = apr_pstrdup(pool, va_arg(args, const char*));
     }
+
     return dbd_pgsql_pselect(pool, sql, results, statement,
-                             seek, nargs, values) ;
+                             seek, statement->nargs, values) ;
 }
 
 static int dbd_pgsql_start_transaction(apr_pool_t *pool, apr_dbd_t *handle,

Modified: apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.2.x/dbd/apr_dbd_sqlite3.c?rev=414126&r1=414125&r2=414126&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 Jun 13 23:55:06 2006
@@ -31,8 +31,6 @@
 #define MAX_RETRY_COUNT 15
 #define MAX_RETRY_SLEEP 100000
 
-#define QUERY_MAX_ARGS 40
-
 struct apr_dbd_transaction_t {
     int errnum;
     apr_dbd_t *handle;
@@ -427,21 +425,19 @@
 static int dbd_sqlite3_pvquery(apr_pool_t *pool, apr_dbd_t *sql, int *nrows,
                                apr_dbd_prepared_t *statement, va_list args)
 {
-    const char *arg, *values[QUERY_MAX_ARGS];
-    int nargs = 0;
+    const char **values;
+    int i, nargs;
 
     if (sql->trans && sql->trans->errnum) {
         return sql->trans->errnum;
     }
 
-    while (arg = va_arg(args, const char*), arg) {
-        if (nargs >= QUERY_MAX_ARGS) {
-            va_end(args);
-            return -1;
-        }
-        values[nargs++] = apr_pstrdup(pool, arg);
+    nargs = sqlite3_bind_parameter_count(statement->stmt);
+    values = apr_palloc(pool, sizeof(*values) * nargs);
+
+    for (i = 0; i < nargs; i++) {
+        values[i] = apr_pstrdup(pool, va_arg(args, const char*));
     }
-    values[nargs] = NULL;
 
     return dbd_sqlite3_pquery(pool, sql, nrows, statement, nargs, values);
 }
@@ -573,21 +569,19 @@
                                 apr_dbd_prepared_t *statement, int seek,
                                 va_list args)
 {
-    const char *arg, *values[QUERY_MAX_ARGS];
-    int nargs = 0;
+    const char **values;
+    int i, nargs;
 
     if (sql->trans && sql->trans->errnum) {
         return sql->trans->errnum;
     }
 
-    while (arg = va_arg(args, const char*), arg) {
-        if (nargs >= QUERY_MAX_ARGS) {
-            va_end(args);
-            return -1;
-        }
-        values[nargs++] = apr_pstrdup(pool, arg);
+    nargs = sqlite3_bind_parameter_count(statement->stmt);
+    values = apr_palloc(pool, sizeof(*values) * nargs);
+
+    for (i = 0; i < nargs; i++) {
+        values[i] = apr_pstrdup(pool, va_arg(args, const char*));
     }
-    values[nargs] = NULL;
 
     return dbd_sqlite3_pselect(pool, sql, results, statement,
                                seek, nargs, values);



Mime
View raw message