Change to avoid warning of "use of unitialized value."
[dbsrgits/SQL-Translator.git] / bin / sql_translator.pl
index 2465737..0132d36 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 # -------------------------------------------------------------------
-# $Id: sql_translator.pl,v 1.5 2002-11-22 03:03:40 kycl4rk Exp $
+# $Id: sql_translator.pl,v 1.9 2003-05-12 14:48:43 kycl4rk Exp $
 # -------------------------------------------------------------------
 # Copyright (C) 2002 Ken Y. Clark <kycl4rk@users.sourceforge.net>,
 #                    darren chamberlain <darren@cpan.org>
@@ -29,17 +29,23 @@ use SQL::Translator;
 use Data::Dumper;
 
 use vars qw( $VERSION );
-$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
-
-my $from;        # the original 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 $xlate;       # user overrides for field translation
-my $debug;       # whether to print debug info
-my $trace;       # whether to print parser trace
-my $list;        # list all parsers and producers
+$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
+
+my $from;             # the original 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 $show_warnings;    # whether to show warnings from SQL::Translator
+my $add_drop_table;   # whether to show warnings from SQL::Translator
+my $xlate;            # user overrides for field translation
+my $debug;            # whether to print debug info
+my $trace;            # whether to print parser trace
+my $list;             # list all parsers and producers
+my $no_trim;          # don't trim whitespace on xSV fields
+my $no_scan;          # don't scan xSV fields for data types and sizes
+my $field_separator;  # for xSV files
+my $record_separator; # for xSV files
 
 #
 # Get options, explain how to use the script if necessary.
@@ -52,7 +58,12 @@ GetOptions(
     'd|debug'         => \$debug,
     'trace'           => \$trace,
     'no-comments'     => \$no_comments,
-    'xlate=s'         => \$xlate,
+    'show-warnings'   => \$show_warnings,
+    'add-drop-table'  => \$add_drop_table,
+    'no-trim'         => \$no_trim,
+    'no-scan'         => \$no_scan,
+    'fs:s'            => \$field_separator,
+    'rs:s'            => \$record_separator,
 ) or pod2usage(2);
 
 my @files = @ARGV; # the create script(s) for the original db
@@ -71,11 +82,19 @@ if ( $xlate ) {
 #
 # If everything is OK, translate file(s).
 #
-my $translator  =  SQL::Translator->new( 
-    xlate       => $xlate || {},
-    debug       => $debug,
-    trace       => $trace,
-    no_comments => $no_comments,
+my $translator      =  SQL::Translator->new( 
+    xlate           => $xlate          || {},
+    debug           => $debug          ||  0,
+    trace           => $trace          ||  0,
+    no_comments     => $no_comments    ||  0,
+    show_warnings   => $show_warnings  ||  0,
+    add_drop_table  => $add_drop_table ||  0,
+    parser_args     => {
+        trim_fields      => $no_trim ? 0 : 1,
+        scan_fields      => $no_scan ? 0 : 1,
+        field_separator  => $field_separator,
+        record_separator => $record_separator,
+    }
 );
 
 if ( $list ) {
@@ -134,10 +153,18 @@ To translate a schema:
 
   Options:
 
-    -d|--debug                Print debug info
-    --trace                   Print parser trace info
-    --no-comments             Don't include comments in SQL output
-    --xlate=foo/bar,baz/blech Overrides for field translation
+    -d|--debug            Print debug info
+    --trace               Print parser trace info
+    --no-comments         Don't include comments in SQL output
+    --show-warnings       Print to STDERR warnings of conflicts, etc.
+    --add-drop-table      Add 'drop table' statements before creates
+
+  xSV 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 
 
 =head1 DESCRIPTION
 
@@ -146,6 +173,12 @@ This script is part of the SQL Fairy project
 database syntax for which it has a grammar into some other format it
 knows about.
 
+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 file.sql \
+       1>out 2>err
+
 =head1 AUTHOR
 
 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>