NAME
SPOPSx::Ginsu::DBI - Ginsu datasource base class.
SYNOPSIS
Assuming the files MyDBI.pm, MyBaseObject.pm, MyObject.pm and my_dbi_conf.pm from steps 1-4 of SPOPSx::Ginsu POD SYNOPSIS ...
use my_dbi_conf.pm # defines package variables for DSN, etc.
use MyObject;
MyObject->dbi_connect;
MyObject->dbi_disconnect;
$dbh = MyObject->global_datasource_handle;
MyObject->drop_table;
MyObject->create_table;
MyObject->recreate_table;
DESCRIPTION
This class inherits from SPOPS::DBI::MySQL and SPOPS::DBI and serves as a base class for your own datasource class (e.g. t/MyDBI.pm) which is in turn a base class for all of your Ginsu object classes. The methods defined here and inherited by all Ginsu objects are for creating, destroying and returning the database connection, and dropping, creating and recreating (dropping and creating again) the table corresponding to the class. All methods are class methods, but can also be called as object methods.
The database connection parameters DBI_DSN, DBI_USER, DBI_PASS, and DBI_OPT are held in package variables with the respective names in your datasource class (e.g. t/MyDBI.pm). Closures of the same names are used to return their values and a closure, set_dbi_connect_args()
is used to set their values. Another datasource class package variable, DBH, holds the database handle when connected. This is also accessed and set through closures named DBH()
and set_DBH()
, respectively. Please see t/MyDBI.pm for an example of such
METHODS
Public Class Methods
- dbi_connect
-
$rc = CLASS->dbi_connect $rc = CLASS->dbi_connect( $DBI_DSN, $DBI_USER, $DBI_PASS, $DBI_OPT )
Calls DBI->connect() and passes back the return value. Arguments to DBI->connect() are found by calling the DBI_DSN, DBI_USER, DBI_PASS and DBI_OPT methods. If values are passed in for these arguments, they are first passed to the
set_dbi_connect_args()
method. - dbi_disconnect
-
CLASS->dbi_disconnect
Calls disconnect() on the handle retured by the classes
DBH()
method. Then sets clears the database handle by passing undef to theset_DBH()
method. - global_datasource_handle
-
$dbh = CLASS->global_datasource_handle $dbh = $object->global_datasource_handle
Returns a DBI database handle. If a cached handle is not available, it calls
dbi_connect
and caches and returns the handle. Retries 10 times if necessary, before giving up. - drop_table
-
CLASS->drop_table
Drops the class's base_table from the database.
- create_table
-
CLASS->create_table
Creates the class's table based on the SQL stored in the class's $TABLE_DEF. We typically use 'CREATE TABLE IF NOT EXISTS'.
- recreate_table
-
CLASS->recreate_table
Does a
drop_table()
followed by acreate_table()
.
BUGS / TODO
Need to refactor some to make it easy to extend to other databases supported by SPOPS. Probably should use some sort of database independent keys and database specific substitution as in SPOPS::Import::DBI::TableTransform.
CHANGE HISTORY
$Log: DBI.pm,v $ Revision 1.18 2004/06/02 15:05:42 ray Now requires SPOPS-0.86
Revision 1.17 2004/04/23 18:05:30 ray Updated docs.
Revision 1.16 2004/04/23 16:50:54 ray Renamed from ESPOPS::DBI and updated docs.
COPYRIGHT
Copyright (c) 2001-2004 PSERC. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Ray Zimmerman, <rz10@cornell.edu>
SEE ALSO
SPOPS(3) SPOPS::DBI(3) SPOPS::DBI::MySQL(3) perl(1)