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 Dave Ingram <da...@dmi.me.uk> on 2008/08/29 18:38:49 UTC

APR DBD: Column names from query

Hi all,

First off, if this isn't the correct place to ask this then I apologise,
but it seemed the most appropriate list. If there's somewhere more
appropriate, please let me know.

I've had a quick look for some information on accessing a database via
APR, and after glancing through the header files, I still have a
question: is it possible to get the column names from the query results?

Most of the answers from a Google search were to do with the Perl DBD
system instead... maybe I'm just not looking for the right thing? I
would have guessed that searches along the lines of
> apr dbd "column names"
would have worked, but sadly they didn't give me anything useful.

I admit that I could perhaps get this information from an existing
module that uses DBD, although I'm not really sure where I should start
looking, as I don't know of any modules that would care about the actual
column names. I'm sure it shouldn't matter, but the target database
(initially) is MySQL, so I could always fall back to calling the MySQL
functions directly with the native handle given to me by DBD if I had to.

If you want some context, then the reason I want to fetch column names
is to use them as substitution patterns in a configuration file, for
example:

<SQLRepeat "SELECT baz, bar, qux FROM sometable WHERE baz='foo'">
<VirtualHost *:80>
  DocumentRoot /www/root/path/$baz
  ServerName $bar
  ServerAdmin $qux
</VirtualHost>
</SQLRepeat>

... which is a very rough-and-ready example, but hopefully illustrates
my reasons.

Thanks,


Dave

Re: APR DBD: Column names from query

Posted by Dave Ingram <da...@dmi.me.uk>.
Vincent Bray wrote:
> 2008/8/29 Dave Ingram <da...@dmi.me.uk>:
>   
>> I presume you meant <IfDefine> and <IfModule>? My basic plan at the
>> moment is essentially based upon mod_macro, with the necessary changes
>> to read from a database. I imagine that internally it works in a similar
>> way to the two <If...> sections.
>>     
> Nick's referring to <If ...> literally. Its a new directive in trunk
> that uses SSI-like parsing in the config. See r644253 et al.
>   
Aha, thanks for that, Vincent. I had no idea that something like that
has been included. I don't tend to keep up with non-releases. I think
the expression parser might be useful for my own configuration
parsing-time conditionals, but I'm not sure that runtime checks like
that really fall under the scope of this project. It could be a powerful
combination, however.

My basic idea is to avoid having to automatically generate configuration
files via a script, and just have templated sections repeating in the
configuration.

Thanks, though -- it's something I'll keep an eye on.


Dave

Re: APR DBD: Column names from query

Posted by Vincent Bray <no...@gmail.com>.
2008/8/29 Dave Ingram <da...@dmi.me.uk>:
> I presume you meant <IfDefine> and <IfModule>? My basic plan at the
> moment is essentially based upon mod_macro, with the necessary changes
> to read from a database. I imagine that internally it works in a similar
> way to the two <If...> sections.

Dave,

Nick's referring to <If ...> literally. Its a new directive in trunk
that uses SSI-like parsing in the config. See r644253 et al.

-- 
noodl

Re: APR DBD: Column names from query

Posted by Dave Ingram <da...@dmi.me.uk>.
Nick Kew wrote:
> Dave Ingram wrote:
>
>> If you're interested, I've posted a bit more about it on my blog while
>> I'm still fleshing out the idea:
>> http://www.dmi.me.uk/blog/2008/08/13/modules-for-apache-and-php/
>
> OK, why doesn't your blog accept my attempt to comment?
> Among other things, I was trying to point you to <If ...>
> configuration sections, which should be background for
> your project.

Aha! Sorry, I've recently changed domains, so the reCAPTCHA key was no
longer valid. I'll fix that in the next half hour or so. Thanks for the
heads-up!

I presume you meant <IfDefine> and <IfModule>? My basic plan at the
moment is essentially based upon mod_macro, with the necessary changes
to read from a database. I imagine that internally it works in a similar
way to the two <If...> sections.


Dave

Re: APR DBD: Column names from query

Posted by Nick Kew <ni...@webthing.com>.
Dave Ingram wrote:

> If you're interested, I've posted a bit more about it on my blog while
> I'm still fleshing out the idea:
> http://www.dmi.me.uk/blog/2008/08/13/modules-for-apache-and-php/

OK, why doesn't your blog accept my attempt to comment?
Among other things, I was trying to point you to <If ...>
configuration sections, which should be background for
your project.

-- 
Nick Kew

Re: APR DBD: Column names from query

Posted by Dave Ingram <da...@dmi.me.uk>.
Nick Kew wrote:
> Dave Ingram wrote:
>
>> First off, if this isn't the correct place to ask this then I apologise,
>> but it seemed the most appropriate list. If there's somewhere more
>> appropriate, please let me know.
>>
>> I've had a quick look for some information on accessing a database via
>> APR, and after glancing through the header files, I still have a
>> question: is it possible to get the column names from the query results?
>
> Yes, with sufficiently up-to-date versions of apr_dbd and mod_dbd.
> Hints about how it works can be found in the relevant CHANGES files.
>
> Sorry to be terse, but it would take too long to dig up URLs
> from here.
That's fine - all I really wanted was to know if it's possible, and a
nudge in the right direction -- thanks!

>> [snip - moved lower and improved]
>
> Interesting idea.  Are you familiar with mod_vhost_dbd, and even
> mod_macro, which do somewhat-related things?
Yes indeed, although I only used the VirtualHost example as it's the
most often-used. Unless I'm much mistaken, mod_vhost_dbd only allows you
to set the document root, and all other mass virtualhosting solutions
that I've seen are quite limited -- nowhere near this flexible.

Say you wanted to add some redirects to your virtual hosts too, after
the directories have been rearranged, for example... as far as I know,
no module allows you to do anything like this:

<SQLRepeat "SELECT baz, bar, qux FROM sometable WHERE baz='foo'">
<VirtualHost *:80>
  DocumentRoot /www/root/path/$baz
  ServerName $bar
  ServerAdmin $qux
  <SQLRepeat "SELECT was, now FROM redirects WHERE type='permanent' AND
servername = ?" $bar>
    RedirectPermanent "$was" "$now"
  </SQLRepeat>
</VirtualHost>
</SQLRepeat>

If you're interested, I've posted a bit more about it on my blog while
I'm still fleshing out the idea:
http://www.dmi.me.uk/blog/2008/08/13/modules-for-apache-and-php/

I've been looking at mod_macro for inspiration and to see how it does
the substitution/re-parsing, and I think I may end up borrowing a few
chunks of its code to avoid re-inventing the wheel...


Dave

Re: APR DBD: Column names from query

Posted by Nick Kew <ni...@webthing.com>.
Dave Ingram wrote:

> First off, if this isn't the correct place to ask this then I apologise,
> but it seemed the most appropriate list. If there's somewhere more
> appropriate, please let me know.
> 
> I've had a quick look for some information on accessing a database via
> APR, and after glancing through the header files, I still have a
> question: is it possible to get the column names from the query results?

Yes, with sufficiently up-to-date versions of apr_dbd and mod_dbd.
Hints about how it works can be found in the relevant CHANGES files.

Sorry to be terse, but it would take too long to dig up URLs
from here.

> <SQLRepeat "SELECT baz, bar, qux FROM sometable WHERE baz='foo'">
> <VirtualHost *:80>
>   DocumentRoot /www/root/path/$baz
>   ServerName $bar
>   ServerAdmin $qux
> </VirtualHost>
> </SQLRepeat>

Interesting idea.  Are you familiar with mod_vhost_dbd, and even
mod_macro, which do somewhat-related things?

-- 
Nick Kew