From dev-return-21110-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Sun Oct 12 17:59:02 2008 Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 66489 invoked from network); 12 Oct 2008 17:59:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Oct 2008 17:59:02 -0000 Received: (qmail 18953 invoked by uid 500); 12 Oct 2008 17:59:01 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 18910 invoked by uid 500); 12 Oct 2008 17:59:01 -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 18899 invoked by uid 99); 12 Oct 2008 17:59:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Oct 2008 10:59:01 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dave@dmi.me.uk designates 213.171.205.116 as permitted sender) Received: from [213.171.205.116] (HELO scaramanga.siterage.net) (213.171.205.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Oct 2008 17:57:56 +0000 Received: from localhost (scaramanga.siterage.net [127.0.0.1]) by localhost.akadia.com (SiteRage Mail Server) with ESMTP id BF842CED4 for ; Sun, 12 Oct 2008 18:58:31 +0100 (BST) X-Spam-Score: -4.239 X-Spam-Level: Received: from scaramanga.siterage.net ([127.0.0.1]) by localhost (scaramanga.siterage.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Djv6w-xs4Msn for ; Sun, 12 Oct 2008 18:58:31 +0100 (BST) Received: from [192.168.1.65] (host217-42-76-125.range217-42.btcentralplus.com [217.42.76.125]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by scaramanga.siterage.net (SiteRage Mail Server) with ESMTPSA id BCE6ECEC2 for ; Sun, 12 Oct 2008 18:58:30 +0100 (BST) Message-ID: <48F23AC5.5020805@dmi.me.uk> Date: Sun, 12 Oct 2008 18:58:29 +0100 From: Dave Ingram User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1.17) Gecko/20080914 Lightning/0.9 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: dev@apr.apache.org Subject: apr_dbd_prepare() corrupts arguments on failure X-Enigmail-Version: 0.95.7 Content-Type: multipart/alternative; boundary="------------060407010101050802030406" X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Flag: NO X-Old-Spam-Status: No, score=-4.239 required=5 tests=[ALL_TRUSTED=-1.8, AWL=0.158, BAYES_00=-2.599, DNS_FROM_SECURITYSAGE=0.001, HTML_MESSAGE=0.001] This is a multi-part message in MIME format. --------------060407010101050802030406 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi all, I've been trying to use the APR-util DBD API (v1.3.2) while writing an Apache 2.2 module, and I've run into a problem with my code and prepared statements, which I really don't understand. I've been taking inspiration from Apache's mod_dbd module, and so I'm slightly at a loss as to why there would be a problem. The offending code fragment: fprintf(stderr, "DBINFO: %p %p %d\n", dbinfo->driver, dbinfo->handle, rv); rv = apr_dbd_prepare(dbinfo->driver, prepared_pool, dbinfo->handle, query, NULL, &stmt); if (rv) { fprintf(stderr, "DBINFO: %p %p %d\n", dbinfo->driver, dbinfo->handle, rv); const char *dberrmsg = apr_dbd_error(dbinfo->driver, dbinfo->handle, rv); ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server, "DBD: failed to prepare SQL statements: %s", (dberrmsg ? dberrmsg : "[???]")); // free the temporary sub-pool apr_pool_destroy(prepared_pool); return "Failed to prepare SQL statement"; } This all appears to work fine if the statement is valid. If there is a problem (e.g. a syntax error in the SQL) then apr_dbd_prepare() seems to destroy its driver and handle arguments, as shown by the fprintf() output: DBINFO: 0xb7b3adc0 0x819fb30 0 DBINFO: 0x81ba928 (nil) 1064 I don't quite see how it can do this though! In any case, the code I have used is virtually identical to that used by mod_dbd, which doesn't seem to have this trouble. What have I missed? Let me know if you need more context. Thanks, Dave Ingram --------------060407010101050802030406 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi all,

I've been trying to use the APR-util DBD API (v1.3.2) while writing an Apache 2.2 module, and I've run into a problem with my code and prepared statements, which I really don't understand. I've been taking inspiration from Apache's mod_dbd module, and so I'm slightly at a loss as to why there would be a problem. The offending code fragment:

fprintf(stderr, "DBINFO: %p %p %d\n", dbinfo->driver, dbinfo->handle, rv);
rv = apr_dbd_prepare(dbinfo->driver, prepared_pool, dbinfo->handle, query, NULL, &stmt);
if (rv) {
  fprintf(stderr, "DBINFO: %p %p %d\n", dbinfo->driver, dbinfo->handle, rv);
  const char *dberrmsg = apr_dbd_error(dbinfo->driver, dbinfo->handle, rv);
  ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server,
               "DBD: failed to prepare SQL statements: %s",
               (dberrmsg ? dberrmsg : "[???]"));
  // free the temporary sub-pool
  apr_pool_destroy(prepared_pool);
  return "Failed to prepare SQL statement";
}


This all appears to work fine if the statement is valid. If there is a problem (e.g. a syntax error in the SQL) then apr_dbd_prepare() seems to destroy its driver and handle arguments, as shown by the fprintf() output:

DBINFO: 0xb7b3adc0 0x819fb30 0
DBINFO: 0x81ba928 (nil) 1064

I don't quite see how it can do this though! In any case, the code I have used is virtually identical to that used by mod_dbd, which doesn't seem to have this trouble. What have I missed? Let me know if you need more context.

Thanks,


Dave Ingram
--------------060407010101050802030406--