X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBI.pm;h=a653657affedd83e8b15c8145f1f58444b9a1f36;hb=c092c5b324e238d963d0f5e2a92622134e2e04eb;hp=d3923dddc85582eba1d268cf830a76a347c46160;hpb=05078e2ced9a570548c6c7cfcd8f4e731561edf1;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/DBI.pm b/lib/SQL/Translator/Parser/DBI.pm index d3923dd..a653657 100644 --- a/lib/SQL/Translator/Parser/DBI.pm +++ b/lib/SQL/Translator/Parser/DBI.pm @@ -1,26 +1,5 @@ package SQL::Translator::Parser::DBI; -# ------------------------------------------------------------------- -# $Id: DBI.pm,v 1.4 2003-10-10 15:52:07 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2003 Ken Y. Clark , -# darren chamberlain -# -# 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 @@ -30,7 +9,12 @@ SQL::Translator::Parser::DBI - "parser" for DBI handles use DBI; use SQL::Translator; - my $dbh = DBI->connect(...); + my $dbh = DBI->connect('dsn', 'user', 'pass', + { + RaiseError => 1, + FetchHashKeyName => 'NAME_lc', + } + ); my $translator = SQL::Translator->new( parser => 'DBI', @@ -41,17 +25,19 @@ Or: use SQL::Translator; - my $translator = SQL::Translator->new( - parser => 'DBI', - dsn => 'dbi:mysql:FOO', - db_user => 'guest', - db_password => 'password', + my $translator = SQL::Translator->new( + parser => 'DBI', + parser_args => { + dsn => 'dbi:mysql:FOO', + db_user => 'guest', + db_password => 'password', + } ); =head1 DESCRIPTION -This parser accepts an open database handle (or the arguments to create -one) and queries the database directly for the information. +This parser accepts an open database handle (or the arguments to create +one) and queries the database directly for the information. The following are acceptable arguments: @@ -59,7 +45,9 @@ The following are acceptable arguments: =item * dbh -An open DBI database handle. +An open DBI database handle. NB: Be sure to create the database with the +"FetchHashKeyName => 'NAME_lc'" option as all the DBI parsers expect +lowercased column names. =item * dsn @@ -79,7 +67,7 @@ There is no need to specify which type of database you are querying as this is determined automatically by inspecting $dbh->{'Driver'}{'Name'}. If a parser exists for your database, it will be used automatically; if not, the code will fail automatically (and you can write the parser -and contribute it to the project!). +and contribute it to the project!). Currently parsers exist for the following databases: @@ -108,29 +96,27 @@ 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 = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/; +our @EXPORT; +our $VERSION = '1.59'; use constant DRIVERS => { mysql => 'MySQL', + odbc => 'SQLServer', + oracle => 'Oracle', + pg => 'PostgreSQL', sqlite => 'SQLite', sybase => 'Sybase', pg => 'PostgreSQL', + db2 => 'DB2', }; use Exporter; use SQL::Translator::Utils qw(debug); -use SQL::Translator::Parser::DBI::MySQL; -use SQL::Translator::Parser::DBI::SQLite; -use SQL::Translator::Parser::DBI::Sybase; -use SQL::Translator::Parser::DBI::PostgreSQL; - use base qw(Exporter); @EXPORT = qw(parse); @@ -148,13 +134,13 @@ sub parse { unless ( $dbh ) { die 'No DSN' unless $dsn; - $dbh = DBI->connect( $dsn, $db_user, $db_password, + $dbh = DBI->connect( $dsn, $db_user, $db_password, { FetchHashKeyName => 'NAME_lc', LongReadLen => 3000, LongTruncOk => 1, RaiseError => 1, - } + } ); } @@ -165,11 +151,7 @@ sub parse { my $pkg = "SQL::Translator::Parser::DBI::$driver"; my $sub = $pkg.'::parse'; - # - # I can't get this to work. I seem to have to have the "use" - # statements above. - # -# $tr->load( $pkg ); + SQL::Translator::load( $pkg ); eval { no strict 'refs'; @@ -185,7 +167,6 @@ sub parse { 1; -# ------------------------------------------------------------------- =pod =head1 AUTHOR