1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 { # Fake storage driver for sqlite with autocast
11 package DBICTest::SQLite::AutoCast;
13 DBIx::Class::Storage::DBI::AutoCast
14 DBIx::Class::Storage::DBI::SQLite
19 datetime => 'DateTime',
21 int => undef, # no conversion
24 sub _native_data_type {
25 return $type_map->{$_[1]};
29 my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::AutoCast');
31 # 'me.id' will be cast unlike the unqualified 'id'
32 my $rs = $schema->resultset ('CD')->search ({
34 'tracks.last_updated_at' => { '!=', undef },
35 'tracks.last_updated_on' => { '<', 2009 },
36 'tracks.position' => 4,
37 'me.single_track' => \[ '= ?', [ single_track => 1 ] ],
38 }, { join => 'tracks' });
41 [ { dbic_colname => "cdid", sqlt_datatype => "integer" }
43 [ { dbic_colname => "single_track", sqlt_datatype => "integer" }
45 [ { dbic_colname => "tracks.last_updated_on", sqlt_datatype => "datetime" }
47 [ { dbic_colname => "tracks.position", sqlt_datatype => "int" }
51 $schema->is_executed_sql_bind( sub { $rs->all }, [[
53 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
55 LEFT JOIN track tracks ON tracks.cd = me.cdid
58 AND me.single_track = ?
59 AND tracks.last_updated_at IS NOT NULL
60 AND tracks.last_updated_on < ?
61 AND tracks.position = ?
64 ]], 'expected sql with casting off' );
66 $schema->storage->auto_cast (1);
68 $schema->is_executed_sql_bind( sub { $rs->all }, [[
70 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
72 LEFT JOIN track tracks ON tracks.cd = me.cdid
75 AND me.single_track = CAST(? AS INT)
76 AND tracks.last_updated_at IS NOT NULL
77 AND tracks.last_updated_on < CAST (? AS DateTime)
78 AND tracks.position = ?
81 ]], 'expected sql with casting on' );