$self->{expand}{exists} = sub {
$_[0]->_expand_op(undef, [ exists => $_[2] ]);
};
+
+ # check for overriden methods
+ if ($self->can('_table') ne SQL::Abstract->can('_table')) {
+ $self->{expand_clause}{'select.from'} = sub {
+ return +{ -literal => [ $_[0]->_table($_[2]) ] };
+ };
+ }
+ if ($self->can('_order_by') ne SQL::Abstract->can('_order_by')) {
+ $self->{expand_clause}{'select.order_by'} = sub {
+ my ($osql, @obind) = $_[0]->_order_by($_[2]);
+ $osql =~ s/^order by //i;
+ return undef unless length($osql);
+ return +{ -literal => [ $osql, @obind ] };
+ };
+ }
return $self;
}
sub _expand_select_clause_where {
my ($self, undef, $where) = @_;
- local (@{$self->{expand}}{qw(ident value)},
- @{$self->{expand_op}}{qw(ident value)},
- $self->{expand_op}{bind})
- = (map {
- my $orig = $self->{expand}{$_};
- sub {
- my $self = shift;
- +{ -func => [
- $self->{convert},
- $self->$orig(@_)
- ] };
- }
- } qw(ident value ident value bind)
- ) if $self->{convert};
-
- local $self->{expand}{func} = do {
- my $orig = $self->{expand}{func};
- sub {
- my ($self, $type, $thing) = @_;
- if (ref($thing) eq 'ARRAY' and $thing->[0] eq $self->{convert}
- and @$thing == 2 and ref($thing->[1]) eq 'HASH'
- and (
- $thing->[1]{-ident}
- or $thing->[1]{-value}
- or $thing->[1]{-bind})
- ) {
- return { -func => $thing }; # already went through our expander
- }
- return $self->$orig($type, $thing);
+ my $sqla = do {
+ if (my $conv = $self->{convert}) {
+ my $_wrap = sub {
+ my $orig = shift;
+ sub {
+ my $self = shift;
+ +{ -func => [
+ $conv,
+ $self->$orig(@_)
+ ] };
+ };
+ };
+ $self->clone
+ ->wrap_expanders(map +($_ => $_wrap), qw(ident value bind))
+ ->wrap_op_expanders(map +($_ => $_wrap), qw(ident value bind))
+ ->wrap_expander(func => sub {
+ my $orig = shift;
+ sub {
+ my ($self, $type, $thing) = @_;
+ if (ref($thing) eq 'ARRAY' and $thing->[0] eq $conv
+ and @$thing == 2 and ref($thing->[1]) eq 'HASH'
+ and (
+ $thing->[1]{-ident}
+ or $thing->[1]{-value}
+ or $thing->[1]{-bind})
+ ) {
+ return { -func => $thing }; # already went through our expander
+ }
+ return $self->$orig($type, $thing);
+ }
+ });
+ } else {
+ $self;
}
- } if $self->{convert};
+ };
- my $exp = $self->expand_expr($where);
- +(where => $exp);
+ return +(where => $sqla->expand_expr($where));
}
sub _expand_select_clause_order_by {
sub select {
my ($self, @args) = @_;
-
my $stmt = do {
if (ref(my $sel = $args[0]) eq 'HASH') {
$sel