ap / DBIx-Connector

Fast, safe DBI connection and transaction management
https://metacpan.org/release/DBIx-Connector
40 stars 14 forks source link

prepare handle & autoreconnect - question #28

Closed Perlover closed 11 years ago

Perlover commented 11 years ago

Good day!

Thanks for nice module! But i have question for future using.

Suppose i made everywhere like this:

my $sth = $conn->dbh->prepare(..);

Then by some reasons a connection was lost. Your module made auto-reconnect and as i understand after reconnect will be:

$conn->dbh != $old_dbh

Yes?

And question: can i use $sth after reconnect (auto-reconnect is transparent so this will be difficult to check this every time) or should i do prepare again? And same question for fork situations: if i made and got $sth in parent, then made fork - can i use $sth in child without new prepare?

I am interested for situations when i use $sth outside of txn, run methods. I understand if i will make sub {} with fixup method where prepare will be - it will work fine: a prepare will rerun. But for old programs i cannot remake logic to your module quickly and in my projects i use $sth outside. If i use DBD::mysql module - there i has mysql_auto_reconnect to true.

Thanks!

theory commented 11 years ago

On Feb 12, 2013, at 11:43 AM, Perlover notifications@github.com wrote:

Good day!

Thanks for nice module! But i have question for future using.

Suppose i made everywhere like this:

my $sth = $conn->dbh->prepare(..);

Then by some reasons a connection was lost. Your module made auto-reconnect and as i understand after reconnect will be:

$conn->dbh != $old_dbh

Yes?

Correct.

And question: can i use $sth after reconnect (auto-reconnect is transparent so this will be difficult to check this every time) or should i do prepare again?

You would need to prepare again. This is what makes txn() blocks so useful.

And same question for fork situations: if i made and got $sth in parent, then made fork - can i use $sth in child without new prepare?

No, you need to re-prepare.

HTH,

David