sub select {
my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
- $self->{"${_}_bind"} = [] for (qw/having from order/);
+ $self->{"${_}_bind"} = [] for (qw/having from order where/);
if (not ref($table) or ref($table) eq 'SCALAR') {
$table = $self->_quote($table);
croak "LIMIT 0 Does Not Compute" if $rest[0] == 0;
# and anyway, SQL::Abstract::Limit will cause a barf if we don't first
- my ($sql, @where_bind) = $self->SUPER::select(
+ my $sql = '';
+ ($sql, @{$self->{where_bind}}) = $self->SUPER::select(
$table, $self->_recurse_fields($fields), $where, $rs_attrs, @rest
);
- return wantarray ? ($sql, @{$self->{from_bind}}, @where_bind, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
+ return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
}
# Quotes table names, and handles default inserts
sub select {
my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
- my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
- push @bind, @{$self->{_oracle_connect_by_binds}};
+ my $sql = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
- return wantarray ? ($sql, @bind) : $sql;
+ return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{_oracle_connect_by_binds}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql;
}
sub _emulate_limit {
$schema->resultset('Artist')->create ({
name => 'root',
+ rank => 1,
cds => [],
children => [
{
name => 'child1',
+ rank => 2,
children => [
{
name => 'grandchild',
+ rank => 3,
cds => [
{
title => "grandchilds's cd" ,
children => [
{
name => 'greatgrandchild',
+ rank => 3,
}
],
}
},
{
name => 'child2',
+ rank => 3,
},
],
});
is( $rs->count, 2, 'Connect By; LIMIT count ok' );
}
+ # combine a connect_by with group_by and having
+ {
+ my $rs = $schema->resultset('Artist')->search({}, {
+ select => ['count(rank)'],
+ start_with => { name => 'root' },
+ connect_by => { parentid => { -prior => \ 'artistid' } },
+ group_by => ['rank'],
+ having => { 'count(rank)' => { '<', 2 } },
+ });
+
+ is_same_sql_bind (
+ $rs->as_query,
+ '(
+ SELECT count(rank)
+ FROM artist me
+ START WITH name = ?
+ CONNECT BY parentid = PRIOR artistid
+ GROUP BY rank HAVING count(rank) < ?
+ )',
+ [ [ name => 'root' ], [ 'count(rank)' => 2 ] ],
+ );
+
+ is_deeply (
+ [ $rs->get_column ('count(rank)')->all ],
+ [1, 1],
+ 'Group By a Connect By query - correct values'
+ );
+ }
+
+
# select the whole cycle tree without nocylce
{
my $rs = $schema->resultset('Artist')->search({}, {