summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Stosberg <mark@summersault.com>2009-06-28 18:30:59 -0800
committerMichael G. Schwern <schwern@pobox.com>2009-12-12 20:58:50 -0800
commitfd74ea189c913f6197ec178db988b1e8e1a31ecf (patch)
tree0910aa10a88e6f18e29747baaf8f7dfd827aae7c
parent427be8550d0731ebdd0d120da31a97c14d1c1979 (diff)
import SQL-Interp 1.10 from CPAN1.10
git-cpan-module: SQL-Interp git-cpan-version: 1.10 git-cpan-authorid: MARKSTOS git-cpan-file: authors/id/M/MA/MARKSTOS/SQL-Interp-1.10.tar.gz
-rw-r--r--Build.PL2
-rw-r--r--Changes37
-rw-r--r--META.yml11
-rw-r--r--Makefile.PL4
-rw-r--r--lib/DBIx/Interp.pm4
-rw-r--r--lib/SQL/Interp.pm63
-rw-r--r--t/lib.pl3
-rw-r--r--t/sql_interp.t27
8 files changed, 108 insertions, 43 deletions
diff --git a/Build.PL b/Build.PL
index 7333785..b15b214 100644
--- a/Build.PL
+++ b/Build.PL
@@ -5,6 +5,8 @@ Module::Build->new(
license => 'perl',
requires => {
DBI => 1.00,
+ # There were test failures on 5.5 and 5.6. Patches welcome to resolve them
+ perl => '5.8.0',
},
recommends => {
Text::Balanced => '1.87',
diff --git a/Changes b/Changes
index b498cc3..1e50d15 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,41 @@
+A future release:
+
+ - If you like SQL::Interp, please consider supporting the project by adding support
+ for the 'quote_char' and 'name_sep' options. SQL::Abstract has code that can be
+ borrowed for this. See this bug report for details:
+ http://rt.cpan.org/Public/Bug/Display.html?id=31488
+
+ - If you use SQL::Interp with PostgreSQL and are interested in a further
+ performance improvement, considering working on this optimization:
+ "RT#39778: wish: optimize IN() to be ANY() for compatible PostgreSQL versions":
+ https://rt.cpan.org/Ticket/Display.html?id=39778
+
+1.10 2009-06-28
+
+ [FEATURES]
+ - Add support for MySQL's "REPLACE INTO". (TBONE, Mark Stosberg, RT#43477)
+
+ [PERFORMANCE]
+ - When SQL snippets are provided as hashrefs, we now always sort them to
+ insure consistent results for the benefit of possible statement caching.
+ This shouldn't change your application behavior, as hashs are not to be
+ considered an ordered data structure. If you want to force an element to
+ be first in the where clause, that's better done with the pre-existing
+ functionality:
+ sql_interp("... WHERE a = 1 AND ",\%rest_of_where_hash);
+
+ Thanks to Andrew Kirkpatrick for the patch (RT#33310).
+
+ [BUG FIXES]
+ - The documentation said that we supported a reference to an arrayref in
+ the "IN ()" context, but there didn't appear to be code or tests for this.
+ Both have been added now. (Mark Stosberg, RT#39336).
+
+ [INTERNALS]
+ - Update formatting and language about the historical fork with SQL::Interpolate.
+ - Fix documentation typos (TBONE, RT#42726, RT#42733, RT#42336)
+
1.06 2007-12-20
[INTERNALS]
diff --git a/META.yml b/META.yml
index cdea29d..39c8236 100644
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
---
name: SQL-Interp
-version: 1.06
+version: 1.10
author:
- "David Manura (http://math2.org/david/contact)"
- 'Mark Stosberg <mark@summersault.com>'
@@ -8,28 +8,29 @@ abstract: Interpolate Perl variables into SQL statements
license: perl
requires:
DBI: 1
+ perl: 5.8.0
recommends:
Filter::Simple: 0
Scalar::Util: 0
Text::Balanced: 1.87
-generated_by: Module::Build version 0.2808
+generated_by: Module::Build version 0.32
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
provides:
DBIx::Interp:
file: lib/DBIx/Interp.pm
- version: 1.06
+ version: 1.10
DBIx::Interp::STX:
file: lib/DBIx/Interp.pm
DBIx::Interp::db:
file: lib/DBIx/Interp.pm
SQL::Interp:
file: lib/SQL/Interp.pm
- version: 1.06
+ version: 1.10
SQL::Interp::SQL:
file: lib/SQL/Interp.pm
SQL::Interp::Variable:
file: lib/SQL/Interp.pm
resources:
- license: http://dev.perl.org/licenses/
+ license: ~
diff --git a/Makefile.PL b/Makefile.PL
index 63a61f1..f001edd 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,8 +1,8 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.03
+# Note: this file was auto-generated by Module::Build::Compat version 0.32
+require 5.8.0;
use ExtUtils::MakeMaker;
WriteMakefile
(
- 'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'NAME' => 'SQL::Interp',
'EXE_FILES' => [],
diff --git a/lib/DBIx/Interp.pm b/lib/DBIx/Interp.pm
index 9154481..2cca0b6 100644
--- a/lib/DBIx/Interp.pm
+++ b/lib/DBIx/Interp.pm
@@ -6,7 +6,7 @@ use Carp;
use SQL::Interp ':all';
use base qw(Exporter DBI);
-our $VERSION = '1.06';
+our $VERSION = '1.10';
our @EXPORT;
our %EXPORT_TAGS = (all => [qw(
@@ -525,7 +525,7 @@ methods.
=item C<new> (static method)
- my $dbx = DBX::Interpolate->new($db, %params);
+ my $dbx = DBIx::Interp->new($db, %params);
Creates a new object, creating or attaching a DBI handle.
diff --git a/lib/SQL/Interp.pm b/lib/SQL/Interp.pm
index d485018..2f91674 100644
--- a/lib/SQL/Interp.pm
+++ b/lib/SQL/Interp.pm
@@ -1,6 +1,6 @@
package SQL::Interp;
-our $VERSION = '1.06';
+our $VERSION = '1.10';
use strict;
use warnings;
@@ -167,6 +167,10 @@ sub _sql_interp {
my $not = quotemeta($1 || '');
$item = [ $$item ] if ref $item eq 'SCALAR';
+
+ # allow double references
+ $item = $$item if ref $item eq 'REF' ;
+
if (ref $item eq 'ARRAY') {
if (@$item == 0) {
my $dummy_expr = $not ? '1=1' : '1=0';
@@ -189,9 +193,9 @@ sub _sql_interp {
my $val = $item->{$key};
"$key=" .
_sql_interp_data($val);
- } keys %$item);
+ } (sort keys %$item));
}
- elsif ($sql =~ /\bINSERT[\w\s]*\sINTO\s*$id_match\s*$/si) {
+ elsif ($sql =~ /\b(REPLACE|INSERT)[\w\s]*\sINTO\s*$id_match\s*$/si) {
$item = [ $$item ] if ref $item eq 'SCALAR';
if (ref $item eq 'ARRAY') {
$sql .= " VALUES(" . join(', ', map {
@@ -199,11 +203,12 @@ sub _sql_interp {
} @$item) . ")";
}
elsif (ref $item eq 'HASH') {
+ my @keyseq = sort keys %$item;
$sql .=
- " (" . join(', ', keys %$item) . ")" .
+ " (" . join(', ', @keyseq) . ")" .
" VALUES(" . join(', ', map {
- _sql_interp_data($_);
- } values %$item) . ")";
+ _sql_interp_data($item->{$_});
+ } @keyseq) . ")";
}
else { _error_item($idx, \@items); }
}
@@ -248,7 +253,7 @@ sub _sql_interp {
"$key=" .
_sql_interp_data($val);
}
- } keys %$item;
+ } (sort keys %$item);
$s = "($s)" if keys %$item > 1;
$s = " $s";
$sql .= $s;
@@ -350,7 +355,7 @@ sub _sql_interp_resultset {
my $sql3 = _sql_interp_data($val);
$sql3 .= " AS $key" if $is_first_row;
$sql3;
- } keys %$first_row);
+ } (sort keys %$first_row));
}
}
else {
@@ -518,7 +523,7 @@ The following variable names will be used in the below examples:
$sref = \3; # scalarref
$aref = [1, 2]; # arrayref
- $hashref = {m => 1, n => undef}; # hashref
+ $href = {m => 1, n => undef}; # hashref
$hv = {v => $v, s => $$s}; # hashref containing arrayref
$vv = [$v, $v]; # arrayref of arrayref
$vh = [$h, $h]; # arrayref of hashref
@@ -592,6 +597,8 @@ arrayref.
IN: 'INSERT INTO mytable', $sref
OUT: 'INSERT INTO mytable VALUES(?)', $$sref;
+MySQL's "REPLACE INTO" is supported the same way.
+
=head3 Context ('SET', $x)
IN: 'UPDATE mytable SET', $href
@@ -635,7 +642,7 @@ that transparently caches statement handles.
if (! defined $sth || $sth->{Statement} ne $sql) {
$sth = $dbh->prepare($sql);
}
- $sth->execute(@list);
+ $sth->execute(@bind);
$sth->fetchall_arrayref();
}
@@ -791,24 +798,32 @@ See L<http://www.perl.com/perl/misc/Artistic.html>.
=head2 Fork
-This module was forked from L<SQL::Interpolate>, after the author of
-SQL::Interpolate was no longer heard from. The core functionality remains
-unchanged, but the following incompatible changes have been made:
+This module was forked from L<SQL::Interpolate>, around version 0.40. The core
+functionality remains unchanged, but the following incompatible changes have
+been made:
+
+=over 4
+
+=item *
+
+The optional source filtering feature was removed.
+
+=item *
+
+The optional "macro" feature was removed.
+
+=item *
+
+A legacy, deprecated function "sql_literal" was removed.
-- The optional source filtering feature was removed.
-- The optional "macro" feature was removed.
-- A legacy, deprecated function "sql_literal" was removed.
-- The docs were overhauled to try to be simpler and clearer.
+=item *
-So if you want those removed features, you should use SQL::Interpolate. I used
-it for years without those optional features and never missed them.
+The docs were overhauled to be simpler and clearer.
-Also, there were a few improvements to SQL::Interpolate which were never
-officially released in that name space because the author disappeared. So,
-SQL::Interp, also has the improvements from 0.33 to 0.40 in SQL::Interpolate.
-These were mostly made by the author or other contributors, and are expected to
-appear in the next official release of SQL::Interpolate, when and if that happens.
+=back
+So if you want those removed features, you should use L<SQL::Interpolate>. I
+used it for years without those optional features and never missed them.
=head2 Other modules in this distribution
diff --git a/t/lib.pl b/t/lib.pl
index 2b1c543..50a1867 100644
--- a/t/lib.pl
+++ b/t/lib.pl
@@ -4,6 +4,7 @@
use strict;
use SQL::Interp qw(:all);
use Data::Dumper;
+use Carp;
#our $fake_mysql_dbh =
# bless {Driver => {Name => 'mysql'}}, 'DBI::db';
@@ -30,7 +31,7 @@ sub my_deeply
local $SIG{__WARN__} = sub {
warn $_[0] if $_[0] !~ /isn't numeric in numeric eq/;
};
- is_deeply(@_) or print STDERR Dumper(@_);
+ is_deeply(@_) or carp Dumper(@_);
}
1
diff --git a/t/sql_interp.t b/t/sql_interp.t
index 0fa75dd..ffaea73 100644
--- a/t/sql_interp.t
+++ b/t/sql_interp.t
@@ -93,6 +93,9 @@ interp_test([sql(sql(),sql())],
interp_test(['INSERT INTO mytable', \$x],
['INSERT INTO mytable VALUES(?)', $x],
'INSERT scalarref');
+interp_test(['REPLACE INTO mytable', \$x],
+ ['REPLACE INTO mytable VALUES(?)', $x],
+ 'REPLACE INTO');
interp_test(['INSERT INTO mytable', sql($x)],
["INSERT INTO mytable $x"], # invalid
'INSERT sql(...)');
@@ -118,8 +121,8 @@ interp_test(['INSERT INTO mytable', $h],
@{$hi->{values}}],
'INSERT hashref of size > 0');
interp_test(['INSERT INTO mytable', $h2i->{hashref}],
- ["INSERT INTO mytable ($h2i->{keys}[0], $h2i->{keys}[1], $h2i->{keys}[2]) " .
- "VALUES($h2i->{places}->[0], $h2i->{places}->[1], $h2i->{places}->[2])",
+ ["INSERT INTO mytable ($h2i->{keys}[1], $h2i->{keys}[0], $h2i->{keys}[2]) " .
+ "VALUES($h2i->{places}->[1], $h2i->{places}->[0], $h2i->{places}->[2])",
@{$h2i->{binds}}],
'INSERT hashref of sql_type + sql()');
interp_test(['INSERT INTO mytable', {one => 1, two => sql(\$x, '*', \$x)}],
@@ -135,6 +138,12 @@ interp_test(['INSERT HIGH_PRIORITY IGNORE INTO mytable', $v],
interp_test(['WHERE field IN', \$x],
['WHERE field IN (?)', $x],
'IN scalarref');
+
+my $maybe_array = [1,2];
+interp_test(['WHERE field IN', \$maybe_array],
+ ['WHERE field IN (?, ?)', @$maybe_array],
+ 'IN maybe_array turns out to be an array');
+
interp_test(['WHERE field IN', sql($x)],
["WHERE field IN $x"], # invalid
'IN sql()');
@@ -175,7 +184,7 @@ interp_test(['UPDATE mytable SET', $h],
'SET hashref');
interp_test(['UPDATE mytable SET',
{one => 1, two => $var2, three => sql('3')}],
- ['UPDATE mytable SET three=3, one=?, two= ?',
+ ['UPDATE mytable SET one=?, three=3, two= ?',
[1, sql_type(\1)], [${$var2->{value}}, $var2]],
'SET hashref of sql_type types, sql()');
#FIX--what if size of hash is zero? error?
@@ -193,7 +202,7 @@ my $h2bi = make_hash_info(
{x => [1]}
);
interp_test(['WHERE', $h2bi->{hashref}],
- ["WHERE ($h2bi->{places}[0] AND $h2bi->{places}[1])", @{$h2bi->{binds}}],
+ ["WHERE ($h2bi->{places}[1] AND $h2bi->{places}[0])", @{$h2bi->{binds}}],
'WHERE hashref sql()');
my $h2ci = make_hash_info(
{x => 1, y => undef},
@@ -201,7 +210,7 @@ my $h2ci = make_hash_info(
{x => [1]}
);
interp_test(['WHERE', $h2ci->{hashref}],
- ["WHERE ($h2ci->{places}[0] AND $h2ci->{places}[1])", @{$h2ci->{binds}}],
+ ["WHERE ($h2ci->{places}[1] AND $h2ci->{places}[0])", @{$h2ci->{binds}}],
'WHERE hashref of NULL');
# WHERE x=
@@ -217,8 +226,8 @@ interp_test(['WHERE x=', \$x, 'AND', 'y=', $var2],
['WHERE x= ? AND y= ?', [$x, sql_type(\$x)], [${$var2->{value}}, $var2]],
'WHERE \$x, sql_type typed');
interp_test(['WHERE', {x => $x, y => $var2}, 'AND z=', \$x],
- ['WHERE (y= ? AND x=?) AND z= ?',
- [${$var2->{value}}, $var2], [$x, sql_type(\$x)], [$x, sql_type(\$x)]],
+ ['WHERE (x=? AND y= ?) AND z= ?',
+ [$x, sql_type(\$x)], [${$var2->{value}}, $var2], [$x, sql_type(\$x)]],
'WHERE hashref of \$x, sql_type typed');
my $h5i = make_hash_info(
{x => $x, y => [3, $var2]},
@@ -226,10 +235,10 @@ my $h5i = make_hash_info(
{x => [[$x, sql_type(\$x)]], y => [[3, sql_type(\3)], [${$var2->{value}}, $var2]]}
);
interp_test(['WHERE', $h5i->{hashref}],
- ["WHERE ($h5i->{places}[0] AND $h5i->{places}[1])", @{$h5i->{binds}}],
+ ["WHERE ($h5i->{places}[1] AND $h5i->{places}[0])", @{$h5i->{binds}}[2,0,1]],
'WHERE hashref of arrayref of sql_type typed');
interp_test(['WHERE', {x => $x, y => sql('z')}],
- ['WHERE (y=z AND x=?)', $x],
+ ['WHERE (x=? AND y=z)', $x],
'WHERE hashref of \$x, sql()');
# table references