6 use Test::SQL::Translator;
11 use SQL::Translator::Schema::Constants;
15 maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy',
16 'SQL::Translator::Producer::SQLite');
19 my $xmlfile = "$Bin/data/xml/schema.xml";
22 $sqlt = SQL::Translator->new(
28 die "Can't find test schema $xmlfile" unless -e $xmlfile;
30 my $sql = $sqlt->translate(
31 from => 'XML-SQLFairy',
34 ) or die $sqlt->error;
36 eq_or_diff($sql, << "SQL");
44 id INTEGER PRIMARY KEY NOT NULL,
45 title varchar(100) NOT NULL DEFAULT 'hello',
46 description text DEFAULT '',
48 explicitnulldef varchar,
49 explicitemptystring varchar DEFAULT '',
51 emptytagdef varchar DEFAULT '',
52 another_id int(10) DEFAULT '2',
56 CREATE INDEX titleindex_Basic ON Basic (title);
58 CREATE UNIQUE INDEX emailuniqueindex_Basic ON Basic (email);
62 CREATE TABLE Another (
63 id INTEGER PRIMARY KEY NOT NULL
66 DROP VIEW IF EXISTS email_list;
67 CREATE VIEW email_list AS
68 SELECT email FROM Basic WHERE email IS NOT NULL;
70 DROP TRIGGER IF EXISTS foo_trigger;
72 CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END;
77 # Test in list context
78 my @sql = $sqlt->translate(
79 from => 'XML-SQLFairy',
82 ) or die $sqlt->error;
86 "\n\nBEGIN TRANSACTION",
89 id INTEGER PRIMARY KEY NOT NULL,
90 title varchar(100) NOT NULL DEFAULT \'hello\',
91 description text DEFAULT \'\',
93 explicitnulldef varchar,
94 explicitemptystring varchar DEFAULT \'\',
96 emptytagdef varchar DEFAULT \'\',
97 another_id int(10) DEFAULT \'2\',
100 'CREATE INDEX titleindex_Basic02 ON Basic (title)',
101 'CREATE UNIQUE INDEX emailuniqueindex_Basic02 ON Basic (email)',
102 'DROP TABLE Another',
103 'CREATE TABLE Another (
104 id INTEGER PRIMARY KEY NOT NULL
106 'DROP VIEW IF EXISTS email_list;
107 CREATE VIEW email_list AS
108 SELECT email FROM Basic WHERE email IS NOT NULL',
109 'DROP TRIGGER IF EXISTS foo_trigger',
110 'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
112 ], 'SQLite translate in list context matches');