Oracle/SQLite test adjustments to deal with new testdata field
[dbsrgits/SQL-Translator.git] / t / 48xml-to-sqlite.t
1 #!/usr/bin/perl
2 use strict;
3
4 use FindBin qw/$Bin/;
5 use Test::More;
6 use Test::SQL::Translator;
7 use Test::Exception;
8 use Test::Differences;
9 use Data::Dumper;
10 use SQL::Translator;
11 use SQL::Translator::Schema::Constants;
12
13
14 BEGIN {
15     maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy',
16               'SQL::Translator::Producer::SQLite');
17 }
18
19 my $xmlfile = "$Bin/data/xml/schema.xml";
20
21 my $sqlt;
22 $sqlt = SQL::Translator->new(
23     no_comments => 1,
24     show_warnings  => 0,
25     add_drop_table => 1,
26 );
27
28 die "Can't find test schema $xmlfile" unless -e $xmlfile;
29
30 my $sql = $sqlt->translate(
31     from     => 'XML-SQLFairy',
32     to       => 'SQLite',
33     filename => $xmlfile,
34 ) or die $sqlt->error;
35
36 eq_or_diff($sql, << "SQL");
37
38
39 BEGIN TRANSACTION;
40
41 DROP TABLE Basic;
42
43 CREATE TABLE Basic (
44   id INTEGER PRIMARY KEY NOT NULL,
45   title varchar(100) NOT NULL DEFAULT 'hello',
46   description text DEFAULT '',
47   email varchar(500),
48   explicitnulldef varchar,
49   explicitemptystring varchar DEFAULT '',
50   -- Hello emptytagdef
51   emptytagdef varchar DEFAULT '',
52   another_id int(10) DEFAULT '2',
53   timest timestamp
54 );
55
56 CREATE INDEX titleindex ON Basic (title);
57
58 CREATE UNIQUE INDEX emailuniqueindex ON Basic (email);
59
60 DROP TABLE Another;
61
62 CREATE TABLE Another (
63   id INTEGER PRIMARY KEY NOT NULL,
64   num numeric(10,2)
65 );
66
67 DROP VIEW IF EXISTS email_list;
68 CREATE VIEW email_list AS
69     SELECT email FROM Basic WHERE (email IS NOT NULL);
70
71 DROP TRIGGER IF EXISTS foo_trigger;
72
73 CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END;
74
75 DROP TRIGGER IF EXISTS bar_trigger_insert;
76
77 CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END;
78
79 DROP TRIGGER IF EXISTS bar_trigger_update;
80
81 CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END;
82
83 COMMIT;
84 SQL
85
86 # Test in list context
87 my @sql = $sqlt->translate(
88     from     => 'XML-SQLFairy',
89     to       => 'SQLite',
90     filename => $xmlfile,
91 ) or die $sqlt->error;
92
93 eq_or_diff(\@sql, 
94           [
95           "\n\nBEGIN TRANSACTION",
96           'DROP TABLE Basic',
97           'CREATE TABLE Basic (
98   id INTEGER PRIMARY KEY NOT NULL,
99   title varchar(100) NOT NULL DEFAULT \'hello\',
100   description text DEFAULT \'\',
101   email varchar(500),
102   explicitnulldef varchar,
103   explicitemptystring varchar DEFAULT \'\',
104   -- Hello emptytagdef
105   emptytagdef varchar DEFAULT \'\',
106   another_id int(10) DEFAULT \'2\',
107   timest timestamp
108 )',
109           'CREATE INDEX titleindex ON Basic (title)',
110           'CREATE UNIQUE INDEX emailuniqueindex ON Basic (email)',
111           'DROP TABLE Another',
112           'CREATE TABLE Another (
113   id INTEGER PRIMARY KEY NOT NULL,
114   num numeric(10,2)
115 )',
116           'DROP VIEW IF EXISTS email_list;
117 CREATE VIEW email_list AS
118     SELECT email FROM Basic WHERE (email IS NOT NULL)',
119           'DROP TRIGGER IF EXISTS foo_trigger',
120           'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
121           'DROP TRIGGER IF EXISTS bar_trigger_insert',
122           'CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END',
123           'DROP TRIGGER IF EXISTS bar_trigger_update',
124           'CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END',
125           'COMMIT',
126
127           ], 'SQLite translate in list context matches');
128
129