more pg test cleanup
[dbsrgits/DBIx-Class-Historic.git] / t / 93autocast.t
CommitLineData
d047d650 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7use DBIC::SqlMakerTest;
8
9{ # Fake storage driver for sqlite with autocast
10 package DBICTest::SQLite::AutoCast;
11 use base qw/
12 DBIx::Class::Storage::DBI::AutoCast
13 DBIx::Class::Storage::DBI::SQLite
14 /;
15 use mro 'c3';
16
17 my $type_map = {
18 datetime => 'DateTime',
19 integer => 'INT',
20 int => undef, # no conversion
21 };
22
0bd2c1cd 23 sub _native_data_type {
d047d650 24 return $type_map->{$_[1]};
25 }
26}
27
28my $schema = DBICTest->init_schema (storage_type => 'DBICTest::SQLite::AutoCast');
29
30# 'me.id' will be cast unlike the unqualified 'id'
31my $rs = $schema->resultset ('CD')->search ({
32 cdid => { '>', 5 },
33 'tracks.last_updated_at' => { '!=', undef },
34 'tracks.last_updated_on' => { '<', 2009 },
35 'tracks.position' => 4,
a7741335 36 'tracks.single_track' => \[ '= ?', [ single_track => [1, 2, 3 ] ] ],
d047d650 37}, { join => 'tracks' });
38
a7741335 39my $bind = [
40 [ cdid => 5 ],
41 [ 'tracks.last_updated_on' => 2009 ],
42 [ 'tracks.position' => 4 ],
43 [ 'single_track' => [ 1, 2, 3] ],
44];
d047d650 45
46is_same_sql_bind (
47 $rs->as_query,
48 '(
49 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
50 FROM cd me
51 LEFT JOIN track tracks ON tracks.cd = me.cdid
52 WHERE
53 cdid > ?
54 AND tracks.last_updated_at IS NOT NULL
55 AND tracks.last_updated_on < ?
56 AND tracks.position = ?
a7741335 57 AND tracks.single_track = ?
d047d650 58 )',
59 $bind,
60 'expected sql with casting off',
61);
62
63$schema->storage->auto_cast (1);
64
65is_same_sql_bind (
66 $rs->as_query,
67 '(
68 SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
69 FROM cd me
70 LEFT JOIN track tracks ON tracks.cd = me.cdid
71 WHERE
72 cdid > CAST(? AS INT)
73 AND tracks.last_updated_at IS NOT NULL
74 AND tracks.last_updated_on < CAST (? AS yyy)
75 AND tracks.position = ?
a7741335 76 AND tracks.single_track = CAST(? AS INT)
d047d650 77 )',
78 $bind,
79 'expected sql with casting on',
80);
81
82done_testing;