# 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
#
DBI Parser Options:
--dsn DSN for connecting to database
+ (see also --use-same-auth below)
--db-user Database user
--db-password Database password
--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
--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:
--no-newlines Write the XML as a single line.
--indent=<n> Use <n> 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
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
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(
'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,
'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 ) {
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,
prefix => $prefix,
indent => $indent,
newlines => $newlines,
+ package_name => $package_name,
},
);
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
#
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;
$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];
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,