diff --git a/lib/SQL/Abstract/More.pm b/lib/SQL/Abstract/More.pm index db3d6c9..98556ab 100644 --- a/lib/SQL/Abstract/More.pm +++ b/lib/SQL/Abstract/More.pm @@ -883,7 +883,10 @@ sub update { # compute join info if the datasource is a join $join_info = $self->_compute_join_info($args{-table}); - $args{-table} = \($join_info->{sql}) if $join_info; + $args{-table} = + defined $join_info + ? \($join_info->{sql}) + : \($self->_parse_table( $args{-table})->{sql}); @old_API_args = @args{qw/-table -set -where/}; @@ -897,6 +900,7 @@ sub update { } # call parent method and merge with bind values from $join_info + my ($sql, @bind) = $self->_parent_update(@old_API_args); unshift @bind, @{$join_info->{bind}} if $join_info; @@ -938,6 +942,8 @@ sub delete { @old_API_args = @_; } + $old_API_args[0] = \($self->_parse_table( $old_API_args[0] )->{sql}); + # call parent method my ($sql, @bind) = $self->next::method(@old_API_args); diff --git a/t/01-sql_abstract_more.t b/t/01-sql_abstract_more.t index f47466b..679bd93 100644 --- a/t/01-sql_abstract_more.t +++ b/t/01-sql_abstract_more.t @@ -945,6 +945,17 @@ is_same_sql_bind( [2, 1, 3], ); +# support for table aliases +($sql, @bind) = $sqla->update( + -table => 'Foo|a', + -set => {foo => 1, bar => 2}, + -where => {buz => 3}, +); +is_same_sql_bind( + $sql, \@bind, + 'UPDATE Foo SET bar = ?, foo = ? WHERE buz = ?', + [2, 1, 3], +); # MySQL supports -limit and -order_by in updates ! # see http://dev.mysql.com/doc/refman/5.6/en/update.html @@ -1054,6 +1065,17 @@ is_same_sql_bind( [3], ); +# support for table aliases +($sql, @bind) = $sqla->delete( + -from => 'Foo|a', + -where => {buz => 3}, +); +is_same_sql_bind( + $sql, \@bind, + 'DELETE FROM Foo AS a WHERE buz = ?', + [3], +); + # MySQL supports -limit and -order_by in deletes ! # see http://dev.mysql.com/doc/refman/5.6/en/delete.html ($sql, @bind) = $sqla->delete(