Commit | Line | Data |
e5938571 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
b2b22cd6 |
5 | use Test::Exception; |
e5938571 |
6 | |
d7571c64 |
7 | local $TODO = 'Temporarily todo-ed for dq2eb'; |
8 | |
c61a0748 |
9 | use lib qw(t/lib); |
5e724964 |
10 | use DBICTest; |
c61a0748 |
11 | use DBIC::SqlMakerTest; |
e5938571 |
12 | |
f6a14bd4 |
13 | my $schema = DBICTest->init_schema(no_deploy => 1); |
e5938571 |
14 | |
15 | my $sql_maker = $schema->storage->sql_maker; |
16 | |
17 | |
20ea616f |
18 | { |
89479564 |
19 | my ($sql, @bind) = $sql_maker->insert( |
20 | 'lottery', |
21 | { |
22 | 'day' => '2008-11-16', |
23 | 'numbers' => [13, 21, 34, 55, 89] |
24 | } |
25 | ); |
26 | |
27 | is_same_sql_bind( |
28 | $sql, \@bind, |
29 | q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/, |
30 | [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], |
31 | 'sql_maker passes arrayrefs in insert' |
32 | ); |
33 | |
34 | |
35 | ($sql, @bind) = $sql_maker->update( |
36 | 'lottery', |
37 | { |
38 | 'day' => '2008-11-16', |
39 | 'numbers' => [13, 21, 34, 55, 89] |
40 | } |
41 | ); |
42 | |
43 | is_same_sql_bind( |
44 | $sql, \@bind, |
45 | q/UPDATE lottery SET day = ?, numbers = ?/, |
46 | [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], |
47 | 'sql_maker passes arrayrefs in update' |
48 | ); |
49 | } |
b2b22cd6 |
50 | |
f6a14bd4 |
51 | # make sure the cookbook caveat of { $op, \'...' } no longer applies |
52 | { |
53 | my ($sql, @bind) = $sql_maker->where({ |
54 | last_attempt => \ '< now() - interval "12 hours"', |
55 | next_attempt => { '<', \ 'now() - interval "12 hours"' }, |
56 | created => [ |
57 | { '<=', \ '1969' }, |
58 | \ '> 1984', |
59 | ], |
60 | }); |
61 | is_same_sql_bind( |
62 | $sql, |
63 | \@bind, |
64 | 'WHERE |
65 | (created <= 1969 OR created > 1984 ) |
66 | AND last_attempt < now() - interval "12 hours" |
67 | AND next_attempt < now() - interval "12 hours" |
68 | ', |
69 | [], |
70 | ); |
71 | } |
72 | |
8249c09b |
73 | # Tests base class for => \'FOO' actually generates proper query. for => |
74 | # 'READ'|'SHARE' is tested in db-specific subclasses |
75 | # we have to instantiate base because SQLMaker::SQLite disables _lock_select |
76 | { |
77 | require DBIx::Class::SQLMaker; |
78 | my $sa = DBIx::Class::SQLMaker->new; |
79 | { |
80 | my ($sql, @bind) = $sa->select('foo', '*', {}, { for => 'update' } ); |
81 | is_same_sql_bind( |
82 | $sql, |
83 | \@bind, |
84 | 'SELECT * FROM foo FOR UPDATE', |
85 | [], |
86 | ); |
87 | } |
88 | |
89 | { |
90 | my ($sql, @bind) = $sa->select('bar', '*', {}, { for => \'baz' } ); |
91 | is_same_sql_bind( |
92 | $sql, |
93 | \@bind, |
94 | 'SELECT * FROM bar FOR baz', |
95 | [], |
96 | ); |
97 | } |
98 | |
99 | } |
100 | |
101 | |
102 | |
d5dedbd6 |
103 | # Make sure the carp/croak override in SQLA works (via SQLMaker) |
8637bb24 |
104 | my $file = quotemeta (__FILE__); |
b2b22cd6 |
105 | throws_ok (sub { |
106 | $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query; |
107 | }, qr/$file/, 'Exception correctly croak()ed'); |
f6a14bd4 |
108 | |
109 | done_testing; |