Gabriel Horner > Fry-Lib-CDBI-Basic-0.05 > cdbi.pl

Download:
Fry-Lib-CDBI-Basic-0.05.tar.gz

Annotate this POD

CPAN RT

Open  0
Report a bug
Source  

NAME ^

cdbi.pl - Tutorial on setting up Class::DBI with its libraries.

DESCRIPTION ^

Setting up a database connection for Class::DBI libraries is flexible and in theory should work with any databases supported by Class::DBI. I've verified the Class::DBI libraries to work with Mysql, Postgresql and Sqlite. If you have Postgresql and Class::DBI::Pg or Sqlite and Class::DBI::SQLite or Mysql then you can use &Fry::Lib::CDBI::BDBI::setdb. If not, then you can set up your connection in the script.

Set Up ^

To set up a Class::DBI connecton you need to do three things: 1. Define database accessors to be used by Class::DBI libraries. They are listed under the Global Data section of Fry::Lib::CDBI::BDBI. 2. Do the normal Class::DBI setup: defining table,columns, and calling &set_db. 3. Call &db_columns for setting up a few more database accessors.

When setting an accessor in step 1, you should be aware of the order of precedence in setting an accessor:

        option > script > library config file > library defaults > global config file

        See the Section 'Global Data' in Fry::Shell for more.

Let's override the defaults at the script level. To do this we use the global parameter in &sh_init. If you look at this script's &sh_init call, you'll see an example. It redefines the application database (db), database name (dbname), and table (tb). You can get this example working fairly easily if you have sqlite. A sample sqlite database is provided in samples/. Note that dbname is set to a file name. This is only true for sqlite since a database is identified by a filename.

Steps 2 and 3 are done automagically by &setdb. However, if your database isn't currently supported by &setdb or you have your own Class::DBI subclass you prefer, then you need to explicitly do steps two and three. The commented out section below &setdb is an example.

Currently, &set_db, &db_columns and &columns should be called in this order since &db_columns needs a working database connection to define accessor &cols (which is used by &columns).

AUTHOR ^

Me. Gabriel that is. I welcome feedback and bug reports to cldwalker AT chwhat DOT com . If you like using perl,linux,vim and databases to make your life easier (not lazier ;) check out my website at www.chwhat.com.

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.