Revision history for SQL::Abstract
+ - fixed open outer parens for a multi-line literal
+
+revision 1.61 2010-02-05 16:28 (UTC)
+----------------------------
- Allow INSERT to take additional attributes
- Support for INSERT ... RETURNING
- Another iteration of SQL::Abstract::Test fixes and improvements
all_from 'lib/SQL/Abstract.pm';
-requires "List::Util" => 0;
-requires "Scalar::Util" => 0;
+requires 'List::Util' => 0;
+requires 'Scalar::Util' => 0;
+requires 'Storable' => 0;
test_requires "Test::Builder" => 0;
-test_requires "Test::Deep" => 0;
test_requires "Test::More" => 0;
test_requires "Test::Exception" => 0;
test_requires "Test::Warn" => 0;
-test_requires "Clone" => 0.31;
tests_recursive 't';
# GLOBALS
#======================================================================
-our $VERSION = '1.60';
+our $VERSION = '1.61';
# This would confuse some packagers
#$VERSION = eval $VERSION; # numify for warning-free dev releases
my ($sql, @bind) = $self->$method($data);
$sql = join " ", $self->_sqlcase('insert into'), $table, $sql;
- if (my $fields = $options->{returning}) {
- my $f = $self->_SWITCH_refkind($fields, {
- ARRAYREF => sub {join ', ', map { $self->_quote($_) } @$fields;},
- SCALAR => sub {$self->_quote($fields)},
- SCALARREF => sub {$$fields},
- });
- $sql .= join " ", $self->_sqlcase(' returning'), $f;
+ if (my $ret = $options->{returning}) {
+ $sql .= $self->_insert_returning ($ret);
}
return wantarray ? ($sql, @bind) : $sql;
}
+sub _insert_returning {
+ my ($self, $fields) = @_;
+
+ my $f = $self->_SWITCH_refkind($fields, {
+ ARRAYREF => sub {join ', ', map { $self->_quote($_) } @$fields;},
+ SCALAR => sub {$self->_quote($fields)},
+ SCALARREF => sub {$$fields},
+ });
+ return join (' ', $self->_sqlcase(' returning'), $f);
+}
+
sub _insert_HASHREF { # explicit list of fields and then values
my ($self, $data) = @_;
# adding them back in the corresponding method
sub _open_outer_paren {
my ($self, $sql) = @_;
- $sql = $1 while $sql =~ /^ \s* \( (.*) \) \s* $/x;
+ $sql = $1 while $sql =~ /^ \s* \( (.*) \) \s* $/xs;
return $sql;
}
=head1 LICENSE
-This module is free software; you may copy this under the terms of
-the GNU General Public License, or the Artistic License, copies of
-which should have accompanied your Perl kit.
+This module is free software; you may copy this under the same
+terms as perl itself (either the GNU General Public License or
+the Artistic License)
=cut
use Data::Dumper;
use Carp;
use Test::Builder;
-use Test::Deep qw(eq_deeply);
our @EXPORT_OK = qw/&is_same_sql_bind &is_same_sql &is_same_bind
&eq_sql_bind &eq_sql &eq_bind
sub eq_bind {
my ($bind_ref1, $bind_ref2) = @_;
- return eq_deeply($bind_ref1, $bind_ref2);
+ local $Data::Dumper::Useqq = 1;
+ local $Data::Dumper::Sortkeys = 1;
+
+ return Dumper($bind_ref1) eq Dumper($bind_ref2);
}
sub eq_sql {
use SQL::Abstract::Test import => ['is_same_sql_bind'];
use Data::Dumper;
+use Storable qw/dclone/;
use SQL::Abstract;
-use Clone;
=begin
Test -and -or and -nest modifiers, assuming the following:
local $SIG{__WARN__} = sub { push @w, @_ };
my $sql = SQL::Abstract->new ($case->{args} || {});
- my $where_copy = Clone::clone ($case->{where});
+ my $where_copy = dclone($case->{where});
lives_ok (sub {
my ($stmt, @bind) = $sql->where($case->{where});
{
parenthesis_significant => 1,
where => {
+ status => { -in => \"(SELECT status_codes\nFROM states)" },
+ },
+ # failed to open outer parens on a multi-line query in 1.61 (semifor)
+ stmt => " WHERE ( status IN ( SELECT status_codes FROM states )) ",
+ bind => [],
+ test => '-in multi-line subquery test',
+ },
+ {
+ parenthesis_significant => 1,
+ where => {
customer => { -in => \[
'SELECT cust_id FROM cust WHERE balance > ?',
2000,