[Mod_log_sql] I need to know if using MySQL or pgsql for my score board patch and pgsql
James Cloos
cloos+outoforder-mod_log_sql at jhcloos.com
Fri May 25 10:37:54 EDT 2007
>>>>> "Edward" == Edward Rudd <urkle at outoforder.cc> writes:
Edward> The ideal solution for this is to move the SQL query into the
Edward> backend, by adding a new function to backend driver.
I don't beleive that is an option in this case, since, AIUI, mysql only
added stored procedures in the latest version, yes?
The original, mysql-specific query he used is:
,----
| insert ignore into %s (domain,vhost,month,year,count_impressions)
| values ('%s','%s','%s','%s','0')
`----
I discovered that this works on postgres, w/o having to change any of
the rest of his patch:
,----
| begin;insert into %s (domain,vhost,month,year,count_impressions)
| values ('%s','%s',%s,%s,0);commit
`----
Ie, s/insert ignore/insert/ and wrap in a transaction.
I discovered this issue using mod_log_sql as packaged in debian with the
dbi backend and the libdbd-pgsql driver for libdbi. Debian also
packages a libdbd-sqlite driver, so the final solution needs to work on
at least mysql, pgsql and sqlite.
Looking at mod_log_sql.c, it uses this to set the driver:
,----< from mod_log_sql.c set_dbparam() >
| apr_table_set(global_config.db.parms,key,val);
`----
where key is set to "driver" and val is going to be one of "mysql",
"pgsql", "sqlite".
So I presume apr_table_get(global_config.db.parms, "driver")
ought to do it.
I see that there is also globaal_config.driver which is a pointer to a
struct logsql_dbdriver. That has member const char *providername.
So I'd say that global_config.driver->providername should be the key to
use to choose the insert syntax. If that is "dbi" then you may have to
call dbi_driver_get_name() (from libdbi) to get the final driver. Or,
it may be the case that this is the right way to do it:
,----
| char *drvr;
| if (global_config.driver && global_config.driver->providername) {
| drvr = global_config.driver->providername;
| if (!strncmp(drvr, (const char *)"dbi", strlen(drvr)))
| drvr = apr_table_get(global_config.db.parms, (const char *)"driver")
| }
`----
Also, you may want to use global_config.driver->insert() instead of
using safe_sql_insert() to execute the insert. I've not investigated
the differences, so I cannot be sure, though.
-JimC
--
James Cloos <cloos at jhcloos.com> OpenPGP: 1024D/ED7DAEA6
More information about the Mod_log_sql
mailing list