~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/randgen/translateMysql.pl

  • Committer: Mark Atwood
  • Date: 2011-10-08 04:50:51 UTC
  • mfrom: (2430.1.1 rf)
  • Revision ID: me@mark.atwood.name-20111008045051-6ha1qiy7k2a9c3jv
Tags: 2011.10.27
mergeĀ lp:~olafvdspek/drizzle/refactor2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Sun Microsystems, Inc. All rights reserved.  Use
2
 
# is subject to license terms.
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; version 2 of the License.
7
 
#
8
 
# This program is distributed in the hope that it will be useful, but
9
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
 
# General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
 
# USA
17
 
 
18
 
#!/usr/bin/perl
19
 
 
20
 
use lib 'lib';
21
 
use lib "$ENV{RQG_HOME}/lib";
22
 
use strict;
23
 
use GenTest;
24
 
use GenTest::Translator;
25
 
use GenTest::Translator::MysqlDML2ANSI;
26
 
use GenTest::Translator::MysqlDML2pgsql;
27
 
use GenTest::Translator::MysqlDML2javadb;
28
 
use GenTest::Translator::Mysqldump2ANSI;
29
 
use GenTest::Translator::Mysqldump2pgsql;
30
 
use GenTest::Translator::Mysqldump2javadb;
31
 
 
32
 
use Getopt::Long;
33
 
 
34
 
my $from = "unspecified";
35
 
my $to = "ansi";
36
 
 
37
 
my $opt_result = GetOptions(
38
 
    'from=s' => $from,
39
 
    'to=s' => \$to
40
 
    );
41
 
 
42
 
$from =~ tr/A-Z/a-z/;
43
 
$to =~ tr/A-Z/a-z/;
44
 
 
45
 
my $translator1;
46
 
my $translator2;
47
 
if ($to eq "ansi") {
48
 
    $translator1 = GenTest::Translator::Mysqldump2ANSI->new();
49
 
    $translator2 = GenTest::Translator::MysqlDML2ANSI->new();
50
 
} elsif ($to eq "javadb" || $to eq "derby") {
51
 
    $translator1 = GenTest::Translator::Mysqldump2javadb->new();
52
 
    $translator2 = GenTest::Translator::MysqlDML2javadb->new();
53
 
} elsif ($to eq "postgres" || $to eq "pg" || $to eq "postgresql" || $to eq "pgsql") {
54
 
    $translator1 = GenTest::Translator::Mysqldump2pgsql->new();
55
 
    $translator2 = GenTest::Translator::MysqlDML2pgsql->new();
56
 
} else {
57
 
    die "Unknown target \"$to\", use \"ansi\", \"javadb\" or \"postgresql\"";
58
 
}
59
 
 
60
 
my $file;
61
 
while(<>) {
62
 
    $file .= $_;
63
 
}
64
 
 
65
 
my $result;
66
 
 
67
 
if ($from eq "unspecified") {
68
 
    $result = $translator1->translate($file);
69
 
    $result = $translator2->translate($result);
70
 
} elsif ($from eq "mysqldump") {
71
 
    $result = $translator1->translate($file);
72
 
} elsif ($from eq "dml") {
73
 
    $result = $translator2->translate($file);
74
 
} else {
75
 
    die "Unknown source \"$from\", if specified, use \"mysqldump\" or \"dml\"";
76
 
}
77
 
 
78
 
print $result;
79
 
 
80