Commit | Line | Data |
a78e3fed |
1 | use strict; |
26334ec1 |
2 | use Test::More; |
c2849787 |
3 | use lib qw(t/lib); |
fbd83464 |
4 | use dbixcsl_common_tests; |
a78e3fed |
5 | |
9e978a19 |
6 | my $dsn = $ENV{DBICTEST_MYSQL_DSN} || ''; |
7 | my $user = $ENV{DBICTEST_MYSQL_USER} || ''; |
8 | my $password = $ENV{DBICTEST_MYSQL_PASS} || ''; |
9 | my $test_innodb = $ENV{DBICTEST_MYSQL_INNODB} || 0; |
a78e3fed |
10 | |
26334ec1 |
11 | my $skip_rels_msg = 'You need to set the DBICTEST_MYSQL_INNODB environment variable to test relationships.'; |
a78e3fed |
12 | |
fbd83464 |
13 | my $tester = dbixcsl_common_tests->new( |
52bf3f26 |
14 | vendor => 'Mysql', |
15 | auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT', |
16 | innodb => $test_innodb ? q{Engine=InnoDB} : 0, |
17 | dsn => $dsn, |
18 | user => $user, |
19 | password => $password, |
309e2aa1 |
20 | connect_info_opts=> { on_connect_call => 'set_strict_mode' }, |
eb040f78 |
21 | loader_options => { preserve_case => 1 }, |
8ff3a23a |
22 | skip_rels => $test_innodb ? 0 : $skip_rels_msg, |
6ebd0f33 |
23 | quote_char => '`', |
52bf3f26 |
24 | no_inline_rels => 1, |
25 | no_implicit_rels => 1, |
98857177 |
26 | data_types => { |
27 | # http://dev.mysql.com/doc/refman/5.5/en/data-type-overview.html |
28 | # Numeric Types |
26334ec1 |
29 | 'bit' => { data_type => 'bit', size => 1 }, |
30 | 'bit(11)' => { data_type => 'bit', size => 11 }, |
31 | |
32 | 'bool' => { data_type => 'tinyint' }, |
33 | 'boolean' => { data_type => 'tinyint' }, |
34 | 'tinyint' => { data_type => 'tinyint' }, |
35 | 'tinyint unsigned' |
36 | => { data_type => 'tinyint', extra => { unsigned => 1 } }, |
37 | 'smallint' => { data_type => 'smallint' }, |
38 | 'smallint unsigned' |
39 | => { data_type => 'smallint', extra => { unsigned => 1 } }, |
40 | 'mediumint' => { data_type => 'mediumint' }, |
41 | 'mediumint unsigned' |
42 | => { data_type => 'mediumint', extra => { unsigned => 1 } }, |
43 | 'int' => { data_type => 'integer' }, |
44 | 'int unsigned' |
45 | => { data_type => 'integer', extra => { unsigned => 1 } }, |
46 | 'integer' => { data_type => 'integer' }, |
47 | 'integer unsigned' |
48 | => { data_type => 'integer', extra => { unsigned => 1 } }, |
33aa3462 |
49 | 'integer not null' |
50 | => { data_type => 'integer' }, |
26334ec1 |
51 | 'bigint' => { data_type => 'bigint' }, |
52 | 'bigint unsigned' |
53 | => { data_type => 'bigint', extra => { unsigned => 1 } }, |
54 | |
55 | 'serial' => { data_type => 'bigint', is_auto_increment => 1, extra => { unsigned => 1 } }, |
56 | |
57 | 'float' => { data_type => 'float' }, |
58 | 'float unsigned' |
59 | => { data_type => 'float', extra => { unsigned => 1 } }, |
60 | 'double' => { data_type => 'double precision' }, |
61 | 'double unsigned' |
62 | => { data_type => 'double precision', extra => { unsigned => 1 } }, |
98857177 |
63 | 'double precision' => |
26334ec1 |
64 | { data_type => 'double precision' }, |
65 | 'double precision unsigned' |
66 | => { data_type => 'double precision', extra => { unsigned => 1 } }, |
67 | |
68 | # we skip 'real' because its alias depends on the 'REAL AS FLOAT' setting |
69 | |
70 | 'float(2)' => { data_type => 'float' }, |
71 | 'float(24)' => { data_type => 'float' }, |
72 | 'float(25)' => { data_type => 'double precision' }, |
73 | |
74 | 'float(3,3)' => { data_type => 'float', size => [3,3] }, |
75 | 'double(3,3)' => { data_type => 'double precision', size => [3,3] }, |
76 | 'double precision(3,3)' |
77 | => { data_type => 'double precision', size => [3,3] }, |
78 | |
79 | 'decimal' => { data_type => 'decimal' }, |
80 | 'decimal unsigned' |
81 | => { data_type => 'decimal', extra => { unsigned => 1 } }, |
82 | 'dec' => { data_type => 'decimal' }, |
83 | 'numeric' => { data_type => 'decimal' }, |
84 | 'fixed' => { data_type => 'decimal' }, |
85 | |
86 | 'decimal(3)' => { data_type => 'decimal', size => [3,0] }, |
87 | |
88 | 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, |
89 | 'dec(3,3)' => { data_type => 'decimal', size => [3,3] }, |
90 | 'numeric(3,3)' => { data_type => 'decimal', size => [3,3] }, |
91 | 'fixed(3,3)' => { data_type => 'decimal', size => [3,3] }, |
92 | |
98857177 |
93 | # Date and Time Types |
58333f16 |
94 | 'date' => { data_type => 'date', datetime_undef_if_invalid => 1 }, |
95 | 'datetime' => { data_type => 'datetime', datetime_undef_if_invalid => 1 }, |
6e566cc4 |
96 | 'timestamp default current_timestamp' |
58333f16 |
97 | => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 }, |
26334ec1 |
98 | 'time' => { data_type => 'time' }, |
99 | 'year' => { data_type => 'year' }, |
100 | 'year(4)' => { data_type => 'year' }, |
101 | 'year(2)' => { data_type => 'year', size => 2 }, |
102 | |
98857177 |
103 | # String Types |
26334ec1 |
104 | 'char' => { data_type => 'char', size => 1 }, |
105 | 'char(11)' => { data_type => 'char', size => 11 }, |
106 | 'varchar(20)' => { data_type => 'varchar', size => 20 }, |
107 | 'binary' => { data_type => 'binary', size => 1 }, |
108 | 'binary(11)' => { data_type => 'binary', size => 11 }, |
109 | 'varbinary(20)'=> { data_type => 'varbinary', size => 20 }, |
110 | |
111 | 'tinyblob' => { data_type => 'tinyblob' }, |
112 | 'tinytext' => { data_type => 'tinytext' }, |
113 | 'blob' => { data_type => 'blob' }, |
114 | |
115 | # text(M) types will map to the appropriate type, length is not stored |
116 | 'text' => { data_type => 'text' }, |
117 | |
118 | 'mediumblob' => { data_type => 'mediumblob' }, |
119 | 'mediumtext' => { data_type => 'mediumtext' }, |
120 | 'longblob' => { data_type => 'longblob' }, |
121 | 'longtext' => { data_type => 'longtext' }, |
122 | |
33aa3462 |
123 | "enum('foo','bar','baz')" |
26334ec1 |
124 | => { data_type => 'enum', extra => { list => [qw/foo bar baz/] } }, |
33aa3462 |
125 | "set('foo','bar','baz')" |
26334ec1 |
126 | => { data_type => 'set', extra => { list => [qw/foo bar baz/] } }, |
698c11d8 |
127 | |
128 | # RT#68717 |
129 | "enum('11,10 (<500)/0 DUN','4,90 (<120)/0 EUR') NOT NULL default '11,10 (<500)/0 DUN'" |
130 | => { data_type => 'enum', extra => { list => ['11,10 (<500)/0 DUN', '4,90 (<120)/0 EUR'] }, default_value => '11,10 (<500)/0 DUN' }, |
131 | "set('11_10 (<500)/0 DUN','4_90 (<120)/0 EUR') NOT NULL default '11_10 (<500)/0 DUN'" |
132 | => { data_type => 'set', extra => { list => ['11_10 (<500)/0 DUN', '4_90 (<120)/0 EUR'] }, default_value => '11_10 (<500)/0 DUN' }, |
133 | |
98857177 |
134 | }, |
3de915bc |
135 | extra => { |
136 | create => [ |
137 | q{ |
6ebd0f33 |
138 | CREATE TABLE `mysql_loader-test1` ( |
3de915bc |
139 | id INT AUTO_INCREMENT PRIMARY KEY, |
140 | value varchar(100) |
141 | ) |
142 | }, |
143 | q{ |
6ebd0f33 |
144 | CREATE VIEW mysql_loader_test2 AS SELECT * FROM `mysql_loader-test1` |
3de915bc |
145 | }, |
146 | ], |
147 | pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ], |
6ebd0f33 |
148 | drop => [ 'mysql_loader-test1', ], |
149 | count => 2, |
3de915bc |
150 | run => sub { |
151 | my ($schema, $monikers, $classes) = @_; |
152 | |
6ebd0f33 |
153 | is $monikers->{'mysql_loader-test1'}, 'MysqlLoaderTest1', |
154 | 'table with dash correctly monikerized'; |
155 | |
3de915bc |
156 | my $rsrc = $schema->resultset($monikers->{mysql_loader_test2})->result_source; |
157 | |
158 | is $rsrc->column_info('value')->{data_type}, 'varchar', |
159 | 'view introspected successfully'; |
160 | }, |
161 | }, |
a78e3fed |
162 | ); |
163 | |
9e978a19 |
164 | if( !$dsn || !$user ) { |
165 | $tester->skip_tests('You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS environment variables'); |
a78e3fed |
166 | } |
167 | else { |
26334ec1 |
168 | diag $skip_rels_msg if not $test_innodb; |
a78e3fed |
169 | $tester->run_tests(); |
170 | } |
26334ec1 |
171 | |
172 | # vim:et sts=4 sw=4 tw=0: |