Some cleanup
[dbsrgits/DBIx-Class.git] / t / 95sql_maker.t
CommitLineData
e5938571 1use strict;
2use warnings;
3
4use Test::More;
b2b22cd6 5use Test::Exception;
e5938571 6
c61a0748 7use lib qw(t/lib);
8use DBIC::SqlMakerTest;
e5938571 9
e5938571 10use_ok('DBICTest');
11
f6a14bd4 12my $schema = DBICTest->init_schema(no_deploy => 1);
e5938571 13
14my $sql_maker = $schema->storage->sql_maker;
15
16
20ea616f 17{
89479564 18 my ($sql, @bind) = $sql_maker->insert(
19 'lottery',
20 {
21 'day' => '2008-11-16',
22 'numbers' => [13, 21, 34, 55, 89]
23 }
24 );
25
26 is_same_sql_bind(
27 $sql, \@bind,
28 q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/,
29 [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
30 'sql_maker passes arrayrefs in insert'
31 );
32
33
34 ($sql, @bind) = $sql_maker->update(
35 'lottery',
36 {
37 'day' => '2008-11-16',
38 'numbers' => [13, 21, 34, 55, 89]
39 }
40 );
41
42 is_same_sql_bind(
43 $sql, \@bind,
44 q/UPDATE lottery SET day = ?, numbers = ?/,
45 [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
46 'sql_maker passes arrayrefs in update'
47 );
48}
b2b22cd6 49
f6a14bd4 50# make sure the cookbook caveat of { $op, \'...' } no longer applies
51{
52 my ($sql, @bind) = $sql_maker->where({
53 last_attempt => \ '< now() - interval "12 hours"',
54 next_attempt => { '<', \ 'now() - interval "12 hours"' },
55 created => [
56 { '<=', \ '1969' },
57 \ '> 1984',
58 ],
59 });
60 is_same_sql_bind(
61 $sql,
62 \@bind,
63 'WHERE
64 (created <= 1969 OR created > 1984 )
65 AND last_attempt < now() - interval "12 hours"
66 AND next_attempt < now() - interval "12 hours"
67 ',
68 [],
69 );
70}
71
b2b22cd6 72# Make sure the carp/croak override in SQLA works (via SQLAHacks)
73my $file = __FILE__;
51a05c99 74$file = "\Q$file\E";
b2b22cd6 75throws_ok (sub {
76 $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query;
77}, qr/$file/, 'Exception correctly croak()ed');
f6a14bd4 78
79done_testing;