in reply to Re^3: Threads and multiple DBI connections
in thread Threads and multiple DBI connections

Oh didn't realize that DBIx is direct subclass, so I can use all the methods of DBI. Anyway I changed the script accordingly (using just one $dbh DBIx Threaded object), and instead of the async methods I use regular ones, but now the problem is that script isn't able make use of more then one connection, so after one thread is created and detached, the second throws fatal error, as it is unable 'prepare' the statement and return $sth object...
my $dbh = DBIx::Threaded->connect("DBI:mysql:database=$database;host=$ +host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_li +st"); $sth->execute(); my $counter = 0; while (my @row = $sth->fetchrow_array()) { my $id = $row[0]; my $domain = $row[1]; my $created = $row[2]; next unless $row[0..3]; my $thr = threads->create(mx_lookup,$id,$domain,$created,$dbh) unl +ess $counter >= $thread_no; $thr->detach && $counter++ if $thr; } $sth->finish(); sub mx_lookup { my $id = shift; my $domain = shift; my $date_c = shift; my @date_c = split /-/, $date_c; my $delta = Delta_Days(@date_c,@date); my %emails_in; my %emails_out; if ($delta <= 30) { my @mx = mx($domain); #add multiple mxs support here my $mx_count = @mx; my $mx = $mx[0]->exchange; #find the last change for the given domain my $sth = $dbh->prepare("select max(id),domain_id,changed_from +,changed_to,date from mx_history where domain_id=?"); #this is where +the script fails $sth->execute($id); my @row = $sth->fetchrow_array(); $sth->finish(); } }
And $dbh->errstr is -->
Thread 43 terminated abnormally: Error:Unexpected db_prepare request: +must be connected to do that.
seems like that the $dbh handle isn't conected at all...

Replies are listed 'Best First'.
Re^5: Threads and multiple DBI connections
by BrowserUk (Patriarch) on Nov 01, 2010 at 22:02 UTC

    Sorry, but I don't understand what is going on either.

    I can only assume from the error message that you are using the module wrong, but reading the pod, I'd probably be trying to us it the same way.

    I think you'll have to contact the modules author.

      Yeah will have to do, thanks for the effort anyway.