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' }, |
8ff3a23a |
21 | skip_rels => $test_innodb ? 0 : $skip_rels_msg, |
52bf3f26 |
22 | no_inline_rels => 1, |
23 | no_implicit_rels => 1, |
98857177 |
24 | data_types => { |
25 | # http://dev.mysql.com/doc/refman/5.5/en/data-type-overview.html |
26 | # Numeric Types |
26334ec1 |
27 | 'bit' => { data_type => 'bit', size => 1 }, |
28 | 'bit(11)' => { data_type => 'bit', size => 11 }, |
29 | |
30 | 'bool' => { data_type => 'tinyint' }, |
31 | 'boolean' => { data_type => 'tinyint' }, |
32 | 'tinyint' => { data_type => 'tinyint' }, |
33 | 'tinyint unsigned' |
34 | => { data_type => 'tinyint', extra => { unsigned => 1 } }, |
35 | 'smallint' => { data_type => 'smallint' }, |
36 | 'smallint unsigned' |
37 | => { data_type => 'smallint', extra => { unsigned => 1 } }, |
38 | 'mediumint' => { data_type => 'mediumint' }, |
39 | 'mediumint unsigned' |
40 | => { data_type => 'mediumint', extra => { unsigned => 1 } }, |
41 | 'int' => { data_type => 'integer' }, |
42 | 'int unsigned' |
43 | => { data_type => 'integer', extra => { unsigned => 1 } }, |
44 | 'integer' => { data_type => 'integer' }, |
45 | 'integer unsigned' |
46 | => { data_type => 'integer', extra => { unsigned => 1 } }, |
47 | 'bigint' => { data_type => 'bigint' }, |
48 | 'bigint unsigned' |
49 | => { data_type => 'bigint', extra => { unsigned => 1 } }, |
50 | |
51 | 'serial' => { data_type => 'bigint', is_auto_increment => 1, extra => { unsigned => 1 } }, |
52 | |
53 | 'float' => { data_type => 'float' }, |
54 | 'float unsigned' |
55 | => { data_type => 'float', extra => { unsigned => 1 } }, |
56 | 'double' => { data_type => 'double precision' }, |
57 | 'double unsigned' |
58 | => { data_type => 'double precision', extra => { unsigned => 1 } }, |
98857177 |
59 | 'double precision' => |
26334ec1 |
60 | { data_type => 'double precision' }, |
61 | 'double precision unsigned' |
62 | => { data_type => 'double precision', extra => { unsigned => 1 } }, |
63 | |
64 | # we skip 'real' because its alias depends on the 'REAL AS FLOAT' setting |
65 | |
66 | 'float(2)' => { data_type => 'float' }, |
67 | 'float(24)' => { data_type => 'float' }, |
68 | 'float(25)' => { data_type => 'double precision' }, |
69 | |
70 | 'float(3,3)' => { data_type => 'float', size => [3,3] }, |
71 | 'double(3,3)' => { data_type => 'double precision', size => [3,3] }, |
72 | 'double precision(3,3)' |
73 | => { data_type => 'double precision', size => [3,3] }, |
74 | |
75 | 'decimal' => { data_type => 'decimal' }, |
76 | 'decimal unsigned' |
77 | => { data_type => 'decimal', extra => { unsigned => 1 } }, |
78 | 'dec' => { data_type => 'decimal' }, |
79 | 'numeric' => { data_type => 'decimal' }, |
80 | 'fixed' => { data_type => 'decimal' }, |
81 | |
82 | 'decimal(3)' => { data_type => 'decimal', size => [3,0] }, |
83 | |
84 | 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, |
85 | 'dec(3,3)' => { data_type => 'decimal', size => [3,3] }, |
86 | 'numeric(3,3)' => { data_type => 'decimal', size => [3,3] }, |
87 | 'fixed(3,3)' => { data_type => 'decimal', size => [3,3] }, |
88 | |
98857177 |
89 | # Date and Time Types |
26334ec1 |
90 | 'date' => { data_type => 'date' }, |
91 | 'datetime' => { data_type => 'datetime' }, |
92 | 'timestamp DEFAULT current_timestamp' |
93 | => { data_type => 'timestamp', default_value => \"CURRENT_TIMESTAMP" }, |
94 | 'time' => { data_type => 'time' }, |
95 | 'year' => { data_type => 'year' }, |
96 | 'year(4)' => { data_type => 'year' }, |
97 | 'year(2)' => { data_type => 'year', size => 2 }, |
98 | |
98857177 |
99 | # String Types |
26334ec1 |
100 | 'char' => { data_type => 'char', size => 1 }, |
101 | 'char(11)' => { data_type => 'char', size => 11 }, |
102 | 'varchar(20)' => { data_type => 'varchar', size => 20 }, |
103 | 'binary' => { data_type => 'binary', size => 1 }, |
104 | 'binary(11)' => { data_type => 'binary', size => 11 }, |
105 | 'varbinary(20)'=> { data_type => 'varbinary', size => 20 }, |
106 | |
107 | 'tinyblob' => { data_type => 'tinyblob' }, |
108 | 'tinytext' => { data_type => 'tinytext' }, |
109 | 'blob' => { data_type => 'blob' }, |
110 | |
111 | # text(M) types will map to the appropriate type, length is not stored |
112 | 'text' => { data_type => 'text' }, |
113 | |
114 | 'mediumblob' => { data_type => 'mediumblob' }, |
115 | 'mediumtext' => { data_type => 'mediumtext' }, |
116 | 'longblob' => { data_type => 'longblob' }, |
117 | 'longtext' => { data_type => 'longtext' }, |
118 | |
119 | "enum('foo', 'bar', 'baz')" |
120 | => { data_type => 'enum', extra => { list => [qw/foo bar baz/] } }, |
121 | "set('foo', 'bar', 'baz')" |
122 | => { data_type => 'set', extra => { list => [qw/foo bar baz/] } }, |
98857177 |
123 | }, |
3de915bc |
124 | extra => { |
125 | create => [ |
126 | q{ |
127 | CREATE TABLE mysql_loader_test1 ( |
128 | id INT AUTO_INCREMENT PRIMARY KEY, |
129 | value varchar(100) |
130 | ) |
131 | }, |
132 | q{ |
133 | CREATE VIEW mysql_loader_test2 AS SELECT * FROM mysql_loader_test1 |
134 | }, |
135 | ], |
136 | pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ], |
137 | drop => [ 'mysql_loader_test1', ], |
138 | count => 1, |
139 | run => sub { |
140 | my ($schema, $monikers, $classes) = @_; |
141 | |
142 | my $rsrc = $schema->resultset($monikers->{mysql_loader_test2})->result_source; |
143 | |
144 | is $rsrc->column_info('value')->{data_type}, 'varchar', |
145 | 'view introspected successfully'; |
146 | }, |
147 | }, |
a78e3fed |
148 | ); |
149 | |
9e978a19 |
150 | if( !$dsn || !$user ) { |
151 | $tester->skip_tests('You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS environment variables'); |
a78e3fed |
152 | } |
153 | else { |
26334ec1 |
154 | diag $skip_rels_msg if not $test_innodb; |
a78e3fed |
155 | $tester->run_tests(); |
156 | } |
26334ec1 |
157 | |
158 | # vim:et sts=4 sw=4 tw=0: |