By royal decree, produced statements in list context shall not end in a semi-colon...
[dbsrgits/SQL-Translator.git] / t / 48xml-to-sqlite.t
CommitLineData
8c4efd11 1#!/usr/bin/perl
2use strict;
3
4use FindBin qw/$Bin/;
5use Test::More;
6use Test::SQL::Translator;
7use Test::Exception;
4d438549 8use Test::Differences;
8c4efd11 9use Data::Dumper;
10use SQL::Translator;
11use SQL::Translator::Schema::Constants;
12
13
14BEGIN {
24d9fe69 15 maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy',
8c4efd11 16 'SQL::Translator::Producer::SQLite');
17}
18
19my $xmlfile = "$Bin/data/xml/schema.xml";
20
21my $sqlt;
22$sqlt = SQL::Translator->new(
23 no_comments => 1,
24 show_warnings => 1,
25 add_drop_table => 1,
26);
27
28die "Can't find test schema $xmlfile" unless -e $xmlfile;
29
30my $sql = $sqlt->translate(
31 from => 'XML-SQLFairy',
32 to => 'SQLite',
33 filename => $xmlfile,
34) or die $sqlt->error;
35
4d438549 36eq_or_diff($sql, << "SQL");
8c4efd11 37BEGIN TRANSACTION;
38
8c4efd11 39DROP TABLE Basic;
24d9fe69 40
8c4efd11 41CREATE TABLE Basic (
42 id INTEGER PRIMARY KEY NOT NULL,
43 title varchar(100) NOT NULL DEFAULT 'hello',
44 description text DEFAULT '',
45 email varchar(255),
46 explicitnulldef varchar,
47 explicitemptystring varchar DEFAULT '',
48 -- Hello emptytagdef
08d91aad 49 emptytagdef varchar DEFAULT '',
b08b5416 50 another_id int(10) DEFAULT '2',
08d91aad 51 timest timestamp
8c4efd11 52);
53
4d438549 54CREATE INDEX titleindex_Basic ON Basic (title);
24d9fe69 55
4d438549 56CREATE UNIQUE INDEX emailuniqueindex_Basic ON Basic (email);
8c4efd11 57
b08b5416 58DROP TABLE Another;
24d9fe69 59
b08b5416 60CREATE TABLE Another (
61 id INTEGER PRIMARY KEY NOT NULL
62);
63
a25ac5d2 64DROP VIEW IF EXISTS email_list;
65CREATE VIEW email_list AS
66 SELECT email FROM Basic WHERE email IS NOT NULL;
ec59a597 67
8c4efd11 68COMMIT;
69SQL
24d9fe69 70
71# Test in list context
72my @sql = $sqlt->translate(
73 from => 'XML-SQLFairy',
74 to => 'SQLite',
75 filename => $xmlfile,
76) or die $sqlt->error;
77
78is_deeply(\@sql,
79 [
80 'BEGIN TRANSACTION',
81 'DROP TABLE Basic',
82 'CREATE TABLE Basic (
83 id INTEGER PRIMARY KEY NOT NULL,
84 title varchar(100) NOT NULL DEFAULT \'hello\',
85 description text DEFAULT \'\',
86 email varchar(255),
87 explicitnulldef varchar,
88 explicitemptystring varchar DEFAULT \'\',
89 -- Hello emptytagdef
90 emptytagdef varchar DEFAULT \'\',
91 another_id int(10) DEFAULT \'2\',
92 timest timestamp
93)',
94 'CREATE INDEX titleindex_Basic02 ON Basic (title)',
95 'CREATE UNIQUE INDEX emailuniqueindex_Basic02 ON Basic (email)',
96 'DROP TABLE Another',
97 'CREATE TABLE Another (
98 id INTEGER PRIMARY KEY NOT NULL
99)',
100 'DROP VIEW IF EXISTS email_list;
101CREATE VIEW email_list AS
102 SELECT email FROM Basic WHERE email IS NOT NULL',
103 'COMMIT'
104 ], 'SQLite translate in list context matches');
105
106