From: Ben Faga Date: Thu, 17 Nov 2005 21:55:41 +0000 (+0000) Subject: Applied changes submitted by Paul Makepeace . X-Git-Tag: v0.11008~477 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4330d04eb774b2c3928f2a04b76c24485b2629bc;p=dbsrgits%2FSQL-Translator.git Applied changes submitted by Paul Makepeace . His notes: I have added the --use-same-auth switch to provide the producers with the same DSN/user/password as the parser gets. Since these options sort of existed already for the Dumper producer so I renamed them to more generic --producer-X; now they all have them. I also added a "--package My::Class::DBI" option for specifying the base class. One thing I wasn't quite sure on was that this base class is being stripped out - confused me at first but it seems to have been taken out in CVS v the version that's on CPAN -- maybe something in the works? Anyway, I put it back just for now as I needed it for my current project :-) (Wasn't particularly excited by either of those switch names; feel free to come up with something better...) E.g., perl -Mlib=blib/lib bin/sqlt --parser DBI –dsn 'dbi:mysql:dbname=X;host=127.0.0.1' --db-user X --db-password X --use-same-auth --producer ClassDBI –package 'My::Class::DBI' --- diff --git a/bin/sqlt b/bin/sqlt index 049f809..9fe46a8 100755 --- a/bin/sqlt +++ b/bin/sqlt @@ -2,7 +2,7 @@ # vim: set ft=perl: # ------------------------------------------------------------------- -# $Id: sqlt,v 1.18 2005-07-06 19:20:27 duality72 Exp $ +# $Id: sqlt,v 1.19 2005-11-17 21:55:41 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -53,6 +53,7 @@ To translate a schema: DBI Parser Options: --dsn DSN for connecting to database + (see also --use-same-auth below) --db-user Database user --db-password Database password @@ -63,6 +64,13 @@ To translate a schema: --no-trim Don't trim whitespace on fields --no-scan Don't scan fields for data types and sizes + General Producer Options + + --producer-db-user Database user for producer + --producer-db-pass Database password for producer + --producer-dsn DSN for producer + --use-same-auth Use these DSN, user, password for producer output + DB Producer Options: --add-drop-table Add 'DROP TABLE' statements before creates @@ -77,9 +85,6 @@ To translate a schema: --skip Comma-separated list of tables to skip --skiplike Regex for tables to skip - --dumper-db-user Database user for dumper script - --dumper-db-pass Database password for dumper script - --dumper-dsn DSN for dumper script --add-truncate Add "TRUNCATE TABLE" statements for each table HTML/POD Producer Options: @@ -100,6 +105,10 @@ To translate a schema: --no-newlines Write the XML as a single line. --indent= Use characters of whitespace to indent the XML. + ClassDBI Producer Options: + + --package Base package name for Class::DBI modules. + =head1 DESCRIPTION This script is part of the SQL Fairy project. It will try to convert @@ -125,7 +134,7 @@ use Pod::Usage; use SQL::Translator; use vars qw( $VERSION ); -$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.19 $ =~ /(\d+)\.(\d+)/; my $from; # the original database my $to; # the destination database @@ -153,15 +162,17 @@ my $add_prefix; # Use explicit namespace prefix (XML producer) my $prefix; # Set explicit namespace prefix (XML producer) my $newlines; # Add newlines around tags (XML producer) my $indent; # Number of indent chars for XML +my $package_name; # Base class name for ClassDBI +my $use_same_auth =0; # producer uses same DSN, user, password as parser my $dsn; # DBI parser my $db_user; # DBI parser my $db_password; # DBI parser my $show_version; # Show version and exit script my $skip; my $skiplike; -my $dumper_db_user; -my $dumper_db_pass; -my $dumper_dsn; +my $producer_db_user; # DSN for producer (e.g. Dumper, ClassDBI) +my $producer_db_password; # db_pass " +my $producer_dsn; # db_user " my $add_truncate; GetOptions( @@ -189,9 +200,9 @@ GetOptions( 'dsn:s' => \$dsn, 'db-user:s' => \$db_user, 'db-password:s' => \$db_password, - 'dumper-dsn:s' => \$dumper_dsn, - 'dumper-db-user:s' => \$dumper_db_user, - 'dumper-db-pass:s' => \$dumper_db_pass, + 'producer-dsn:s' => \$producer_dsn, + 'producer-db-user:s'=> \$producer_db_user, + 'producer-db-pass:s'=> \$producer_db_password, 'skip:s' => \$skip, 'skiplike:s' => \$skiplike, 'add_truncate' => \$add_truncate, @@ -199,9 +210,17 @@ GetOptions( 'prefix:s' => \$prefix, 'indent:s' => \$indent, 'newlines!' => \$newlines, + 'package=s' => \$package_name, + 'use-same-auth' => \$use_same_auth, 'version' => \$show_version, ) or pod2usage(2); +if ($use_same_auth) { + $producer_dsn = $dsn; + $producer_db_user = $db_user; + $producer_db_password = $db_password; +} + $from = 'DBI' if !defined $from && defined $dsn; my @files = @ARGV; # source files unless ( @files ) { @@ -244,9 +263,9 @@ my $translator = SQL::Translator->new( tt_vars => \%tt_vars, tt_conf => \%tt_conf, title => $title, - dsn => $dumper_dsn, - db_user => $dumper_db_user, - db_password => $dumper_db_pass, + dsn => $producer_dsn, + db_user => $producer_db_user, + db_password => $producer_db_password, skip => $skip, skiplike => $skiplike, add_truncate => $add_truncate, @@ -254,6 +273,7 @@ my $translator = SQL::Translator->new( prefix => $prefix, indent => $indent, newlines => $newlines, + package_name => $package_name, }, ); diff --git a/lib/SQL/Translator/Producer/ClassDBI.pm b/lib/SQL/Translator/Producer/ClassDBI.pm index f6b8c17..04c244e 100755 --- a/lib/SQL/Translator/Producer/ClassDBI.pm +++ b/lib/SQL/Translator/Producer/ClassDBI.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::ClassDBI; # ------------------------------------------------------------------- -# $Id: ClassDBI.pm,v 1.43 2005-07-07 22:37:19 allenday Exp $ +# $Id: ClassDBI.pm,v 1.44 2005-11-17 21:55:41 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -22,7 +22,7 @@ package SQL::Translator::Producer::ClassDBI; use strict; use vars qw[ $VERSION $DEBUG ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.43 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.44 $ =~ /(\d+)\.(\d+)/; $DEBUG = 1 unless defined $DEBUG; use SQL::Translator::Schema::Constants; @@ -50,8 +50,9 @@ sub produce { $t->format_fk_name( $fmt ); } my $db_user = $args->{'db_user'} || ''; - my $db_pass = $args->{'db_pass'} || ''; - my $main_pkg_name = $args->{'main_pkg_name'} || + my $db_pass = $args->{'db_password'} || ''; + my $main_pkg_name = $args->{'package_name'} || + # $args->{'main_pkg_name'} || # keep this? undocumented $t->format_package_name('DBI'); my $header = header_comment( __PACKAGE__, "# " ); my $parser_type = ( split /::/, $t->parser_type )[-1]; @@ -113,7 +114,7 @@ sub produce { for my $table ( $schema->get_tables ) { my $table_name = $table->name or next; - my $table_pkg_name = $t->format_package_name($table_name); + my $table_pkg_name = join '::', $main_pkg_name, $t->format_package_name($table_name); $packages{ $table_pkg_name } = { order => ++$order, pkg_name => $table_pkg_name,