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',
20 # 'sqlite_' is reserved, so we use 'extra_'
22 CREATE TABLE "extra_loader_test1" (
23 "id" NOT NULL PRIMARY KEY,
24 "value" TEXT UNIQUE NOT NULL
28 CREATE TABLE extra_loader_test2 (
29 event_id INTEGER PRIMARY KEY
33 CREATE TABLE extra_loader_test3 (
34 person_id INTEGER PRIMARY KEY
37 # Wordy, newline-heavy SQL
39 CREATE TABLE extra_loader_test4 (
40 event_id INTEGER NOT NULL
41 CONSTRAINT fk_event_id
42 REFERENCES extra_loader_test2(event_id),
43 person_id INTEGER NOT NULL
44 CONSTRAINT fk_person_id
45 REFERENCES extra_loader_test3 (person_id),
46 PRIMARY KEY (event_id, person_id)
49 # make sure views are picked up
51 CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4
54 pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ],
55 drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
58 my ($schema, $monikers, $classes) = @_;
60 ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
61 'resultset for quoted table');
63 ok ((my $source = $rs->result_source), 'source');
65 is_deeply [ $source->columns ], [ qw/id value/ ],
66 'retrieved quoted column names from quoted table';
68 ok ((exists $source->column_info('value')->{is_nullable}),
69 'is_nullable exists');
71 is $source->column_info('value')->{is_nullable}, 0,
72 'is_nullable is set correctly';
74 ok (($source = $schema->source($monikers->{extra_loader_test4})),
77 is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
78 'composite primary key';
80 is ($source->relationships, 2,
81 '2 foreign key constraints found');
83 # test that columns for views are picked up
84 is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'integer',
85 'columns for views are introspected';
93 unlink './t/sqlite_test';