7 use DBIC::SqlMakerTest;
9 { # Fake storage driver for sqlite with autocast
10 package DBICTest::SQLite::AutoCast;
12 DBIx::Class::Storage::DBI::AutoCast
13 DBIx::Class::Storage::DBI::SQLite
18 datetime => 'DateTime',
20 int => undef, # no conversion
23 sub _native_data_type {
24 return $type_map->{$_[1]};
28 my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::AutoCast');
30 # 'me.id' will be cast unlike the unqualified 'id'
31 my $rs = $schema->resultset ('CD')->search ({
33 'tracks.last_updated_at' => { '!=', undef },
34 'tracks.last_updated_on' => { '<', 2009 },
35 'tracks.position' => 4,
36 'tracks.single_track' => \[ '= ?', [ single_track => [1, 2, 3 ] ] ],
37 }, { join => 'tracks' });
41 [ 'tracks.last_updated_on' => 2009 ],
42 [ 'tracks.position' => 4 ],
43 [ 'single_track' => [ 1, 2, 3] ],
49 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
51 LEFT JOIN track tracks ON tracks.cd = me.cdid
54 AND tracks.last_updated_at IS NOT NULL
55 AND tracks.last_updated_on < ?
56 AND tracks.position = ?
57 AND tracks.single_track = ?
60 'expected sql with casting off',
63 $schema->storage->auto_cast (1);
68 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
70 LEFT JOIN track tracks ON tracks.cd = me.cdid
73 AND tracks.last_updated_at IS NOT NULL
74 AND tracks.last_updated_on < CAST (? AS yyy)
75 AND tracks.position = ?
76 AND tracks.single_track = CAST(? AS INT)
79 'expected sql with casting on',