[DBIx-Class-Devel] [dbsrgits/sql-abstract] Handle empty array argument to in in subclasses (PR #22)

José Joaquín Atria notifications at github.com
Wed Sep 7 16:23:16 GMT 2022


Subclasses that override `_where_field_IN` and `_where_field_BETWEEN` and conditionally re-dispatch to the default handlers in SQL::Abstract were not correctly handling empty array references passed as arguments to `-in`, `-between`, and their negated counterparts.

This behaviour was broken in the refactor that lead to 2.000000, and more specifically in 1.90_03, going from

    $ perl -Ilib -MSQL::Abstract -E '
      say "version " . $SQL::Abstract::VERSION;
      package X {
        use parent "SQL::Abstract";
        use mro "c3";
        sub _where_field_IN { shift->next::method(@_) }
      }
      say X->new->select( table => ["*"], { foo => { -in => [] } } )
    '
    version 1.9002
    SELECT * FROM table WHERE 0=1

to

    $ perl -Ilib -MSQL::Abstract -E '
      say "version " . $SQL::Abstract::VERSION;
      package X {
        use parent "SQL::Abstract";
        use mro "c3";
        sub _where_field_IN { shift->next::method(@_) }
      }
      say X->new->select( table => ["*"], { foo => { -in => [] } } )
    '
    version 1.9003
    SELECT * FROM table WHERE foo IN ( )

and resulting in illegal SQL.

This was breaking behaviour that resulted in downstream issues affecting at least SQL::Abstract::More (see https://github.com/damil/SQL-Abstract-More/issues/20).

Likewise, a class overriding `_where_field_BETWEEN` was not triggering the parameter validation that disallowed empty array references or undefined values to be used as parameters to `-between` and its negation:

    $ perl -Ilib -MSQL::Abstract -E '
      say "version " . $SQL::Abstract::VERSION;
      package X {
        use parent "SQL::Abstract";
        use mro "c3";
        sub _where_field_BETWEEN { shift->next::method(@_) }
      }
      say X->new->select( table => ["*"], { foo => { -between => [] } } )
    '
    version 1.9003
    SELECT * FROM table WHERE ( foo BETWEEN AND )

This change ensures that the path taken by subclasses that override those methods triggers equivalent code paths to those that don't.

Fixes https://rt.cpan.org/Ticket/Display.html?id=142341
You can view, comment on, or merge this pull request online at:

  https://github.com/dbsrgits/sql-abstract/pull/22

-- Commit Summary --

  * Handle empty array argument to in in subclasses

-- File Changes --

    M lib/SQL/Abstract.pm (20)
    M t/05in_between.t (53)

-- Patch Links --

https://github.com/dbsrgits/sql-abstract/pull/22.patch
https://github.com/dbsrgits/sql-abstract/pull/22.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/dbsrgits/sql-abstract/pull/22
You are receiving this because you are subscribed to this thread.

Message ID: <dbsrgits/sql-abstract/pull/22 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class-devel/attachments/20220907/94ac617f/attachment.htm>


More information about the DBIx-Class-Devel mailing list