todo ALL the things
[dbsrgits/DBIx-Class.git] / t / sqlmaker / core.t
CommitLineData
e5938571 1use strict;
2use warnings;
3
4use Test::More;
b2b22cd6 5use Test::Exception;
e5938571 6
d7571c64 7local $TODO = 'Temporarily todo-ed for dq2eb';
8
c61a0748 9use lib qw(t/lib);
5e724964 10use DBICTest;
c61a0748 11use DBIC::SqlMakerTest;
e5938571 12
f6a14bd4 13my $schema = DBICTest->init_schema(no_deploy => 1);
e5938571 14
15my $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 104my $file = quotemeta (__FILE__);
b2b22cd6 105throws_ok (sub {
106 $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query;
107}, qr/$file/, 'Exception correctly croak()ed');
f6a14bd4 108
109done_testing;