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