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,
52 FOREIGN KEY(another_id) REFERENCES Another()
55 CREATE INDEX titleindex ON Basic (title);
57 CREATE UNIQUE INDEX emailuniqueindex ON Basic (email);
59 CREATE UNIQUE INDEX very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms ON Basic (title);
63 CREATE TABLE Another (
64 id INTEGER PRIMARY KEY NOT NULL,
68 DROP VIEW IF EXISTS email_list;
70 CREATE VIEW email_list AS
71 SELECT email FROM Basic WHERE (email IS NOT NULL);
73 DROP TRIGGER IF EXISTS foo_trigger;
75 CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END;
77 DROP TRIGGER IF EXISTS bar_trigger_insert;
79 CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END;
81 DROP TRIGGER IF EXISTS bar_trigger_update;
83 CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END;
88 # Test in list context
89 my @sql = $sqlt->translate(
90 from => 'XML-SQLFairy',
93 ) or die $sqlt->error;
100 id INTEGER PRIMARY KEY NOT NULL,
101 title varchar(100) NOT NULL DEFAULT \'hello\',
102 description text DEFAULT \'\',
104 explicitnulldef varchar,
105 explicitemptystring varchar DEFAULT \'\',
107 emptytagdef varchar DEFAULT \'\',
108 another_id int(10) DEFAULT 2,
110 FOREIGN KEY(another_id) REFERENCES Another()
112 'CREATE INDEX titleindex ON Basic (title)',
113 'CREATE UNIQUE INDEX emailuniqueindex ON Basic (email)',
114 'CREATE UNIQUE INDEX very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms ON Basic (title)',
115 'DROP TABLE Another',
116 'CREATE TABLE Another (
117 id INTEGER PRIMARY KEY NOT NULL,
120 'DROP VIEW IF EXISTS email_list',
121 'CREATE VIEW email_list AS
122 SELECT email FROM Basic WHERE (email IS NOT NULL)',
123 'DROP TRIGGER IF EXISTS foo_trigger',
124 'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
125 'DROP TRIGGER IF EXISTS bar_trigger_insert',
126 'CREATE TRIGGER bar_trigger_insert before insert on Basic BEGIN update modified2=timestamp(); END',
127 'DROP TRIGGER IF EXISTS bar_trigger_update',
128 'CREATE TRIGGER bar_trigger_update before update on Basic BEGIN update modified2=timestamp(); END',
131 ], 'SQLite translate in list context matches');