8 { # Fake storage driver for sqlite with autocast
9 package DBICTest::SQLite::AutoCast;
11 DBIx::Class::Storage::DBI::AutoCast
12 DBIx::Class::Storage::DBI::SQLite
17 datetime => 'DateTime',
19 int => undef, # no conversion
22 sub _native_data_type {
23 return $type_map->{$_[1]};
27 my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::AutoCast');
29 # 'me.id' will be cast unlike the unqualified 'id'
30 my $rs = $schema->resultset ('CD')->search ({
32 'tracks.last_updated_at' => { '!=', undef },
33 'tracks.last_updated_on' => { '<', 2009 },
34 'tracks.position' => 4,
35 'me.single_track' => \[ '= ?', [ single_track => 1 ] ],
36 }, { join => 'tracks' });
39 [ { dbic_colname => "cdid", sqlt_datatype => "integer" }
41 [ { dbic_colname => "single_track", sqlt_datatype => "integer" }
43 [ { dbic_colname => "tracks.last_updated_on", sqlt_datatype => "datetime" }
45 [ { dbic_colname => "tracks.position", sqlt_datatype => "int" }
49 $schema->is_executed_sql_bind( sub { $rs->all }, [[
51 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
53 LEFT JOIN track tracks ON tracks.cd = me.cdid
56 AND me.single_track = ?
57 AND tracks.last_updated_at IS NOT NULL
58 AND tracks.last_updated_on < ?
59 AND tracks.position = ?
62 ]], 'expected sql with casting off' );
64 $schema->storage->auto_cast (1);
66 $schema->is_executed_sql_bind( sub { $rs->all }, [[
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 me.single_track = CAST(? AS INT)
74 AND tracks.last_updated_at IS NOT NULL
75 AND tracks.last_updated_on < CAST (? AS DateTime)
76 AND tracks.position = ?
79 ]], 'expected sql with casting on' );