Subject: | -between generates bad SQL |
use strict;
use warnings;
use SQL::Abstract;
use JSON qw/to_json/;
say(to_json [SQL::Abstract->new()->where(
{
a => { -between => [1,2] },
c => 'b',
}
)] );
makes
[" WHERE ( a BETWEEN ? AND ? AND c = ? )",1,2,"b"]
but, I needs
[" WHERE ( ( a BETWEEN ? AND ? ) AND c = ? )",1,2,"b"]
follow is a patch
--- lib/SQL/Abstract.pm.org 2008-10-15 19:21:25.000000000 +0900
+++ lib/SQL/Abstract.pm 2008-10-15 19:40:51.000000000 +0900
@@ -692,8 +692,8 @@
$self->_debug("HASH($f => $x) uses
special operator: [ $u ]");
if ($u =~ /between/i) {
# SQL sucks
- push @sqlf, join ' ',
$self->_convert($label), $u, $self->_convert('?'),
-
$self->_sqlcase('and'), $self->_convert('?');
+ push @sqlf, join ' ', '(',
$self->_convert($label), $u, $self->_convert('?'),
+
$self->_sqlcase('and'), $self->_convert('?'), ')';
} else {
push @sqlf, join ' ',
$self->_convert($label), $u, '(',
join(', ', map {
$self->_convert('?') } @$x),