DBIx::PhraseBook - provides phrasebooked database queries, allowing client code to avoid embedding sql and direct dbi calls. supports named bind parameters only if the underlying DBD driver does.
always returns uppercased key names and resultset is a structure as returned by fetchrow_hashref (see DBI documentation).
loads phrasebooks defined in a properties file, returning a hash keyed on phrasebook name.
example props file:
test.hosts.db.dsn=dbi:mysql:hostname=127.0.0.1;debug=1;port=1367;database=hosts test.hosts.db.username=testuser test.hosts.db.password=passwordstring test.hosts.db.phrasebooks.1.name=hosts test.hosts.db.phrasebooks.1.path=/fullpath/to/phrasebooks/hosts.xml test.hosts.db.phrasebooks.1.key=key1 test.hosts.db.phrasebooks.2.name=hosts test.hosts.db.phrasebooks.2.path=/fullpath/to/phrasebooks/hosts.xml test.hosts.db.phrasebooks.2.key=key1
$prefix would be test.hosts.db for this properties file.
fetch are the main methods in this class that client code will use.
both execute a query retrieved from an xml file given a key,
binding all necessary variables along the way.
fetch returns an array or single row resultset according to what the caller expects (uses
execute does not do a fetch from the statement handle and only returns execute status.
in array context, fetch will return an array containing hashrefs of all rows. in scalar context, will return one ie the first row as a hashref.
if query only has one input bind parameter,
and it is called ':id',
or query has a single '?',
then first form of each of
fetch (above) can be used.
does the same as fetch, but prints a timings report to the logger.
prepares named query and returns a statement handle - is used by
fetch and by test scripts.
not normally invoked directly by user.
returns names of all queries in phrasebook. used by test scripts.
Force use of an existing handle
Return existing handle
Switch DBMS Debugging on
Switch DBMS Debugging off
Mark Clements, February 2003
is a relatively thin wrapper around Class::Phrasebook and DBI and is quite simplistic - have probably missed a few tricks but should be flexible enough to extend as necessary without too much trouble. possibly should be implemented as a singleton.
getAllQueryNames probably belongs in the Class::Phrasebook module - it's a bit messy having xpath in this class that directly references the phrasebook xml file.