Oracle sequence detection
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 14ora_common.t
1 use strict;
2 use lib qw(t/lib);
3 use dbixcsl_common_tests;
4 use Test::More;
5 use Test::Exception;
6
7 my $dsn      = $ENV{DBICTEST_ORA_DSN} || '';
8 my $user     = $ENV{DBICTEST_ORA_USER} || '';
9 my $password = $ENV{DBICTEST_ORA_PASS} || '';
10
11 my $tester = dbixcsl_common_tests->new(
12     vendor      => 'Oracle',
13     auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
14     auto_inc_cb => sub {
15         my ($table, $col) = @_;
16         return (
17             qq{ CREATE SEQUENCE ${table}_${col}_seq START WITH 1 INCREMENT BY 1},
18             qq{ 
19                 CREATE OR REPLACE TRIGGER ${table}_${col}_trigger
20                 BEFORE INSERT ON ${table}
21                 FOR EACH ROW
22                 BEGIN
23                     SELECT ${table}_${col}_seq.nextval INTO :NEW.${col} FROM dual;
24                 END;
25             }
26         );
27     },
28     auto_inc_drop_cb => sub {
29         my ($table, $col) = @_;
30         return qq{ DROP SEQUENCE ${table}_${col}_seq };
31     },
32     preserve_case_mode_is_exclusive => 1,
33     quote_char                      => '"',
34     dsn         => $dsn,
35     user        => $user,
36     password    => $password,
37     data_types  => {
38         # From:
39         # http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#i54330
40         #
41         # These tests require at least Oracle 9.2, because of the VARCHAR to
42         # VARCHAR2 casting.
43         #
44         # Character Types
45         'char'         => { data_type => 'char',      size => 1  },
46         'char(11)'     => { data_type => 'char',      size => 11 },
47         'nchar'        => { data_type => 'nchar',     size => 1  },
48         'nchar(11)'    => { data_type => 'nchar',     size => 11 },
49         'varchar(20)'  => { data_type => 'varchar2',  size => 20 },
50         'varchar2(20)' => { data_type => 'varchar2',  size => 20 },
51         'nvarchar2(20)'=> { data_type => 'nvarchar2', size => 20 },
52
53         # Numeric Types
54         #
55         # integer/decimal/numeric is alised to NUMBER
56         #
57         'integer'      => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
58         'int'          => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
59         'smallint'     => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
60
61         'decimal'      => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
62         'dec'          => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
63         'numeric'      => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
64
65         'decimal(3)'   => { data_type => 'numeric', size => [3,0], original => { data_type => 'number' } },
66         'dec(3)'       => { data_type => 'numeric', size => [3,0], original => { data_type => 'number' } },
67         'numeric(3)'   => { data_type => 'numeric', size => [3,0], original => { data_type => 'number' } },
68
69         'decimal(3,3)' => { data_type => 'numeric', size => [3,3], original => { data_type => 'number' } },
70         'dec(3,3)'     => { data_type => 'numeric', size => [3,3], original => { data_type => 'number' } },
71         'numeric(3,3)' => { data_type => 'numeric', size => [3,3], original => { data_type => 'number' } },
72
73         'binary_float'  => { data_type => 'real',             original => { data_type => 'binary_float'  } },
74         'binary_double' => { data_type => 'double precision', original => { data_type => 'binary_double' } },
75
76         # these are not mentioned in the summary chart, must be aliased
77         real            => { data_type => 'real',             original => { data_type => 'float', size => 63  } },
78         'float(63)'     => { data_type => 'real',             original => { data_type => 'float', size => 63  } },
79         'float(64)'     => { data_type => 'double precision', original => { data_type => 'float', size => 64  } },
80         'float(126)'    => { data_type => 'double precision', original => { data_type => 'float', size => 126 } },
81         float           => { data_type => 'double precision', original => { data_type => 'float', size => 126 } },
82
83         # Blob Types
84         'raw(50)'      => { data_type => 'raw', size => 50 },
85         'clob'         => { data_type => 'clob' },
86         'nclob'        => { data_type => 'nclob' },
87         'blob'         => { data_type => 'blob' },
88         'bfile'        => { data_type => 'bfile' },
89         'long'         => { data_type => 'long' },
90         'long raw'     => { data_type => 'long raw' },
91
92         # Datetime Types
93         'date'         => { data_type => 'datetime', original => { data_type => 'date' } },
94         'date default sysdate'
95                        => { data_type => 'datetime', default_value => \'current_timestamp',
96                             original  => { data_type => 'date', default_value => \'sysdate' } },
97         'timestamp'    => { data_type => 'timestamp' },
98         'timestamp default current_timestamp'
99                        => { data_type => 'timestamp', default_value => \'current_timestamp' },
100         'timestamp(3)' => { data_type => 'timestamp', size => 3 },
101         'timestamp with time zone'
102                        => { data_type => 'timestamp with time zone' },
103         'timestamp(3) with time zone'
104                        => { data_type => 'timestamp with time zone', size => 3 },
105         'timestamp with local time zone'
106                        => { data_type => 'timestamp with local time zone' },
107         'timestamp(3) with local time zone'
108                        => { data_type => 'timestamp with local time zone', size => 3 },
109         'interval year to month'
110                        => { data_type => 'interval year to month' },
111         'interval year(3) to month'
112                        => { data_type => 'interval year to month', size => 3 },
113         'interval day to second'
114                        => { data_type => 'interval day to second' },
115         'interval day(3) to second'
116                        => { data_type => 'interval day to second', size => [3,6] },
117         'interval day to second(3)'
118                        => { data_type => 'interval day to second', size => [2,3] },
119         'interval day(3) to second(3)'
120                        => { data_type => 'interval day to second', size => [3,3] },
121
122         # Other Types
123         'rowid'        => { data_type => 'rowid' },
124         'urowid'       => { data_type => 'urowid' },
125         'urowid(3333)' => { data_type => 'urowid', size => 3333 },
126     },
127     extra => {
128         count => 1,
129         run   => sub {
130             my ($schema, $monikers, $classes) = @_;
131
132             SKIP: {
133                 if (my $source = $monikers->{loader_test1s}) {
134                     is $schema->source($source)->column_info('id')->{sequence},
135                         'loader_test1s_id_seq',
136                         'Oracle sequence detection';
137                 }
138                 else {
139                     skip 1, 'not running common tests';
140                 }
141             }
142         },
143     },
144 );
145
146 if( !$dsn || !$user ) {
147     $tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
148 }
149 else {
150     $tester->run_tests();
151 }
152 # vim:et sw=4 sts=4 tw=0: