8a430b6fea895f6e02ab7072cef310d8fdd666e1
[dbsrgits/SQL-Translator.git] / t / 43xml-to-db2.t
1 #!/usr/bin/perl
2 use strict;
3
4 use FindBin qw/$Bin/;
5 use Test::More;
6 use Test::SQL::Translator;
7 use Test::Exception;
8 use Data::Dumper;
9 use SQL::Translator;
10 use SQL::Translator::Schema::Constants;
11
12
13 BEGIN {
14     maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy',
15               'SQL::Translator::Producer::DB2');
16 }
17
18 my $xmlfile = "$Bin/data/xml/schema.xml";
19
20 my $sqlt;
21 $sqlt = SQL::Translator->new(
22     no_comments => 1,
23     show_warnings  => 1,
24     add_drop_table => 1,
25 );
26
27 die "Can't find test schema $xmlfile" unless -e $xmlfile;
28
29 my $sql = $sqlt->translate(
30     from     => 'XML-SQLFairy',
31     to       => 'DB2',
32     filename => $xmlfile,
33 ) or die $sqlt->error;
34
35 is($sql, << "SQL");
36 DROP TABLE Basic;
37
38 CREATE TABLE Basic (
39 id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL,
40 title VARCHAR(100) NOT NULL DEFAULT 'hello',
41 description VARCHAR(0) DEFAULT '',
42 email VARCHAR(255),
43 explicitnulldef VARCHAR(0),
44 explicitemptystring VARCHAR(0) DEFAULT '',
45 emptytagdef VARCHAR(0) DEFAULT '',
46 timest TIMESTAMP,
47 CONSTRAINT emailuniqueindex UNIQUE (email)   ,
48  PRIMARY KEY(id)
49 );
50
51 CREATE INDEX titleindex ON Basic ( title );
52
53 CREATE VIEW email_list AS
54 SELECT email FROM Basic WHERE email IS NOT NULL;
55
56 CREATE TRIGGER foo_trigger after insert ON Basic REFERENCING OLD AS oldrow NEW AS newrow FOR EACH ROW MODE DB2SQL update modified=timestamp();
57 SQL