Bug 46827 - Execute some SQL statement after database connection has been established
Summary: Execute some SQL statement after database connection has been established
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_dbd (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2009-03-10 02:30 UTC by Marko Kevac
Modified: 2009-10-09 15:35 UTC (History)
0 users



Attachments
add DBDInitSQL parameter to mod_dbd (4.07 KB, patch)
2009-03-10 02:30 UTC, Marko Kevac
Details | Diff
add DBDInitSQL parameter to mod_dbd (5.71 KB, patch)
2009-03-13 03:19 UTC, Marko Kevac
Details | Diff
main patch (5.46 KB, patch)
2009-04-12 08:34 UTC, Marko Kevac
Details | Diff
new patch (5.44 KB, patch)
2009-04-16 10:51 UTC, Marko Kevac
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marko Kevac 2009-03-10 02:30:27 UTC
Created attachment 23365 [details]
add DBDInitSQL parameter to mod_dbd

Usually, after connection to DB has been established, user has to execute some initialization statement.

For example this one:

SET NAMES 'utf8';

Attached patch adds configuration parameter DBDInitSQL, which enables user to specify which statement(s) to execute after connection has been established.

Same like parameter for prepared statements:

DBDInitSQL "SET NAMES 'utf8'" label

This patch is part of major change to mod_dbd concerning DBDPool-s. See http://www.mail-archive.com/dev@httpd.apache.org/msg42922.html
Comment 1 Marko Kevac 2009-03-13 03:19:31 UTC
Created attachment 23379 [details]
 add DBDInitSQL parameter to mod_dbd

http://www.mail-archive.com/dev@httpd.apache.org/msg43269.html

Nick Kew proposed use of hook instead of function call. So I'v implemented that and now i am adding new patch.
Comment 2 Chris Darroch 2009-03-26 11:30:26 UTC
Comments from Ronald Park on dev@httpd.apache.org:
(http://marc.info/?l=apache-httpd-dev&m=123792143900952&w=2)

I think this is an excellent set of patches.  I had developed a similar enhancement to allow mod_dbd to connect with multiple databases at my last job but never had a chance to make it available here.  Your version is far more clever and configurable.

I did have one minor nit to pick with the implementation of the DBDInitSQL command.  A user might presume that the order of commands listed in the config file would be preserved when the commands are run.  By using a hash table, you'll likely get a random order causing problems.  For example, perhaps the user needs to first load one table then choose a subset from that first table to file another; if you run them in the reserve order, the second table will likely be empty. :(

If you choose not to change the implementation, then the documentation should make this clear.
Comment 3 Marko Kevac 2009-04-12 08:34:01 UTC
Created attachment 23482 [details]
main patch

This patch adds ability to the mod_dbd Apache module to execute any SQL statements after DB connection have been established.

Patch is against httpd trunk.

Configuration example:

        DBDriver mysql
        DBDParams host=localhost,user=root,reconnect=0
        DBDPersist On
        DBDInitSQL "USE passport"
        DBDInitSQL "SET NAMES utf8"
        DBDMin 1

Order of the DBDInitSQL statements is preserved (statements will be executed in same order they were in httpd.conf file).

Also this patch introduces optional post_connection hook, which enables any other module to hook after connection were established.
Comment 4 Marko Kevac 2009-04-16 10:51:31 UTC
Created attachment 23500 [details]
new patch

Removed DBD_DECLARE_NONSTD(void) from ap_dbd_sql_init function definition.
Comment 5 Graham Leggett 2009-10-09 15:35:37 UTC
My understanding is that this was committed to trunk, can you confirm whether this was resolved?

Can you reopen this if not.