Backout teejay's changes to get trunk stable again
[dbsrgits/SQL-Translator.git] / t / 15oracle-parser.t
index 6377ad2..adce322 100644 (file)
@@ -5,17 +5,10 @@ use strict;
 use Test::More;
 use SQL::Translator;
 use SQL::Translator::Schema::Constants;
+use Test::SQL::Translator qw(maybe_plan);
 
-eval {
-    require SQL::Translator::Parser::Oracle;
-    SQL::Translator::Parser::Oracle->import('parse');
-};
-if ($@) {
-    plan skip_all => "$@";
-}
-else {
-    plan tests => 76;
-}
+maybe_plan(97, 'SQL::Translator::Parser::Oracle');
+SQL::Translator::Parser::Oracle->import('parse');
 
 my $t   = SQL::Translator->new( trace => 0 );
 my $sql = q[
@@ -26,7 +19,8 @@ my $sql = q[
         trait_category              VARCHAR2(100)   NOT NULL,
         UNIQUE ( trait_category )
     );
-    comment on table qtl_trait_category is 'hey, hey, hey, hey';
+    COMMENT ON TABLE qtl_trait_category IS 
+    'hey, hey, hey, hey';
     comment on column qtl_trait_category.qtl_trait_category_id 
         is 'the primary key!';
 
@@ -35,8 +29,8 @@ my $sql = q[
     (
         qtl_trait_id            NUMBER(11)      NOT NULL    
             CONSTRAINT pk_qtl_trait PRIMARY KEY,
-        trait_symbol            VARCHAR2(100)   NOT NULL,
-        trait_name              VARCHAR2(200)   NOT NULL,
+        trait_symbol            VARCHAR2(100 BYTE)   NOT NULL,
+        trait_name              VARCHAR2(200 CHAR)   NOT NULL,
         qtl_trait_category_id   NUMBER(11)      NOT NULL,
         UNIQUE ( trait_symbol ),
         UNIQUE ( trait_name ),
@@ -56,10 +50,13 @@ my $sql = q[
         start_position      NUMBER(11,2)    NOT NULL,
         stop_position       NUMBER(11,2)    NOT NULL,
         comments            long,
-        UNIQUE ( qtl_accession_id ),
         FOREIGN KEY ( qtl_trait_id ) REFERENCES qtl_trait
     );
 
+    CREATE UNIQUE INDEX qtl_accession ON qtl ( qtl_accession_id );
+    CREATE UNIQUE INDEX qtl_accession_upper ON qtl ( UPPER(qtl_accession_id) );
+    CREATE INDEX qtl_index ON qtl ( qtl_accession_id );
+
     CREATE TABLE qtl_trait_synonym
     (
         qtl_trait_synonym_id    NUMBER(11)      NOT NULL    
@@ -67,8 +64,48 @@ my $sql = q[
         trait_synonym           VARCHAR2(200)   NOT NULL,
         qtl_trait_id            NUMBER(11)      NOT NULL,
         UNIQUE( qtl_trait_id, trait_synonym ),
-        FOREIGN KEY ( qtl_trait_id ) REFERENCES qtl_trait
+        FOREIGN KEY ( qtl_trait_id ) REFERENCES qtl_trait ON DELETE SET NULL
     );
+
+-- View and procedure testing
+       CREATE OR REPLACE PROCEDURE CMDOMAIN_LATEST.P_24_HOUR_EVENT_SUMMARY
+       IS
+                   ldate                   varchar2(10);
+                   user_added              INT;
+                   user_deleted            INT;
+                   workingsets_created     INT;
+                   change_executed         INT;
+                   change_detected         INT;
+                   reports_run             INT;
+                   backup_complete         INT;
+                   backup_failed           INT;
+                   devices_in_inventory    INT;
+       
+       
+       BEGIN
+       
+                  select CAST(TO_CHAR(sysdate,'MM/DD/YYYY') AS varchar2(10))  INTO ldate  from  dual;
+       END;
+/
+       
+       CREATE OR REPLACE FORCE VIEW CMDOMAIN_MIG.VS_ASSET (ASSET_ID, FQ_NAME, FOLDER_NAME, ASSET_NAME, ANNOTATION, ASSET_TYPE, FOREIGN_ASSET_ID, FOREIGN_ASSET_ID2, DATE_CREATED, DATE_MODIFIED, CONTAINER_ID, CREATOR_ID, MODIFIER_ID, USER_ACCESS) AS
+         SELECT
+           a.asset_id, a.fq_name,
+           ap_extract_folder(a.fq_name) AS folder_name,
+           ap_extract_asset(a.fq_name)  AS asset_name,
+           a.annotation,
+           a.asset_type,
+           a.foreign_asset_id,
+           a.foreign_asset_id2,
+           a.dateCreated AS date_created,
+           a.dateModified AS date_modified,
+           a.container_id,
+           a.creator_id,
+           a.modifier_id,
+           m.user_id AS user_access
+       from asset a
+       JOIN M_ACCESS_CONTROL m on a.acl_id = m.acl_id;
+
 ];
 
 $| = 1;
@@ -211,7 +248,11 @@ my @t3_fields = $t3->get_fields;
 is( scalar @t3_fields, 8, '8 fields in table' );
 
 my @t3_constraints = $t3->get_constraints;
-is( scalar @t3_constraints, 3, '3 constraints on table' );
+is( scalar @t3_constraints, 4, '4 constraints on table' );
+my $t3_c4 = $t3_constraints[3];
+is( $t3_c4->type, UNIQUE, 'Fourth constraint is unique' );
+is( $t3_c4->name, 'qtl_accession_upper', 'Name = "qtl_accession_upper"' );
+is( join(',', $t3_c4->fields), 'UPPER(qtl_accession_id)', 'Fields = "UPPER(qtl_accession_id)"' );
 
 is( $t3->comments, 'qtl table comment', 'Comment "qtl table comment" exists' );
 
@@ -222,6 +263,14 @@ my $t3_f2     = shift @t3_fields;
 is( $t3_f2->comments, 'accession comment', 
     'Comment "accession comment" exists' );
 
+my @t3_indices = $t3->get_indices;
+is( scalar @t3_indices, 1, '1 index on table' );
+
+my $t3_i1 = shift @t3_indices;
+is( $t3_i1->type, 'NORMAL', 'First index is normal' );
+is( $t3_i1->name, 'qtl_index', 'Name is "qtl_index"' );
+is( join(',', $t3_i1->fields), 'qtl_accession_id', 'Fields = "qtl_accession_id"' );
+
 #
 # qtl_trait_synonym
 #
@@ -233,3 +282,28 @@ is( scalar @t4_fields, 3, '3 fields in table' );
 
 my @t4_constraints = $t4->get_constraints;
 is( scalar @t4_constraints, 3, '3 constraints on table' );
+my $t4_c3 = $t4_constraints[2];
+is( $t4_c3->type, FOREIGN_KEY, 'Third constraint is FK' );
+is( $t4_c3->name, '', 'No name' );
+is( join(',', $t4_c3->fields), 'qtl_trait_id', 
+    'Fields = "qtl_trait_id"' );
+is( $t4_c3->reference_table, 'qtl_trait', 
+    'Reference table = "qtl_trait"' );
+is( join(',', $t4_c3->reference_fields), 'qtl_trait_id', 
+    'Reference fields = "qtl_trait_id"' );
+is( $t4_c3->on_delete, 'SET NULL', 
+    'on_delete = "SET NULL"' );
+
+my @views = $schema->get_views;
+is( scalar @views, 1, 'Right number of views (1)' );
+my $view1 = shift @views;
+is( $view1->name, 'VS_ASSET', 'Found "VS_ASSET" view' );
+like($view1->sql, qr/VS_ASSET/, "Detected view VS_ASSET");
+unlike($view1->sql, qr/CMDOMAIN_MIG/, "Did not detect CMDOMAIN_MIG");
+    
+my @procs = $schema->get_procedures;
+is( scalar @procs, 1, 'Right number of procedures (1)' );
+my $proc1 = shift @procs;
+is( $proc1->name, 'P_24_HOUR_EVENT_SUMMARY', 'Found "P_24_HOUR_EVENT_SUMMARY" procedure' );
+like($proc1->sql, qr/P_24_HOUR_EVENT_SUMMARY/, "Detected procedure P_24_HOUR_EVENT_SUMMARY");
+unlike($proc1->sql, qr/CMDOMAIN_MIG/, "Did not detect CMDOMAIN_MIG");