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");
42 id INTEGER PRIMARY KEY NOT NULL,
43 title varchar(100) NOT NULL DEFAULT 'hello',
44 description text DEFAULT '',
46 explicitnulldef varchar,
47 explicitemptystring varchar DEFAULT '',
49 emptytagdef varchar DEFAULT '',
50 another_id int(10) DEFAULT 2,
54 CREATE INDEX titleindex ON Basic (title);
56 CREATE UNIQUE INDEX emailuniqueindex ON Basic (email);
58 CREATE UNIQUE INDEX very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms ON Basic (title);
62 CREATE TABLE Another (
63 id INTEGER PRIMARY KEY NOT NULL,
67 DROP VIEW IF EXISTS email_list;
69 CREATE VIEW email_list AS
70 SELECT email FROM Basic WHERE (email IS NOT NULL);
72 DROP TRIGGER IF EXISTS foo_trigger;
74 CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END;
76 DROP TRIGGER IF EXISTS bar_trigger_insert;
78 CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END;
80 DROP TRIGGER IF EXISTS bar_trigger_update;
82 CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END;
87 # Test in list context
88 my @sql = $sqlt->translate(
89 from => 'XML-SQLFairy',
92 ) or die $sqlt->error;
99 id INTEGER PRIMARY KEY NOT NULL,
100 title varchar(100) NOT NULL DEFAULT \'hello\',
101 description text DEFAULT \'\',
103 explicitnulldef varchar,
104 explicitemptystring varchar DEFAULT \'\',
106 emptytagdef varchar DEFAULT \'\',
107 another_id int(10) DEFAULT 2,
110 'CREATE INDEX titleindex ON Basic (title)',
111 'CREATE UNIQUE INDEX emailuniqueindex ON Basic (email)',
112 'CREATE UNIQUE INDEX very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms ON Basic (title)',
113 'DROP TABLE Another',
114 'CREATE TABLE Another (
115 id INTEGER PRIMARY KEY NOT NULL,
118 'DROP VIEW IF EXISTS email_list',
119 'CREATE VIEW email_list AS
120 SELECT email FROM Basic WHERE (email IS NOT NULL)',
121 'DROP TRIGGER IF EXISTS foo_trigger',
122 'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
123 'DROP TRIGGER IF EXISTS bar_trigger_insert',
124 'CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END',
125 'DROP TRIGGER IF EXISTS bar_trigger_update',
126 'CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END',
129 ], 'SQLite translate in list context matches');