Subject: | allow ( ?? ) and (?? ) and more instead of just (??) in a query |
Hi,
I really like to write
$db->query(q{ INSERT INTO xx ( name, street ) VALUES ( ?? ) }, $name, $street );
It just looks better to me.
please apply the attached patch
--
Boris
Subject: | allow_q_with_spaces.patch |
- Add: ( ?? ) instead of only (??)
---
commit df2d95344e3f3c462600cb56ee8f6e15a20329ac
tree c89e2d6957189649d3f2f766d12d6fe617a2998c
parent bcb0aafe074e673d5f45104f8261dfd0cad759e1
author Boris Zentner <borisz@lisa.local> Sun, 05 Nov 2006 16:57:16 +0100
committer Boris Zentner <borisz@lisa.local> Sun, 05 Nov 2006 16:57:16 +0100
lib/DBIx/Simple.pm | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/DBIx/Simple.pm b/lib/DBIx/Simple.pm
index 443c796..73851c7 100644
--- a/lib/DBIx/Simple.pm
+++ b/lib/DBIx/Simple.pm
@@ -8,6 +8,9 @@ $DBIx::Simple::VERSION = '1.26';
$Carp::Internal{$_} = 1
for qw(DBIx::Simple DBIx::Simple::Result DBIx::Simple::DeadObject);
+# omniholder regex
+my $oh = qr/\([ \t]*\?\?[ \t]*\)/;
+
my $quoted = qr/'(?:\\.|[^\\']+)*'|"(?:\\.|[^\\"]+)*"/s;
my %statements; # "$db" => { "$st" => $st, ... }
@@ -79,10 +82,10 @@ sub _gimme_regex { no strict 'refs'; *{
# Replace (??) with (?, ?, ?, ...)
sub _replace_omniholder {
my ($self, $query, $binds) = @_;
- return if $$query !~ /\(\?\?\)/;
+ return if $$query !~ /$oh/;
my $omniholders = 0;
- $$query =~ s[(\(\?\?\)|$quoted+|(?:(?!\(\?\?\)).)+)] {
- $1 eq '(??)'
+ $$query =~ s[($oh|$quoted+|(?:(?!$oh).)+)] {
+ $1 =~ /^$oh$/
? do {
Carp::croak('There can be only one omniholder')
if $omniholders++;