# vim: set ft=perl:
# -------------------------------------------------------------------
-# $Id: sqlt,v 1.6 2003-10-10 16:38:43 dlc Exp $
+# $Id: sqlt,v 1.16 2004-11-25 23:15:23 grommit Exp $
# -------------------------------------------------------------------
-# Copyright (C) 2002 Ken Y. Clark <kclar@cpan.org>,
-# darren chamberlain <darren@cpan.org>
+# Copyright (C) 2002-4 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
sqlt -h|--help
-For a list of all parsers and producers:
+For a list of all parsers and producers:
sqlt -l|--list
To translate a schema:
- sqlt -f|--from|--parser MySQL
- -t|--to|--producer Oracle
- [options]
+ sqlt -f|--from|--parser MySQL
+ -t|--to|--producer Oracle
+ [options]
file [file2 ...]
General Options:
-d|--debug Print debug info
-v|--validate Validate the schema
+ --version Show the version of SQL::Translator
--trace Print parser trace info
--show-warnings Print warnings to STDERR
--dsn DSN for connecting to database
--db-user Database user
- --db-password Database password
+ --db-password Database password
xSV Parser Options:
--fs The field separator
--rs The record separator
- --no-trim Don't trim whitespace on fields
- --no-scan Don't scan fields for data types and sizes
+ --no-trim Don't trim whitespace on fields
+ --no-scan Don't scan fields for data types and sizes
DB Producer Options:
--imap-file Filename to put image map data
--imap-url URL to use for image map
+ Dumper Producer Options:
+
+ --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:
--pretty Use CGI::Pretty for the output
TTSchema Producer Options:
--template The path to the template
+ --tt-var var=value Pass extra variables to the template
XML-SQLFairy Producer Options:
- --emit-empty-tags Print empty tags for attributes
- --attrib-values Use attributes instead of tags for
- values of the schema objects
+ --add-prefix Use an explicit namespace prefix of 'sqlf:'
+ --prefix=<p> Use the namespace prefix given as argument.
+ --no-newlines Write the XML as a single line.
+ --indent=<n> Use <n> characters of whitespace to indent the XML.
=head1 DESCRIPTION
any source file for which it has a grammar into any format for which
it has a producer.
-If using "show-warnings," be sure to redirect STDERR to a separate file.
+If using "show-warnings," be sure to redirect STDERR to a separate file.
In bash, you could do this:
$ sql_translator.pl -f MySQL -t PostgreSQL --show-warnings \
use SQL::Translator;
use vars qw( $VERSION );
-$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/;
my $from; # the original database
-my $to; # the destination database
+my $to; # the destination database
my $help; # show POD and bail
my $stdin; # whether to read STDIN for create script
my $no_comments; # whether to put comments in out file
my $imap_url; # URL to use in making image map
my $pretty; # use CGI::Pretty instead of CGI (HTML producer)
my $template; # template to pass to TTSchema producer
+my %tt_vars; # additional template vars to pass the TTSchema producer
my $title; # title for HTML/POD producer
-my $emit_empty_tags; # show empty XML tags
-my $attrib_values; # use XML attributes instead of tags
-my $dsn; # DBI parser
-my $db_user; # DBI parser
-my $db_password; # DBI parser
+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 $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 $add_truncate;
GetOptions(
- 'add-drop-table' => \$add_drop_table,
- 'attrib-values' => \$attrib_values,
- 'd|debug' => \$debug,
- 'emit_empty_tags' => \$emit_empty_tags,
- 'f|from|parser:s' => \$from,
- 'fs:s' => \$field_separator,
- 'h|help' => \$help,
- 'imap-file:s' => \$imap_file,
- 'imap-url:s' => \$imap_url,
- 't|to|producer:s' => \$to,
- 'l|list' => \$list,
- 'pretty!' => \$pretty,
- 'no-comments' => \$no_comments,
- 'no-scan' => \$no_scan,
- 'no-trim' => \$no_trim,
- 'rs:s' => \$record_separator,
- 'show-warnings' => \$show_warnings,
- 'template:s' => \$template,
- 'title:s' => \$title,
- 'trace' => \$trace,
- 'v|validate' => \$validate,
- 'dsn:s' => \$dsn,
- 'db-user:s' => \$db_user,
- 'db-password:s' => \$db_password,
+ 'add-drop-table' => \$add_drop_table,
+ 'd|debug' => \$debug,
+ 'f|from|parser:s' => \$from,
+ 'fs:s' => \$field_separator,
+ 'h|help' => \$help,
+ 'imap-file:s' => \$imap_file,
+ 'imap-url:s' => \$imap_url,
+ 't|to|producer:s' => \$to,
+ 'l|list' => \$list,
+ 'pretty!' => \$pretty,
+ 'no-comments' => \$no_comments,
+ 'no-scan' => \$no_scan,
+ 'no-trim' => \$no_trim,
+ 'rs:s' => \$record_separator,
+ 'show-warnings' => \$show_warnings,
+ 'template:s' => \$template,
+ 'tt-var=s' => \%tt_vars,
+ 'title:s' => \$title,
+ 'trace' => \$trace,
+ 'v|validate' => \$validate,
+ '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,
+ 'skip:s' => \$skip,
+ 'skiplike:s' => \$skiplike,
+ 'add_truncate' => \$add_truncate,
+ 'add-prefix' => \$add_prefix,
+ 'prefix:s' => \$prefix,
+ 'indent:s' => \$indent,
+ 'newlines!' => \$newlines,
+ 'version' => \$show_version,
) or pod2usage(2);
-my @files = @ARGV || '-'; # source files
+my @files = @ARGV; # source files
+unless ( @files ) {
+ if ( defined($from) && $from eq 'DBI' ) {
+ @files = ('!');
+ }
+ else {
+ @files = ('-');
+ }
+}
pod2usage(1) if $help;
+if ( $show_version ) {
+ print "SQL::Translator v", $SQL::Translator::VERSION, "\n";
+ exit(0);
+}
+
my $translator = SQL::Translator->new(
debug => $debug || 0,
trace => $trace || 0,
imap_url => $imap_url,
pretty => $pretty,
ttfile => $template,
+ tt_vars => \%tt_vars,
title => $title,
- emit_empty_tags => $emit_empty_tags,
- attrib_values => $attrib_values,
+ dsn => $dumper_dsn,
+ db_user => $dumper_db_user,
+ db_password => $dumper_db_pass,
+ skip => $skip,
+ skiplike => $skiplike,
+ add_truncate => $add_truncate,
+ add_prefix => $add_prefix,
+ prefix => $prefix,
+ indent => $indent,
+ newlines => $newlines,
},
);
$_ = $1;
}
}
-
+
print "\nParsers:\n", map { "\t$_\n" } sort @parsers;
print "\nProducers:\n", map { "\t$_\n" } sort @producers;
print "\n";
exit(0);
}
-pod2usage( msg => 'Please supply "from" and "to" arguments' ) unless $from && $to;
+pod2usage( msg => 'Please supply "from" and "to" arguments' )
+ unless $from && $to;
$translator->parser($from);
$translator->producer($to);
for my $file (@files) {
- my @args = ($file eq '-') ? (data => \*STDIN) : (file => $file);
+ my @args =
+ ($file eq '-') ? (data => \*STDIN) :
+ ($file eq '!') ? (data => '') :
+ (file => $file);
+
my $output = $translator->translate(@args) or die
"Error: " . $translator->error;
+
print $output;
}
=head1 AUTHOR
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
+Ken Y. Clark E<lt>kclark@cpan.orgE<gt>,
+darren chamberlain E<lt>darren@cpan.orgE<gt>.
=head1 SEE ALSO
-perl, SQL::Translator, Parse::RecDescent,
-L<http://sqlfairy.sourceforge.net>.
+SQL::Translator, L<http://sqlfairy.sourceforge.net>.
=cut