httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sorin Manolache <sor...@gmail.com>
Subject Re: Segfault doing SQL select
Date Tue, 01 Dec 2009 09:23:00 GMT
On Tue, Dec 1, 2009 at 09:26, Micah Yoder <micah@yoderdev.com> wrote:
> Hello,
>
> I'm new to this. Just read most of Nick Kew's book and am trying to write a
> module that is a thin-as-possible layer between an AJAX type rich client web
> app and an SQL database. I then hope to build a small CMS on top of that.
>
> Currently I'm running into a road block with a segfault every time I run the
> query. I'm using Postgres 8.4 from the Ubuntu repos and a custom-compiled
> Apache 2.2.14 with the Worker MPM.  Here is the relevant code:
>
> void sql_template(ap_dbd_t *con, request_rec *r, apr_hash_t *formdata) {
>  apr_dbd_results_t *res;


Set res to NULL before passing it.

>  apr_dbd_row_t *row;


Set row to NULL before passing it.

>  int rv;
>
>  rv = apr_dbd_select(con->driver, r->pool, con->handle, &res, "select *
from
> topics;", 0);
>  if (!rv)
>   ap_rputs("Failed to run query.\n", r);
>  while (apr_dbd_get_row(con->driver, r->pool, res, &row, 0) != -1) {
>   ap_rputs("*** Row data *** ", r);
>   ap_rputs(apr_dbd_get_entry(con->driver, row, 0), r);
>   ap_rputs(" ... ", r);
>   ap_rputs(apr_dbd_get_entry(con->driver, row, 1), r);
>  }
> }
>
> This is being called from the main handler function.
>
>  apr_hash_t *formdata;
>  ap_dbd_t *con;
>
> [...]
>
>  if (r->method_number == M_GET)
>   formdata = parse_form_from_string(r, r->args);
>
> [...]
>
>  con = ap_dbd_acquire(r);
>  if (!con) return HTTP_INTERNAL_SERVER_ERROR;
>
>  sql_template(con, r, formdata);
>
> Kind of ugly but I'm just trying to get the concepts to work.
>
> I've run it through GDB and sometimes the segfault is on apr_dbd_select line
> and sometimes it is on the apr_dbd_get_row line. The arguments passed into
> my sql_template function seem to be valid.
>
> Am I doing anything obviously wrong? Or can someone point to a simple
> handler module that does a SELECT? (mod_auth_dbd appears to use a different
> method and introduces other complexities.)
>
> Thanks,
> Micah
>
>
>



-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Mime
View raw message