Commit | Line | Data |
7a8e1f51 |
1 | #!/usr/bin/perl -w |
16dc9970 |
2 | |
49e1eb70 |
3 | # ------------------------------------------------------------------- |
4 | # $Id: sql_translator.pl,v 1.4 2002-11-20 04:03:02 kycl4rk Exp $ |
5 | # ------------------------------------------------------------------- |
783908a1 |
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 | # ------------------------------------------------------------------- |
16dc9970 |
23 | |
24 | use strict; |
25 | use Getopt::Long; |
26 | use Pod::Usage; |
27 | use SQL::Translator; |
49e1eb70 |
28 | |
29 | use Data::Dumper; |
30 | |
16dc9970 |
31 | use vars qw( $VERSION ); |
49e1eb70 |
32 | $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/; |
16dc9970 |
33 | |
34 | my $from; # the original database |
35 | my $to; # the destination database |
36 | my $help; # show POD and bail |
37 | my $stdin; # whether to read STDIN for create script |
38 | my $no_comments; # whether to put comments in out file |
39 | my $verbose; # whether to print progress/debug |
40 | |
41 | # |
42 | # Get options, explain how to use the script if necessary. |
43 | # |
44 | GetOptions( |
783908a1 |
45 | 'f|from|parser=s' => \$from, |
46 | 't|to|producer=s' => \$to, |
47 | 'h|help' => \$help, |
48 | 'v|verbose' => \$verbose, |
49 | 'no_comments' => \$no_comments, |
16dc9970 |
50 | ) or pod2usage(2); |
51 | |
52 | my @files = @ARGV; # the create script for the original db |
53 | |
54 | pod2usage(1) if $help; |
55 | pod2usage(2) unless $from && $to && @files; |
56 | |
57 | # |
58 | # If everything is OK, translate file(s). |
59 | # |
49e1eb70 |
60 | my $translator = SQL::Translator->new( debug => $verbose ); |
783908a1 |
61 | $translator->parser($from); |
62 | $translator->producer($to); |
63 | |
64 | for my $file (@files) { |
49e1eb70 |
65 | my $output = $translator->translate( $file ) or die |
66 | "Error: " . $translator->error; |
67 | print $output; |
68 | warn "parser = ", Dumper( $translator->parser ); |
783908a1 |
69 | } |
16dc9970 |
70 | |
49e1eb70 |
71 | # ---------------------------------------------------- |
16dc9970 |
72 | # It is not all books that are as dull as their readers. |
73 | # Henry David Thoreau |
49e1eb70 |
74 | # ---------------------------------------------------- |
16dc9970 |
75 | |
76 | =head1 NAME |
77 | |
49e1eb70 |
78 | sql_translator.pl - convert an SQL database schema |
16dc9970 |
79 | |
80 | =head1 SYNOPSIS |
81 | |
82 | ./sql_translator.pl -h|--help |
83 | |
49e1eb70 |
84 | ./sql_translator.pl -f|--from MySQL -t|--to Oracle [options] file |
16dc9970 |
85 | |
86 | Options: |
87 | |
88 | -v|--verbose Print debug info to STDERR |
89 | --no-comments Don't include comments in SQL output |
90 | |
91 | =head1 DESCRIPTION |
92 | |
93 | Part of the SQL Fairy project (sqlfairy.sourceforge.net), this script |
94 | will try to convert any database syntax for which it has a grammar |
49e1eb70 |
95 | into some other format it knows about. |
16dc9970 |
96 | |
97 | =head1 AUTHOR |
98 | |
49e1eb70 |
99 | Ken Y. Clark, E<lt>kclark@logsoft.comE<gt> |
16dc9970 |
100 | |
101 | =head1 SEE ALSO |
102 | |
49e1eb70 |
103 | perl(1), SQL::Translator. |
16dc9970 |
104 | |
105 | =cut |