-limit => 0

6 views
Skip to first unread message

Sergiy Zuban

unread,
Apr 1, 2014, 6:19:51 PM4/1/14
to dbix-da...@googlegroups.com
Hi Laurent,

I need to make a select query with LIMIT 0, but currently it's not working because of:

1. DBIx::DataModel::Statement:265

  $args->{$_} and $sqla_args{$_} = $args->{$_} for @args_to_copy;

It doesn't pass defined, but false values, so 0 doesn't even passed to SQL::Abstract::More. Suggested change is:

 defined( $args->{$_} ) and $sqla_args{$_} = $args->{$_} for @args_to_copy;

2. SQL::Abstract::More:260

  if ( $args{-limit}) {

Suggested change:

  if ( defined $args{-limit}) {

Currently I was able to achieve the same result using WHERE  1 = 0 condition in filter, but this is dirty workaround and it would be nice to make -limit => 0 working as well.

Dami Laurent (PJ)

unread,
Apr 2, 2014, 7:52:59 AM4/2/14
to dbix-da...@googlegroups.com

 

 

De : dbix-da...@googlegroups.com [mailto:dbix-da...@googlegroups.com] De la part de Sergiy Zuban
Envoyé : mercredi 2 avril 2014 00:20
À : dbix-da...@googlegroups.com
Objet : [dbix-datamodel] -limit => 0

 

Hi Laurent,

 

I need to make a select query with LIMIT 0, but currently it's not working

 

Hi Sergiy,

 

OK, good point, I’ll fix that.

But out of curiosity : what is the point of a « LIMIT 0 » ? You get no results, so why would you ever write such a thing ?

 

Cheers, Laurent D.

Sergiy Zuban

unread,
Apr 2, 2014, 11:43:44 AM4/2/14
to dbix-da...@googlegroups.com
we have implemented an adapter for DBIx::DataModel to allow so called "aliased joins".

    my $join = $schema->aliased_join('Foo|f', 'Bar|b');
    my $statement = $join->select(
        -columns => [qw(  f.x f.y b.* )],
        -result_as => 'fast_statement',
    );

    while( my $row = $statement->next )
    {
        my $foo   = $join->get( 'f', $row );
        my $bar = $join->get( 'b', $row );
        ... 
    }

1. This allows to retrieve columns related to each joined table into separate hashes/objects rather than deal with plain row (which may have column name collisions).
2. Cons of this approach is that we have to specify all columns explicitly, which is not so big problem in most cases.

But sometimes we want to use '*' (like in example above) to retrieve all columns. To implement that I need to query corresponding table with SELECT * FROM bar LIMIT 0 to retrieve no data, but just to determine list of columns.

--
Sergiy Zuban
Reply all
Reply to author
Forward
0 new messages