Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 89519 invoked from network); 13 Jun 2006 01:53:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Jun 2006 01:53:15 -0000 Received: (qmail 6049 invoked by uid 500); 13 Jun 2006 01:53:14 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 6001 invoked by uid 500); 13 Jun 2006 01:53:14 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 5990 invoked by uid 99); 13 Jun 2006 01:53:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jun 2006 18:53:14 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of bojan@rexursive.com designates 203.171.74.242 as permitted sender) Received: from [203.171.74.242] (HELO beauty.rexursive.com) (203.171.74.242) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jun 2006 18:53:13 -0700 Received: from coyote.rexursive.com (coyote.rexursive.com [172.27.0.22]) by beauty.rexursive.com (Postfix) with ESMTP id C2B062567F0 for ; Tue, 13 Jun 2006 11:52:48 +1000 (EST) Subject: Re: current dbd initiatives From: Bojan Smojver To: dev@apr.apache.org In-Reply-To: <1150158301.3581.53.camel@coyote.rexursive.com> References: <20060608170430.ldbedf96ckccss0k@www.rexursive.com> <44884A0E.3000107@pearsoncmg.com> <20060609101900.l21i463xwc0g40o0@www.rexursive.com> <448A2E57.7070509@pearsoncmg.com> <1150008489.25077.33.camel@coyote.rexursive.com> <448DE1F5.7020707@pearsoncmg.com> <1150158301.3581.53.camel@coyote.rexursive.com> Content-Type: multipart/mixed; boundary="=-uOiTXnfB589sijuwei9A" Date: Tue, 13 Jun 2006 11:52:48 +1000 Message-Id: <1150163568.3581.58.camel@coyote.rexursive.com> Mime-Version: 1.0 X-Mailer: Evolution 2.6.2 (2.6.2-1.fc5.5) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --=-uOiTXnfB589sijuwei9A Content-Type: text/plain Content-Transfer-Encoding: 7bit On Tue, 2006-06-13 at 10:25 +1000, Bojan Smojver wrote: > It is easy to make that change in PostgreSQL and SQLite drivers (i.e. to > remember the number of args parsed in _prepare). People can keep passing > NULL as the last argument in pvquery/pvselect - they shouldn't get hurt. > If nobody objects, I can take it upon myself to do this. Something like the attached, maybe? -- Bojan --=-uOiTXnfB589sijuwei9A Content-Disposition: attachment; filename=apr_dbd-nargs.patch Content-Type: text/x-patch; name=apr_dbd-nargs.patch; charset=utf-8 Content-Transfer-Encoding: 7bit Index: dbd/apr_dbd_sqlite3.c =================================================================== --- dbd/apr_dbd_sqlite3.c (revision 413780) +++ dbd/apr_dbd_sqlite3.c (working copy) @@ -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; @@ -403,21 +401,18 @@ 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 = sqlite3_bind_parameter_count(statement->stmt); 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) * 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); } @@ -541,21 +536,18 @@ 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 = sqlite3_bind_parameter_count(statement->stmt); 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) * 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); Index: dbd/apr_dbd_pgsql.c =================================================================== --- dbd/apr_dbd_pgsql.c (revision 413780) +++ dbd/apr_dbd_pgsql.c (working copy) @@ -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) \ @@ -252,7 +253,6 @@ size_t i = 0; const char *args[QUERY_MAX_ARGS]; size_t alen; - int nargs = 0; int ret; PGresult *res; char *pgquery; @@ -261,11 +261,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; @@ -273,8 +274,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) ; @@ -329,10 +330,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; inargs; ++i) { alen = strlen(args[i]); memcpy(sqlptr, args[i], alen); sqlptr += alen; @@ -404,22 +405,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, @@ -505,23 +505,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, --=-uOiTXnfB589sijuwei9A--