Pg views and sqlite views, patch from wreis
[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 {
15 maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy',
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
36# print ">>$sql<<\n";
37
4d438549 38eq_or_diff($sql, << "SQL");
8c4efd11 39BEGIN TRANSACTION;
40
41
8c4efd11 42DROP TABLE Basic;
43CREATE TABLE Basic (
44 id INTEGER PRIMARY KEY NOT NULL,
45 title varchar(100) NOT NULL DEFAULT 'hello',
46 description text DEFAULT '',
47 email varchar(255),
48 explicitnulldef varchar,
49 explicitemptystring varchar DEFAULT '',
50 -- Hello emptytagdef
08d91aad 51 emptytagdef varchar DEFAULT '',
b08b5416 52 another_id int(10) DEFAULT '2',
08d91aad 53 timest timestamp
8c4efd11 54);
55
4d438549 56CREATE INDEX titleindex_Basic ON Basic (title);
57CREATE UNIQUE INDEX emailuniqueindex_Basic ON Basic (email);
8c4efd11 58
b08b5416 59DROP TABLE Another;
60CREATE TABLE Another (
61 id INTEGER PRIMARY KEY NOT NULL
62);
63
64
a25ac5d2 65DROP VIEW IF EXISTS email_list;
66CREATE VIEW email_list AS
67 SELECT email FROM Basic WHERE email IS NOT NULL;
ec59a597 68
69
8c4efd11 70COMMIT;
71SQL