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