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