Test changes
[dbsrgits/SQL-Translator.git] / bin / sql_translator.pl
1 #!/usr/local/bin/perl -w
2
3 #-----------------------------------------------------
4 # $Id: sql_translator.pl,v 1.1.1.1.2.1 2002-03-15 20:09:38 dlc Exp $
5 #-----------------------------------------------------
6 # Copyright (C) 2002 Ken Y. Clark <kycl4rk@users.sourceforge.net>,
7 #                    darren chamberlain <darren@cpan.org>
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; version 2.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # 02111-1307  USA
22 # -------------------------------------------------------------------
23
24 use strict;
25 use Getopt::Long;
26 use Pod::Usage;
27 use SQL::Translator;
28 use vars qw( $VERSION );
29 $VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1.2.1 $ =~ /(\d+)\.(\d+)/;
30
31 my $from;        # the original database
32 my $to;          # the destination database 
33 my $help;        # show POD and bail
34 my $stdin;       # whether to read STDIN for create script
35 my $no_comments; # whether to put comments in out file
36 my $verbose;     # whether to print progress/debug
37
38 #
39 # Get options, explain how to use the script if necessary.
40 #
41 GetOptions(
42     'f|from|parser=s' => \$from,
43     't|to|producer=s' => \$to,
44     'h|help'          => \$help,
45     'v|verbose'       => \$verbose,
46     'no_comments'     => \$no_comments,
47 ) or pod2usage(2);
48
49 my @files = @ARGV; # the create script for the original db
50
51 pod2usage(1) if $help;
52 pod2usage(2) unless $from && $to && @files;
53
54 #
55 # If everything is OK, translate file(s).
56 #
57 my $translator = SQL::Translator->new;
58 $translator->parser($from);
59 $translator->producer($to);
60
61 for my $file (@files) {
62     my $output =  $translator->translate($file)
63                      or die "Error: " . $translator->error;
64     print "Output:\n", $output;
65 }
66
67 __END__
68 #-----------------------------------------------------
69 # It is not all books that are as dull as their readers.
70 # Henry David Thoreau
71 #-----------------------------------------------------
72
73 =head1 NAME
74
75 sql_translator.pl - convert schema to Oracle syntax
76
77 =head1 SYNOPSIS
78
79   ./sql_translator.pl -h|--help
80
81   ./sql_translator.pl -f|--from mysql -t|--to oracle [options] file
82
83   Options:
84
85     -v|--verbose   Print debug info to STDERR
86     --no-comments  Don't include comments in SQL output
87
88 =head1 DESCRIPTION
89
90 Part of the SQL Fairy project (sqlfairy.sourceforge.net), this script
91 will try to convert any database syntax for which it has a grammar
92 into some other format will accept.
93
94 =head1 AUTHOR
95
96 Ken Y. Clark, kclark@logsoft.com
97
98 =head1 SEE ALSO
99
100 perl(1), SQL::Transport.
101
102 =cut