I want make sure that when a database handle is created, a sql statement
is executed first thing (it turns off read locking for the session).
I'm running in a mod_perl enviroment using Apache::DBI.  Is there a
canonical way to do this?  I understand that I can run
__PACKAGE__->db_Main->do("sql statement") in my Model class, but as far
as I know, that will only get run when the code is parsed, and therefore
if the connection times out and gets reconnected, the statement will not
get run.  I tried adding this to my model class, slightly modified from
Ima::DBI

sub db_Main {
       my $class = shift;
        my $attr = $class->_add_default_attributes({});
        $class->_remember_handle('Main');
       $class->_mk_db_closure('dbi:ODBC:db_name', 'username', 'pass',
$attr);
}

sub _mk_db_closure {
        my ($class, @connection) = @_;
        my $dbh;
        return sub {
                unless ($dbh && $dbh->FETCH('Active') && $dbh->ping) {
                        $dbh = DBI->connect(@connection);
# The statement I need to run at the start of every connection
                       $dbh->do("set transaction isolation level read
uncommitted");
                }
                return $dbh;
        };
}

but I get:
Can't call method "prepare_cached" on unblessed reference
at /usr/local/lib/perl5/site_perl/5.8.6/Ima/DBI.pm line 391, <GEN2> line
3.
:  at /usr/local/lib/perl5/site_perl/5.8.6/Maypole.pm line 118
Use of uninitialized value in concatenation (.) or string
at /usr/local/lib/perl5/site_perl/5.8.6/Apache/MVC.pm line 58, <GEN2>
line 3.
Use of uninitialized value in length
at /usr/local/lib/perl5/site_perl/5.8.6/Apache/MVC.pm line 64, <GEN2>
line 3.
Use of uninitialized value in subroutine entry
at /usr/local/lib/perl5/site_perl/5.8.6/Apache/MVC.pm line 73, <GEN2>
line 3.

Is there an easy way before I go further down this path?  Ideally, I
want to be able to run this statement once per session, without losing
my connection cacheing.

Thanks





-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users

Reply via email to