X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=xt%2Fclauses.t;h=85d002db2edc594b01f0fa3181f96059ff3e203e;hb=1601bb47472f6eb2ca3633935bbf3f3399e78604;hp=c6d301d426cbb08fbbbecb767bc034cc51cb024a;hpb=b1904bd59a11c1b362d2a8a3707dcb42e4625c23;p=scpubgit%2FQ-Branch.git diff --git a/xt/clauses.t b/xt/clauses.t index c6d301d..85d002d 100644 --- a/xt/clauses.t +++ b/xt/clauses.t @@ -2,9 +2,15 @@ use strict; use warnings; use Test::More; use SQL::Abstract::Test import => [ qw(is_same_sql_bind is_same_sql) ]; +use SQL::Abstract; use SQL::Abstract::ExtraClauses; -my $sqlac = SQL::Abstract::ExtraClauses->new(unknown_unop_always_func => 1); +my $sqlac = SQL::Abstract->new( + unknown_unop_always_func => 1, + lazy_join_sql_parts => 1, +); + +SQL::Abstract::ExtraClauses->apply_to($sqlac); is_deeply( [ $sqlac->statement_list ], @@ -423,4 +429,55 @@ is_same_sql_bind( )] ); +($sql, @bind) = $sqlac->update({ + _ => ['survey'], + set => { + license_id => { -ident => 'info.default_license_id' }, + }, + from => [ + -select => { + select => [qw( s.survey_id p.default_license_id p.person_id)], + from => [ + person => -as => 'p', + -join => { + to => 'class', + as => 'c', + on => { 'c.faculty_id' => 'p.person_id' }, + }, + -join => { + to => 'survey', + as => 's', + on => { 's.class_id' => 'c.class_id' }, + }, + ], + where => { 'p.institution_id' => { -value => 15031 } }, + }, + -as => 'info', + ], + where => { + 'info.survey_id' => { -ident => 'survey.survey_id' }, + } +}); + +is_same_sql_bind( + $sql, \@bind, + q{ + update survey + set license_id=info.default_license_id + from ( + select s.survey_id, p.default_license_id, p.person_id + from person AS p + join class AS c on c.faculty_id = p.person_id + join survey AS s on s.class_id = c.class_id + where p.institution_id = ? + ) AS info + where info.survey_id=survey.survey_id + }, + [qw( + 15031 + )] +); + + + done_testing;