Skip to content

Commit 5228110

Browse files
djeriusalranel
authored andcommitted
bugfix: table alias failed for update & delete if SQLA's quote_char was set.
Prior to version 1.44 of SQL::Abstract::More, specifying a table alias as "$table_name|$table_alias" was supported only for select, not for delete or update. DBIx::Lite worked around this by calling SQLA::M's table_alias method, which returns a string of "$table_name as $table_alias" If SQLA's quote_char option is set, this entire construct is quoted, rather than just $table_name, leading to illegal SQL. This commit will use the "$name|$alias" form if SQLA::M is version 1.44 or higher.
1 parent 1bf2cd1 commit 5228110

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎lib/DBIx/Lite/ResultSet.pm‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use Carp qw(croak);
66
use Clone qw(clone);
77
use Data::Page;
88
use List::MoreUtils qw(uniq firstval);
9+
use version 0.77;
910
use vars qw($AUTOLOAD);
1011
$Carp::Internal{$_}++ for __PACKAGE__;
1112

@@ -464,8 +465,8 @@ sub delete_sql {
464465
}
465466

466467
return $self->{dbix_lite}->{abstract}->delete(
467-
$self->_table_alias_expr($self->{cur_table}{name}, 'delete'),
468-
$delete_where,
468+
-from => $self->_table_alias_expr($self->{cur_table}{name}, 'delete'),
469+
-where => $delete_where,
469470
);
470471
}
471472

@@ -646,13 +647,24 @@ sub _table_alias_expr {
646647
my ($table_name, $op) = @_;
647648

648649
my $table_alias = $self->_table_alias($table_name, $op);
650+
649651
if ($table_name eq $table_alias) {
650652
# foo
651653
return $table_name;
652654
} else {
653-
# foo AS my_foo
654-
return $self->{dbix_lite}->{abstract}->table_alias($table_name, $table_alias);
655+
656+
# As of SQL::Abstract::More v1.44, table alias syntax works for select, update, delete
657+
my $supported_op = $op eq 'select' || $op eq 'update' || $op eq 'delete';
658+
if ( $supported_op && version->parse(SQL::Abstract::More->VERSION) >= version->parse('1.44') ) {
659+
return "$table_name|$table_alias";
660+
}
661+
else {
662+
# foo AS my_foo
663+
return $self->{dbix_lite}->{abstract}->table_alias($table_name, $table_alias);
664+
}
665+
655666
}
667+
656668
}
657669

658670
sub _inflate_row {

0 commit comments

Comments
 (0)