On Sat, 2005-09-03 at 17:59 -0700, Ron McClain wrote:
> 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).

This is a lot easier to do in your MySQL configuration file.

> 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.

That's right.

> 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);
> }

Doesn't look like you're changing anything there.  Just leave that out.

> 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;
>         };
> }

This looks reasonable to me.  Does it work without the line that sets
the transaction level?

- Perrin



-------------------------------------------------------
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