<p dir="auto">Subclasses that override <code class="notranslate">_where_field_IN</code> and <code class="notranslate">_where_field_BETWEEN</code> and conditionally re-dispatch to the default handlers in SQL::Abstract were not correctly handling empty array references passed as arguments to <code class="notranslate">-in</code>, <code class="notranslate">-between</code>, and their negated counterparts.</p>
<p dir="auto">This behaviour was broken in the refactor that lead to 2.000000, and more specifically in 1.90_03, going from</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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"><pre class="notranslate notranslate"><code>$ 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
</code></pre></div>
<p dir="auto">to</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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 ( )"><pre class="notranslate notranslate"><code>$ 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 ( )
</code></pre></div>
<p dir="auto">and resulting in illegal SQL.</p>
<p dir="auto">This was breaking behaviour that resulted in downstream issues affecting at least SQL::Abstract::More (see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1128838688" data-permission-text="Title is private" data-url="https://github.com/damil/SQL-Abstract-More/issues/20" data-hovercard-type="issue" data-hovercard-url="/damil/SQL-Abstract-More/issues/20/hovercard" href="https://github.com/damil/SQL-Abstract-More/issues/20">damil/SQL-Abstract-More#20</a>).</p>
<p dir="auto">Likewise, a class overriding <code class="notranslate">_where_field_BETWEEN</code> was not triggering the parameter validation that disallowed empty array references or undefined values to be used as parameters to <code class="notranslate">-between</code> and its negation:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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 )"><pre class="notranslate notranslate"><code>$ 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 )
</code></pre></div>
<p dir="auto">This change ensures that the path taken by subclasses that override those methods triggers equivalent code paths to those that don't.</p>
<p dir="auto">Fixes <a href="https://rt.cpan.org/Ticket/Display.html?id=142341" rel="nofollow">https://rt.cpan.org/Ticket/Display.html?id=142341</a></p>
<hr>
<h4>You can view, comment on, or merge this pull request online at:</h4>
<p> <a href='https://github.com/dbsrgits/sql-abstract/pull/22'>https://github.com/dbsrgits/sql-abstract/pull/22</a></p>
<h4>Commit Summary</h4>
<ul>
<li><a href="https://github.com/dbsrgits/sql-abstract/pull/22/commits/0f94bfb34fb31a4fb830e9b339b4fe62c3b659d3" class="commit-link">0f94bfb</a> Handle empty array argument to in in subclasses</li>
</ul>
<h4 style="display: inline-block">File Changes </h4> <p style="display: inline-block">(<a href="https://github.com/dbsrgits/sql-abstract/pull/22/files">2 files</a>)</p>
<ul>
<li>
<strong>M</strong>
<a href="https://github.com/dbsrgits/sql-abstract/pull/22/files#diff-ec7e26da6911a44b059c4cbcaba4718cf763f401b76860ab7d6656f39badb2c5">lib/SQL/Abstract.pm</a>
(20)
</li>
<li>
<strong>M</strong>
<a href="https://github.com/dbsrgits/sql-abstract/pull/22/files#diff-003ad1d133844ea943fb67bd12e8aafc8ccff6c2ebcaa1716ce781ae56619ee6">t/05in_between.t</a>
(53)
</li>
</ul>
<h4>Patch Links:</h4>
<ul>
<li><a href='https://github.com/dbsrgits/sql-abstract/pull/22.patch'>https://github.com/dbsrgits/sql-abstract/pull/22.patch</a></li>
<li><a href='https://github.com/dbsrgits/sql-abstract/pull/22.diff'>https://github.com/dbsrgits/sql-abstract/pull/22.diff</a></li>
</ul>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/dbsrgits/sql-abstract/pull/22">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AACJ4ARXV72QFUEC2EFBPILV5C6PJANCNFSM6AAAAAAQG5WX34">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AACJ4AUSMBR2VZZK7GHPEI3V5C6PJA5CNFSM6AAAAAAQG5WX36WGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFCWXH3M.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><dbsrgits/sql-abstract/pull/22</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/dbsrgits/sql-abstract/pull/22",
"url": "https://github.com/dbsrgits/sql-abstract/pull/22",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>