Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/SQL/Abstract/More.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/};

Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions t/01-sql_abstract_more.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down