From: Johannes Plunien Date: Fri, 5 Dec 2008 13:18:27 +0000 (+0000) Subject: fixed 51-xml-to-oracle.t X-Git-Tag: v0.11008~267 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6828ad754b94e4787189d177c503bd3830e1012;p=dbsrgits%2FSQL-Translator.git fixed 51-xml-to-oracle.t --- diff --git a/t/51-xml-to-oracle.t b/t/51-xml-to-oracle.t index f44bd0d..c0681c7 100644 --- a/t/51-xml-to-oracle.t +++ b/t/51-xml-to-oracle.t @@ -38,9 +38,9 @@ my $sql_string = $sqlt->translate( ) or die $sqlt->error; my $want = [ -'DROP TABLE Basic CASCADE CONSTRAINTS;', - 'DROP SEQUENCE sq_Basic_id01;', - 'CREATE SEQUENCE sq_Basic_id01;', +'DROP TABLE Basic CASCADE CONSTRAINTS', + 'DROP SEQUENCE sq_Basic_id', + 'CREATE SEQUENCE sq_Basic_id', 'CREATE TABLE Basic ( id number(10) NOT NULL, title varchar2(100) DEFAULT \'hello\' NOT NULL, @@ -53,54 +53,55 @@ my $want = [ timest date, PRIMARY KEY (id), CONSTRAINT emailuniqueindex UNIQUE (email) -);', - 'DROP TABLE Another CASCADE CONSTRAINTS;', - 'DROP SEQUENCE sq_Another_id01;', - 'CREATE SEQUENCE sq_Another_id01;', +)', + 'DROP TABLE Another CASCADE CONSTRAINTS', + 'DROP SEQUENCE sq_Another_id', + 'CREATE SEQUENCE sq_Another_id', 'CREATE TABLE Another ( id number(10) NOT NULL, PRIMARY KEY (id) -);', +)', 'CREATE VIEW email_list AS -SELECT email FROM Basic WHERE email IS NOT NULL;', - 'ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk01 FOREIGN KEY (another_id) REFERENCES Another (id);', - 'CREATE OR REPLACE TRIGGER ai_Basic_id01 +SELECT email FROM Basic WHERE email IS NOT NULL', + 'ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk FOREIGN KEY (another_id) REFERENCES Another (id)', + 'CREATE OR REPLACE TRIGGER ai_Basic_id BEFORE INSERT ON Basic FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 ) BEGIN - SELECT sq_Basic_id01.nextval + SELECT sq_Basic_id.nextval INTO :new.id FROM dual; END; -/', - 'CREATE OR REPLACE TRIGGER ts_Basic_timest01 +', + 'CREATE OR REPLACE TRIGGER ts_Basic_timest BEFORE INSERT OR UPDATE ON Basic FOR EACH ROW WHEN (new.timest IS NULL) BEGIN SELECT sysdate INTO :new.timest FROM dual; END; -/', - 'CREATE OR REPLACE TRIGGER ai_Another_id01 +', + 'CREATE OR REPLACE TRIGGER ai_Another_id BEFORE INSERT ON Another FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 ) BEGIN - SELECT sq_Another_id01.nextval + SELECT sq_Another_id.nextval INTO :new.id FROM dual; END; -/']; +', +'CREATE INDEX titleindex on Basic (title)']; is_deeply(\@sql, $want, 'Got correct Oracle statements in list context'); is($sql_string, q|DROP TABLE Basic CASCADE CONSTRAINTS; -DROP SEQUENCE sq_Basic_id02; +DROP SEQUENCE sq_Basic_id01; -CREATE SEQUENCE sq_Basic_id02; +CREATE SEQUENCE sq_Basic_id01; CREATE TABLE Basic ( id number(10) NOT NULL, @@ -118,9 +119,9 @@ CREATE TABLE Basic ( DROP TABLE Another CASCADE CONSTRAINTS; -DROP SEQUENCE sq_Another_id02; +DROP SEQUENCE sq_Another_id01; -CREATE SEQUENCE sq_Another_id02; +CREATE SEQUENCE sq_Another_id01; CREATE TABLE Another ( id number(10) NOT NULL, @@ -130,106 +131,11 @@ CREATE TABLE Another ( CREATE VIEW email_list AS SELECT email FROM Basic WHERE email IS NOT NULL; -ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk02 FOREIGN KEY (another_id) REFERENCES Another (id); - -CREATE OR REPLACE TRIGGER ai_Basic_id02 -BEFORE INSERT ON Basic -FOR EACH ROW WHEN ( - new.id IS NULL OR new.id = 0 -) -BEGIN - SELECT sq_Basic_id02.nextval - INTO :new.id - FROM dual; -END; -/ - -CREATE OR REPLACE TRIGGER ts_Basic_timest02 -BEFORE INSERT OR UPDATE ON Basic -FOR EACH ROW WHEN (new.timest IS NULL) -BEGIN - SELECT sysdate INTO :new.timest FROM dual; -END; -/ - -CREATE OR REPLACE TRIGGER ai_Another_id02 -BEFORE INSERT ON Another -FOR EACH ROW WHEN ( - new.id IS NULL OR new.id = 0 -) -BEGIN - SELECT sq_Another_id02.nextval - INTO :new.id - FROM dual; -END; -/|); -#!/usr/bin/perl -use strict; - -use FindBin qw/$Bin/; -use Test::More; -use Test::SQL::Translator; -use Test::Exception; -use Data::Dumper; -use SQL::Translator; -use SQL::Translator::Schema::Constants; - -BEGIN { - maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy', - 'SQL::Translator::Producer::Oracle'); -} - -my $xmlfile = "$Bin/data/xml/schema.xml"; +ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk01 FOREIGN KEY (another_id) REFERENCES Another (id); -my $sqlt; -$sqlt = SQL::Translator->new( - no_comments => 1, - show_warnings => 1, - add_drop_table => 1, -); +CREATE INDEX titleindex01 on Basic (title); -die "Can't find test schema $xmlfile" unless -e $xmlfile; - -my @sql = $sqlt->translate( - from => 'XML-SQLFairy', - to => 'Oracle', - filename => $xmlfile, -) or die $sqlt->error; - -my $sql_string = $sqlt->translate( - from => 'XML-SQLFairy', - to => 'Oracle', - filename => $xmlfile, -) or die $sqlt->error; - -my $want = [ -'DROP TABLE Basic CASCADE CONSTRAINTS;', - 'DROP SEQUENCE sq_Basic_id01;', - 'CREATE SEQUENCE sq_Basic_id01;', - 'CREATE TABLE Basic ( - id number(10) NOT NULL, - title varchar2(100) DEFAULT \'hello\' NOT NULL, - description clob DEFAULT \'\', - email varchar2(255), - explicitnulldef varchar2, - explicitemptystring varchar2 DEFAULT \'\', - emptytagdef varchar2 DEFAULT \'\', - another_id number(10) DEFAULT \'2\', - timest date, - PRIMARY KEY (id), - CONSTRAINT emailuniqueindex UNIQUE (email) -);', - 'DROP TABLE Another CASCADE CONSTRAINTS;', - 'DROP SEQUENCE sq_Another_id01;', - 'CREATE SEQUENCE sq_Another_id01;', - 'CREATE TABLE Another ( - id number(10) NOT NULL, - PRIMARY KEY (id) -);', - 'CREATE VIEW email_list AS -SELECT email FROM Basic WHERE email IS NOT NULL;', - 'ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk01 FOREIGN KEY (another_id) REFERENCES Another (id);', - 'CREATE OR REPLACE TRIGGER ai_Basic_id01 +CREATE OR REPLACE TRIGGER ai_Basic_id01 BEFORE INSERT ON Basic FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 @@ -239,77 +145,9 @@ BEGIN INTO :new.id FROM dual; END; -/', - 'CREATE OR REPLACE TRIGGER ts_Basic_timest01 -BEFORE INSERT OR UPDATE ON Basic -FOR EACH ROW WHEN (new.timest IS NULL) -BEGIN - SELECT sysdate INTO :new.timest FROM dual; -END; -/', - 'CREATE OR REPLACE TRIGGER ai_Another_id01 -BEFORE INSERT ON Another -FOR EACH ROW WHEN ( - new.id IS NULL OR new.id = 0 -) -BEGIN - SELECT sq_Another_id01.nextval - INTO :new.id - FROM dual; -END; -/']; - -is_deeply(\@sql, $want, 'Got correct Oracle statements in list context'); - -is($sql_string, q|DROP TABLE Basic CASCADE CONSTRAINTS; - -DROP SEQUENCE sq_Basic_id02; - -CREATE SEQUENCE sq_Basic_id02; - -CREATE TABLE Basic ( - id number(10) NOT NULL, - title varchar2(100) DEFAULT 'hello' NOT NULL, - description clob DEFAULT '', - email varchar2(255), - explicitnulldef varchar2, - explicitemptystring varchar2 DEFAULT '', - emptytagdef varchar2 DEFAULT '', - another_id number(10) DEFAULT '2', - timest date, - PRIMARY KEY (id), - CONSTRAINT emailuniqueindex UNIQUE (email) -); - -DROP TABLE Another CASCADE CONSTRAINTS; - -DROP SEQUENCE sq_Another_id02; - -CREATE SEQUENCE sq_Another_id02; - -CREATE TABLE Another ( - id number(10) NOT NULL, - PRIMARY KEY (id) -); - -CREATE VIEW email_list AS -SELECT email FROM Basic WHERE email IS NOT NULL; - -ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk02 FOREIGN KEY (another_id) REFERENCES Another (id); - -CREATE OR REPLACE TRIGGER ai_Basic_id02 -BEFORE INSERT ON Basic -FOR EACH ROW WHEN ( - new.id IS NULL OR new.id = 0 -) -BEGIN - SELECT sq_Basic_id02.nextval - INTO :new.id - FROM dual; -END; / -CREATE OR REPLACE TRIGGER ts_Basic_timest02 +CREATE OR REPLACE TRIGGER ts_Basic_timest01 BEFORE INSERT OR UPDATE ON Basic FOR EACH ROW WHEN (new.timest IS NULL) BEGIN @@ -317,13 +155,13 @@ BEGIN END; / -CREATE OR REPLACE TRIGGER ai_Another_id02 +CREATE OR REPLACE TRIGGER ai_Another_id01 BEFORE INSERT ON Another FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 ) BEGIN - SELECT sq_Another_id02.nextval + SELECT sq_Another_id01.nextval INTO :new.id FROM dual; END;