Commit | Line | Data |
a78e3fed |
1 | use strict; |
8763ffda |
2 | use Test::More; |
c2849787 |
3 | use lib qw(t/lib); |
fbd83464 |
4 | use dbixcsl_common_tests; |
a78e3fed |
5 | |
6 | eval { require DBD::SQLite }; |
7 | my $class = $@ ? 'SQLite2' : 'SQLite'; |
8 | |
8763ffda |
9 | my $tester = dbixcsl_common_tests->new( |
10 | vendor => 'SQLite', |
11 | auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT', |
12 | dsn => "dbi:$class:dbname=./t/sqlite_test", |
13 | user => '', |
14 | password => '', |
b308dcca |
15 | connect_info_opts => { |
16 | on_connect_do => 'PRAGMA foreign_keys = ON', |
17 | }, |
eb040f78 |
18 | loader_options => { preserve_case => 1 }, |
62bc1e5d |
19 | data_types => { |
20 | # SQLite ignores data types aside from INTEGER pks. |
21 | # We just test that they roundtrip sanely. |
22 | # |
23 | # Numeric types |
24 | 'smallint' => { data_type => 'smallint' }, |
25 | 'int' => { data_type => 'int' }, |
26 | 'integer' => { data_type => 'integer' }, |
bc1cb85e |
27 | |
28 | # test that type name is lowercased |
29 | 'INTEGER' => { data_type => 'integer' }, |
30 | |
62bc1e5d |
31 | 'bigint' => { data_type => 'bigint' }, |
32 | 'float' => { data_type => 'float' }, |
33 | 'double precision' => |
34 | { data_type => 'double precision' }, |
35 | 'real' => { data_type => 'real' }, |
36 | |
37 | 'float(2)' => { data_type => 'float', size => 2 }, |
38 | 'float(7)' => { data_type => 'float', size => 7 }, |
39 | |
40 | 'decimal' => { data_type => 'decimal' }, |
41 | 'dec' => { data_type => 'dec' }, |
42 | 'numeric' => { data_type => 'numeric' }, |
43 | |
44 | 'decimal(3)' => { data_type => 'decimal', size => 3 }, |
45 | 'numeric(3)' => { data_type => 'numeric', size => 3 }, |
46 | |
47 | 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, |
48 | 'dec(3,3)' => { data_type => 'dec', size => [3,3] }, |
49 | 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] }, |
50 | |
51 | # Date and Time Types |
52 | 'date' => { data_type => 'date' }, |
53 | 'timestamp DEFAULT CURRENT_TIMESTAMP' |
54 | => { data_type => 'timestamp', default_value => \'CURRENT_TIMESTAMP' }, |
55 | 'time' => { data_type => 'time' }, |
56 | |
57 | # String Types |
58 | 'char' => { data_type => 'char' }, |
59 | 'char(11)' => { data_type => 'char', size => 11 }, |
60 | 'varchar(20)' => { data_type => 'varchar', size => 20 }, |
61 | }, |
8763ffda |
62 | extra => { |
63 | create => [ |
64 | # 'sqlite_' is reserved, so we use 'extra_' |
65 | q{ |
66 | CREATE TABLE "extra_loader_test1" ( |
67 | "id" NOT NULL PRIMARY KEY, |
2a6dfbc9 |
68 | "value" TEXT UNIQUE NOT NULL |
8763ffda |
69 | ) |
68d650df |
70 | }, |
71 | q{ |
72 | CREATE TABLE extra_loader_test2 ( |
73 | event_id INTEGER PRIMARY KEY |
74 | ) |
75 | }, |
76 | q{ |
77 | CREATE TABLE extra_loader_test3 ( |
78 | person_id INTEGER PRIMARY KEY |
79 | ) |
80 | }, |
26da4cc3 |
81 | # Wordy, newline-heavy SQL |
68d650df |
82 | q{ |
83 | CREATE TABLE extra_loader_test4 ( |
84 | event_id INTEGER NOT NULL |
85 | CONSTRAINT fk_event_id |
86 | REFERENCES extra_loader_test2(event_id), |
87 | person_id INTEGER NOT NULL |
88 | CONSTRAINT fk_person_id |
89 | REFERENCES extra_loader_test3 (person_id), |
90 | PRIMARY KEY (event_id, person_id) |
91 | ) |
92 | }, |
26da4cc3 |
93 | # make sure views are picked up |
94 | q{ |
95 | CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4 |
96 | } |
8763ffda |
97 | ], |
26da4cc3 |
98 | pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ], |
68d650df |
99 | drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ], |
bf558f72 |
100 | count => 9, |
8763ffda |
101 | run => sub { |
102 | my ($schema, $monikers, $classes) = @_; |
a78e3fed |
103 | |
8763ffda |
104 | ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})), |
105 | 'resultset for quoted table'); |
106 | |
0fa48bf5 |
107 | ok ((my $source = $rs->result_source), 'source'); |
108 | |
109 | is_deeply [ $source->columns ], [ qw/id value/ ], |
8763ffda |
110 | 'retrieved quoted column names from quoted table'; |
68d650df |
111 | |
3b134b29 |
112 | ok ((exists $source->column_info('value')->{is_nullable}), |
113 | 'is_nullable exists'); |
114 | |
0fa48bf5 |
115 | is $source->column_info('value')->{is_nullable}, 0, |
3b134b29 |
116 | 'is_nullable is set correctly'; |
0fa48bf5 |
117 | |
118 | ok (($source = $schema->source($monikers->{extra_loader_test4})), |
68d650df |
119 | 'verbose table'); |
120 | |
121 | is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ], |
122 | 'composite primary key'; |
123 | |
68d650df |
124 | is ($source->relationships, 2, |
125 | '2 foreign key constraints found'); |
126 | |
bf558f72 |
127 | # test that columns for views are picked up |
00805149 |
128 | is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'integer', |
bf558f72 |
129 | 'columns for views are introspected'; |
8763ffda |
130 | }, |
131 | }, |
132 | ); |
133 | |
134 | $tester->run_tests(); |
a78e3fed |
135 | |
136 | END { |
137 | unlink './t/sqlite_test'; |
138 | } |