Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local $dbh->{HandleError} = ... is not localized #114

Open
damil opened this issue Jan 27, 2024 · 0 comments
Open

local $dbh->{HandleError} = ... is not localized #114

damil opened this issue Jan 27, 2024 · 0 comments

Comments

@damil
Copy link

damil commented Jan 27, 2024

A localized installation of a HandleError handler remains active even after exiting the localizing block.
See test below (perl 5.32.0, DBI v1.643).

use strict;
use warnings;
use Test::More;
use DBI;

run_tests(SQLITE => DBI->connect('dbi:SQLite:dbname=:memory:', '', '', {RaiseError => 1}));
run_tests(CSV    => DBI->connect('dbi:CSV:', '', '', {f_ext => "foo.csv", RaiseError => 1}));


sub run_tests {
  my ($db_name, $dbh) = @_;

  eval {my $bug = $dbh->prepare("BAD SQL")};
  unlike $@, qr/FROM HandleError/, "$db_name: HandleError not installed yet";

  {
    local $dbh->{HandleError} = sub {die shift . " FROM HandleError"};
    eval {my $bug = $dbh->prepare("BAD SQL")};
    like $@, qr/FROM HandleError/, "$db_name: HandleError installled";
  }

  eval {my $bug = $dbh->prepare("BAD SQL")};
  unlike $@, qr/FROM HandleError/, "$db_name: HandleError should no longer be active";

}


done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant