[Dbix-class] Connection Questions

Brandi b.cantarel at gmail.com
Wed Oct 15 15:36:48 BST 2008


Ash,
I really don't understand -- so this is so the interaction with the DB
code takes more than 30 sec...  But what about if I am doing some
interaction with the database then my code has to run a process that
doesn't do anything with the database, then I have to do something
with the database.

if it were DBI,
I would:
my $dbh =  DBI->connect("dbi:mysql:db=database",
                        $user,$pwd) or die $DBI::errstr;

#do stuff -- interact with the database

$dbh->disconnect;

#do stuff like run a external program to calculate stuff

my $dbh =  DBI->connect("dbi:mysql:db=database",
                        $user,$pwd) or die $DBI::errstr;


#do stuff to interact with database.


How do I do that??

BTW -- this is not through the web.


On Wed, Oct 15, 2008 at 4:22 PM, Ash Berlin <ash_cpan at firemirror.com> wrote:
>
> On 15 Oct 2008, at 14:25, Brandi wrote:
>
>> 2)
>>
>> I have some computation that might cause the connection to MySQL to
>> timeout.  How can I reestablish a connection in my script, or in other
>> words disconnect and reconnect again at a later time in my script?
>>
>
> Default timeout is 30s, and having a web request sit for 30s is bad form.
> But anyway:
>
> use $schema->txn_do(sub {
>    # Code goes here
> });
>
> If the connection times out at anypoint during that, the entire thing will
> be restarted and rexecuted. I wouldn't bother with explicitly disconnecting.
>
> http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Schema.pm#txn_do
>
> -ash
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



More information about the DBIx-Class mailing list