4 use dbixcsl_common_tests;
6 eval { require DBD::SQLite };
7 my $class = $@ ? 'SQLite2' : 'SQLite';
9 my $tester = dbixcsl_common_tests->new(
11 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
12 dsn => "dbi:$class:dbname=./t/sqlite_test",
15 connect_info_opts => {
16 on_connect_do => 'PRAGMA foreign_keys = ON',
19 # SQLite ignores data types aside from INTEGER pks.
20 # We just test that they roundtrip sanely.
23 'smallint' => { data_type => 'smallint' },
24 'int' => { data_type => 'int' },
25 'integer' => { data_type => 'integer' },
27 # test that type name is lowercased
28 'INTEGER' => { data_type => 'integer' },
30 'bigint' => { data_type => 'bigint' },
31 'float' => { data_type => 'float' },
33 { data_type => 'double precision' },
34 'real' => { data_type => 'real' },
36 'float(2)' => { data_type => 'float', size => 2 },
37 'float(7)' => { data_type => 'float', size => 7 },
39 'decimal' => { data_type => 'decimal' },
40 'dec' => { data_type => 'dec' },
41 'numeric' => { data_type => 'numeric' },
43 'decimal(3)' => { data_type => 'decimal', size => 3 },
44 'numeric(3)' => { data_type => 'numeric', size => 3 },
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] },
51 'date' => { data_type => 'date' },
52 'timestamp DEFAULT CURRENT_TIMESTAMP'
53 => { data_type => 'timestamp', default_value => \'CURRENT_TIMESTAMP' },
54 'time' => { data_type => 'time' },
57 'char' => { data_type => 'char' },
58 'char(11)' => { data_type => 'char', size => 11 },
59 'varchar(20)' => { data_type => 'varchar', size => 20 },
63 # 'sqlite_' is reserved, so we use 'extra_'
65 CREATE TABLE "extra_loader_test1" (
66 "id" NOT NULL PRIMARY KEY,
67 "value" TEXT UNIQUE NOT NULL
71 CREATE TABLE extra_loader_test2 (
72 event_id INTEGER PRIMARY KEY
76 CREATE TABLE extra_loader_test3 (
77 person_id INTEGER PRIMARY KEY
80 # Wordy, newline-heavy SQL
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)
92 # make sure views are picked up
94 CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4
97 pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ],
98 drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
101 my ($schema, $monikers, $classes) = @_;
103 ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
104 'resultset for quoted table');
106 ok ((my $source = $rs->result_source), 'source');
108 is_deeply [ $source->columns ], [ qw/id value/ ],
109 'retrieved quoted column names from quoted table';
111 ok ((exists $source->column_info('value')->{is_nullable}),
112 'is_nullable exists');
114 is $source->column_info('value')->{is_nullable}, 0,
115 'is_nullable is set correctly';
117 ok (($source = $schema->source($monikers->{extra_loader_test4})),
120 is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
121 'composite primary key';
123 is ($source->relationships, 2,
124 '2 foreign key constraints found');
126 # test that columns for views are picked up
127 is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'integer',
128 'columns for views are introspected';
133 $tester->run_tests();
136 unlink './t/sqlite_test';