Skip to content

Commit

Permalink
Merge pull request #9 from nihen/mysql_server_prepare_reconnect
Browse files Browse the repository at this point in the history
fail mysql_server_prepare reconnect
  • Loading branch information
CaptTofu committed Aug 20, 2011
2 parents a2da3a3 + ccc9c57 commit ce03906
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mysql.xs
Expand Up @@ -325,7 +325,9 @@ do(dbh, statement, attr=Nullsv, ...)

stmt= mysql_stmt_init(imp_dbh->pmysql);

if (mysql_stmt_prepare(stmt, str_ptr, strlen(str_ptr)))
if ((mysql_stmt_prepare(stmt, str_ptr, strlen(str_ptr))) &&
(!mysql_db_reconnect(dbh) ||
(mysql_stmt_prepare(stmt, str_ptr, strlen(str_ptr)))))
{
/*
For commands that are not supported by server side prepared
Expand Down
7 changes: 6 additions & 1 deletion t/15reconnect.t
Expand Up @@ -18,7 +18,11 @@ eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
if ($@) {
plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
}
plan tests => 8;
plan tests => 8 * 2;

for my $mysql_server_prepare (0, 1) {
$dbh= DBI->connect($test_dsn . ';mysql_server_prepare=' . $mysql_server_prepare, $test_user, $test_password,
{ RaiseError => 1, PrintError => 1, AutoCommit => 0 });

ok(defined $dbh, "Connected to database");

Expand All @@ -37,3 +41,4 @@ ok($dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");
ok($dbh->{Active}, "checking for reactivated handle");

$dbh->disconnect();
}

0 comments on commit ce03906

Please sign in to comment.