You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Peter Poeml <po...@suse.de> on 2008/11/05 16:46:59 UTC

Where to prepare DBD statements? post_config or child_init?

Hi,

I wonder where is the best place to prepare a mod_dbd statement - I'm
thinking about either the post_config or child_init hook.

So far, I prepared the statements when a configuration directive is
processed, like many other similar modules do, too. To decrease error
proneness by (me) forgetting to update the configuration when I change
my module in a way that requires a changed SQL query, I want to compile
a default query into the module. This means that no config directive for
this is needed in the config anymore (although it can optionally still
be given). Therefore, I don't have the occasion any longer to use my
config directive processing handler to prepare the statement.

So this needs to be moved to another place (which is always run, after
configuration processing). 

Therefore I was thinking about a post_config or child_init hook. I'm not
exactly sure about the difference, I know that child_init is run after
forking but before thread creation, but I am not sure which way is
appropriate to be used with mod_dbd.

Could someone who knows share their insight? 
Pointers to examples would be appreciated very much, too.

I'm using Apache 2.2.10 worker, in a multi-process and multi-threaded
configuration.

Thanks,
Peter
-- 
Contact: admin@opensuse.org (a.k.a. ftpadmin@suse.com)
         #opensuse-mirrors on freenode.net
Info: http://en.opensuse.org/Mirror_Infrastructure
 
SUSE LINUX Products GmbH
Research & Development

Re: Where to prepare DBD statements? post_config or child_init?

Posted by Peter Poeml <po...@suse.de>.
On Wed, Nov 05, 2008 at 04:46:59PM +0100, Peter Poeml wrote:
> Hi,
> 
> I wonder where is the best place to prepare a mod_dbd statement - I'm
> thinking about either the post_config or child_init hook.
> 
> So far, I prepared the statements when a configuration directive is
> processed, like many other similar modules do, too. To decrease error
> proneness by (me) forgetting to update the configuration when I change
> my module in a way that requires a changed SQL query, I want to compile
> a default query into the module. This means that no config directive for
> this is needed in the config anymore (although it can optionally still
> be given). Therefore, I don't have the occasion any longer to use my
> config directive processing handler to prepare the statement.
> 
> So this needs to be moved to another place (which is always run, after
> configuration processing). 
> 
> Therefore I was thinking about a post_config or child_init hook. I'm not
> exactly sure about the difference, I know that child_init is run after
> forking but before thread creation, but I am not sure which way is
> appropriate to be used with mod_dbd.
> 
> Could someone who knows share their insight? 
> Pointers to examples would be appreciated very much, too.
> 
> I'm using Apache 2.2.10 worker, in a multi-process and multi-threaded
> configuration.
> 
> Thanks,
> Peter

Hi,

I found an answer myself: doing this in a post_config hook works just
fine.

--------------------->

    /* make sure that mod_dbd is loaded */
    if (zrkadlo_dbd_prepare_fn == NULL) {
        zrkadlo_dbd_prepare_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_prepare);
        if (zrkadlo_dbd_prepare_fn == NULL) {
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
                         "[mod_zrkadlo] You must load mod_dbd to enable Zrkadlo functions");
        return HTTP_INTERNAL_SERVER_ERROR;
        }
        zrkadlo_dbd_acquire_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_acquire);
    }

    /* prepare DBD SQL statements */
    static unsigned int label_num = 0;
    server_rec *sp;
    for (sp = s; sp; sp = sp->next) {
        zrkadlo_server_conf *cfg = ap_get_module_config(sp->module_config,
                                                        &zrkadlo_module);
        /* make a label */
        cfg->query_prep = apr_psprintf(pconf, "zrkadlo_dbd_%d", ++label_num);
        zrkadlo_dbd_prepare_fn(sp, cfg->query, cfg->query_prep);
    }

    return OK;

<---------------------

Peter
-- 
Contact: admin@opensuse.org (a.k.a. ftpadmin@suse.com)
         #opensuse-mirrors on freenode.net
Info: http://en.opensuse.org/Mirror_Infrastructure
 
SUSE LINUX Products GmbH
Research & Development