apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Ingram <d...@dmi.me.uk>
Subject apr_dbd_prepare() corrupts arguments on failure
Date Sun, 12 Oct 2008 17:58:29 GMT
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

Mime
View raw message