httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Poeml <>
Subject Re: Where to prepare DBD statements? post_config or child_init?
Date Sun, 09 Nov 2008 15:48:52 GMT
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


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


    /* 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");
        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,
        /* 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;


Contact: (a.k.a.
         #opensuse-mirrors on
SUSE LINUX Products GmbH
Research & Development

View raw message