X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBI.pm;h=86236ea168ddfdb5c04bd23632bc47ff56d1c202;hb=aa4301a7a673eb7206bb6c837a2adaaf33d9c6d9;hp=bef687162f0c97bbdbc14f40c069fb236a229838;hpb=282bf498899061be19ec7fd7ce16bf25a562fdcf;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/DBI.pm b/lib/SQL/Translator/Parser/DBI.pm index bef6871..86236ea 100644 --- a/lib/SQL/Translator/Parser/DBI.pm +++ b/lib/SQL/Translator/Parser/DBI.pm @@ -1,23 +1,5 @@ package SQL::Translator::Parser::DBI; -# ------------------------------------------------------------------- -# Copyright (C) 2002-2009 SQLFairy Authors -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ------------------------------------------------------------------- - =head1 NAME SQL::Translator::Parser::DBI - "parser" for DBI handles @@ -115,9 +97,10 @@ query Oracle directly and skip the parsing of a text file, too. =cut use strict; +use warnings; use DBI; -use vars qw($VERSION @EXPORT); -$VERSION = '1.59'; +our @EXPORT; +our $VERSION = '1.59'; use constant DRIVERS => { mysql => 'MySQL', @@ -149,6 +132,7 @@ sub parse { my $db_user = $args->{'db_user'}; my $db_password = $args->{'db_password'}; + my $dbh_is_local; unless ( $dbh ) { die 'No DSN' unless $dsn; $dbh = DBI->connect( $dsn, $db_user, $db_password, @@ -159,6 +143,7 @@ sub parse { RaiseError => 1, } ); + $dbh_is_local = 1; } die 'No database handle' unless defined $dbh; @@ -170,16 +155,17 @@ sub parse { SQL::Translator::load( $pkg ); - eval { + my $s = eval { no strict 'refs'; &{ $sub }( $tr, $dbh ) or die "No result from $pkg"; }; + my $err = $@; - $dbh->disconnect if defined $dbh; + eval { $dbh->disconnect } if (defined $dbh and $dbh_is_local); - die $@ if $@; + die $err if $err; - return 1; + return $s; } 1;