Luke Ross

DBIx::InterpolationBinding

5 releases git clone https://lukeross.name/projects/dbix-interpolationbinding.git/

Perl extension for turning perl double-quote string interpolation into DBI bind parameters.

Commit ffd80df172685382fc476eabca267a3384185bfa

Doh. Copying array reference doesn't mean you have your own array. Clone needs to set up a new array git-svn-id: file:///home/lukeross/ToDo/code-subversion/perl-DBIx-InterpolationBinding@263 3208c2a6-1f24-0410-bbd8-cb17f2cc2c65

Committed 19 Mar 2008 by lukeross

lib/DBIx/InterpolationBinding.pm

@@ -83,6 +83,7 @@ sub _append_item_to_object {
 	# $new_hash will become the object we return, so the old one
 	# isn't mashed.
 	my $new_hash = { %$self };
+	$new_hash->{bind_params} = [ @{ $self->{bind_params} } ];
 
 	# At this point, the thing that isn't $self is either an object of
 	# this class, or it's a boring string. Also, we either need to append


t/02-dbi.t

@@ -7,7 +7,7 @@
 
 use Test;
 my $tests;
-BEGIN { $tests = 8; plan tests => $tests };
+BEGIN { $tests = 10; plan tests => $tests };
 
 my $dbh;
 eval 'use DBI; $dbh = DBI->connect("dbi:DBM:");';
@@ -55,11 +55,18 @@ ok($sth and $sth->rows == 1);
 
 # Try a select
 my $row;
-my $sth = $dbh->execute("SELECT * FROM fruit WHERE dVal = $g");
+$sth = $dbh->execute("SELECT * FROM fruit WHERE dVal = $g");
 ok($sth and $sth->rows == 1 and $row = $sth->fetchrow_hashref and
    $row->{dKey} eq $b and $row->{dVal} eq $g);
 $sth->finish if $sth;
 
+# And a loop
+foreach my $type ($d, $g) {
+	$sth = $dbh->execute("SELECT * FROM fruit WHERE dVal = $type");
+	ok($sth and $sth->rows == 1 and $row = $sth->fetchrow_hashref and
+		$row->{dVal} eq $type);
+}
+
 }
 
 # Can't work outside scope? - the eval should fail as the string isn't