Skip to content

Instantly share code, notes, and snippets.

@sirhc
Created November 3, 2010 15:05
Show Gist options
  • Save sirhc/661181 to your computer and use it in GitHub Desktop.
Save sirhc/661181 to your computer and use it in GitHub Desktop.
my $dbh = DBI->connect( $dsn,
$Opt{'user'} // '',
$Opt{'password'} // '',
{ AutoCommit => 1,
PrintError => 0,
RaiseError => 0,
HandleError => sub { warn shift },
Callbacks => {
ChildCallbacks => {
execute => sub {
my ( $sth, @params ) = @_;
if ( $Opt{'verbose'} ) {
my $sql = $sth->{'Statement'};
$sql =~ s{[?]}{ $sth->{'Database'}->quote( shift @params // '' ) }ge;
say {*STDERR} $sql;
}
if ( $Opt{'dry-run'} ) {
undef $_;
}
return;
},
},
},
},
) or die DBI->errstr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment