d239569faab4d068a8138aad6a941fff800d363d
[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     dsn         => $dsn,
33     user        => $user,
34     password    => $password,
35     data_types  => {
36         # From:
37         # http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#i54330
38         #
39         # These tests require at least Oracle 9.2, because of the VARCHAR to
40         # VARCHAR2 casting.
41         #
42         # Character Types
43         'char'         => { data_type => 'char',      size => 1  },
44         'char(11)'     => { data_type => 'char',      size => 11 },
45         'nchar'        => { data_type => 'nchar',     size => 1  },
46         'nchar(11)'    => { data_type => 'nchar',     size => 11 },
47         'varchar(20)'  => { data_type => 'varchar2',  size => 20 },
48         'varchar2(20)' => { data_type => 'varchar2',  size => 20 },
49         'nvarchar2(20)'=> { data_type => 'nvarchar2', size => 20 },
50
51         # Numeric Types
52         #
53         # everything is alised to NUMBER
54         #
55         'decimal'      => { data_type => 'integer' },
56         'dec'          => { data_type => 'integer' },
57         'numeric'      => { data_type => 'integer' },
58
59         'decimal(3)'   => { data_type => 'numeric', size => [3,0] },
60         'dec(3)'       => { data_type => 'numeric', size => [3,0] },
61         'numeric(3)'   => { data_type => 'numeric', size => [3,0] },
62
63         'decimal(3,3)' => { data_type => 'numeric', size => [3,3] },
64         'dec(3,3)'     => { data_type => 'numeric', size => [3,3] },
65         'numeric(3,3)' => { data_type => 'numeric', size => [3,3] },
66
67         'integer'      => { data_type => 'integer' },
68         'int'          => { data_type => 'integer' },
69         'smallint'     => { data_type => 'integer' },
70
71         'binary_float'  => { data_type => 'binary_float' },
72         'binary_double' => { data_type => 'binary_double' },
73
74         # Blob Types
75         'raw(50)'      => { data_type => 'raw', size => 50 },
76         'clob'         => { data_type => 'clob' },
77         'nclob'        => { data_type => 'nclob' },
78         'blob'         => { data_type => 'blob' },
79         'bfile'        => { data_type => 'bfile' },
80         # these must be tested one at a time, can't have 2 longs in one table
81         # XXX add overrides to type tester to handle this
82 #        'long'         => { data_type => 'long' },
83         'long raw'     => { data_type => 'long raw' },
84
85         # Datetime Types
86         'date'         => { data_type => 'date' },
87         'date default sysdate'
88                        => { data_type => 'date', default_value => \'current_timestamp' },
89         'timestamp'    => { data_type => 'timestamp' },
90         'timestamp default current_timestamp'
91                        => { data_type => 'timestamp', default_value => \'current_timestamp' },
92         'timestamp(3)' => { data_type => 'timestamp', size => 3 },
93         'timestamp with time zone'
94                        => { data_type => 'timestamp with time zone' },
95         'timestamp(3) with time zone'
96                        => { data_type => 'timestamp with time zone', size => 3 },
97         'timestamp with local time zone'
98                        => { data_type => 'timestamp with local time zone' },
99         'timestamp(3) with local time zone'
100                        => { data_type => 'timestamp with local time zone', size => 3 },
101         'interval year to month'
102                        => { data_type => 'interval year to month' },
103         'interval year(3) to month'
104                        => { data_type => 'interval year to month', size => 3 },
105         'interval day to second'
106                        => { data_type => 'interval day to second' },
107         'interval day(3) to second'
108                        => { data_type => 'interval day to second', size => [3,6] },
109         'interval day to second(3)'
110                        => { data_type => 'interval day to second', size => [2,3] },
111         'interval day(3) to second(3)'
112                        => { data_type => 'interval day to second', size => [3,3] },
113
114         # Other Types
115         'rowid'        => { data_type => 'rowid' },
116         'urowid'       => { data_type => 'urowid' },
117         'urowid(3333)' => { data_type => 'urowid', size => 3333 },
118     },
119 );
120
121 if( !$dsn || !$user ) {
122     $tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
123 }
124 else {
125     $tester->run_tests();
126 }
127 # vim:et sw=4 sts=4 tw=0: