1use strict; 2use warnings; 3 4use Test::More; 5use Test::Exception; 6 7use lib qw(t/lib); 8use DBIC::SqlMakerTest; 9 10use_ok('DBICTest'); 11 12my $schema = DBICTest->init_schema(no_deploy => 1); 13 14my $sql_maker = $schema->storage->sql_maker; 15 16 17{ 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} 49 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 72# Make sure the carp/croak override in SQLA works (via SQLAHacks) 73my $file = quotemeta (__FILE__); 74throws_ok (sub { 75 $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query; 76}, qr/$file/, 'Exception correctly croak()ed'); 77 78done_testing; 79