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 ],
)]
);
+($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;