DBIWrapper Code
Brought to you by:
pcxuser
DBIWrapper README Created by James Pattie, Xperience, Inc., 11/02/2000 http://www.pcxperience.com/ mailto:pcxuser@sf.net This module allows you to abstract working with DBI databases so that the normal program just instantiates the wrapper, specifies the database, etc. and then calls read or write on it to work with the database. The programmer will still need to know how DBI returns data, etc. but won't have to work with the setup and exection code directly. Needed modules: DBI, DBD-{Database name} Recommended modules: XML::LibXML Installation: untar the distribution: tar xvzf dbi_wrapper-{VERSION}.tar.gz perl Makefile.PL make make test su (if not root) make install touch /var/log/dbiwrapper-sql-statements.log touch /var/log/dbiwrapper-sql-statements-start.log touch /var/log/dbiwrapper-sql-statements-stop.log touch /var/log/dbiwrapper-long-running-sql.log chmod 0666 /var/log/dbiwrapper-sql-statements.log chmod 0666 /var/log/dbiwrapper-sql-statements-start.log chmod 0666 /var/log/dbiwrapper-sql-statements-stop.log chmod 0666 /var/log/dbiwrapper-long-running-sql.log To test the program (make test), you need to create a test database called testing_db. For PostgreSQL you would do: createdb testing_db psql testing_db < testing_db.pgsql If you are doing this as root, you should su to the postgres user so that the database is created owned by postgres. For MySQL: mysqladmin -p create testing_db mysql -p testing_db source testing_db.mysql Modify the test.pl script to use mysql instead of Pg. Note: As of version 0.16 XML output is now possible via the readXML method. This will return a valid XML document with the result of your SELECT statement or the error that was encountered. As of version 0.17, you can parse the XML document created by readXML via the DBIWrapper::XMLParser module. It depends on XML::LibXML. libxml2 2.4.11 File-Temp 0.12 XML::SAX 0.03 XML::LibXML 1.31 Note: As of version 0.19, you can optionally call the read, readXML, write, setError methods by just passing in the value (if only dealing with one argument otherwise you still have to pass by name. For read, readXML and write, I assume the single argument is the sql string to execute. Note: As of version 0.20, there are now helper methods to convert boolean values back and forth between what DBI is expecting and a more user readable format. 1 <=> true, 0 <=> false. Note: As of version 0.22, you can get the ID of the just inserted row by calling getID(). See the manpage for PostgreSQL specific implementation details. Sybase is also now a supported database backend. Note: As of version 0.26 all sql statements are logged into /var/log/dbiwrapper-sql-statements.log. The debian package will make sure this file exists and is world writable (mode 0666). You will need to configure log rotation of this file per your policies. Make sure the file is world writable again by touching it into existance after you rotate it and set the permissions again. You also need to deal with /var/log/dbiwrapper-long-running-sql.log. NOTE: As of version 0.26-5 the log format has been tweaked to include human readable versions of the timestamps and to include the server/dbHost and dbName values. NOTE: As of version 0.27-1 the log format has been modified again to include millisecond level granularity and uniquely identify each line so you can correlate from the new -start.log and -stop.log log files to determine durations and the full sql that was executed at that time. This requires DateTime::HiRes and Digest::SHA being available. Make sure you have created these log files and chmod 0666 them otherwise non-root users will not be able to create/append them and your scripts will die. NOTE: As of version 0.34 you can now specify 'STDOUT' for each log file and specify a custom prefix to identify the sql statements, long running sql statements and the start and stop log entries.