7 use DBIC::SqlMakerTest;
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 my $debugobj = DBIC::DebugObj->new (\$sql, \@bind);
42 my $storage = $schema->storage;
43 my ($orig_debug, $orig_debugobj) = ($storage->debug, $storage->debugobj);
44 $storage->debugobj ($debugobj);
47 # the quoting is a debugobj thing, not dbic-internals
48 my $bind = [ map { "'$_'" } qw/
57 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
59 LEFT JOIN track tracks ON tracks.cd = me.cdid
62 AND me.single_track = ?
63 AND tracks.last_updated_at IS NOT NULL
64 AND tracks.last_updated_on < ?
65 AND tracks.position = ?
68 'expected sql with casting off',
71 $schema->storage->auto_cast (1);
78 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
80 LEFT JOIN track tracks ON tracks.cd = me.cdid
83 AND me.single_track = CAST(? AS INT)
84 AND tracks.last_updated_at IS NOT NULL
85 AND tracks.last_updated_on < CAST (? AS DateTime)
86 AND tracks.position = ?
89 'expected sql with casting on',
92 $storage->debugobj ($orig_debugobj);
93 $storage->debug ($orig_debug);