diff DBD/t/12bind.t @ 54:b0ac51c36919

Properly handle bound parameters with question marks in them
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 14 Oct 2022 17:24:58 +0200 (2022-10-14)
parents 8c8bd15f7a0b
children
line wrap: on
line diff
--- a/DBD/t/12bind.t
+++ b/DBD/t/12bind.t
@@ -16,7 +16,7 @@ use DBD_TEST();
 use Test::More;
 
 if (defined $ENV{DBI_DSN}) {
-  plan tests => 6;
+  plan tests => 7;
 } else {
   plan skip_all => 'Cannot test without DB info';
 }
@@ -38,6 +38,8 @@ ok( tab_insert( $dbh, $data ),'Insert te
 
 ok( tab_select( $dbh ),'Select test data');
 
+ok( tab_bind_question_marks( $dbh ), 'Bind data with question marks');
+
 ok( DBD_TEST::tab_delete( $dbh ),'Drop test table');
 
 ok( $dbh->disconnect,'Disconnect');
@@ -64,6 +66,43 @@ sub tab_select
   return 1;
 }
 
+sub tab_bind_question_marks
+{
+	my $dbh = shift;
+
+	my $sth = $dbh->prepare("SELECT ? AS x, ? AS y");
+	unless ( $sth ) {
+		print $DBI::errstr;
+		return 0;
+	}
+
+	# without question marks
+	$sth->execute("foo", "bar");
+	my($x, $y) = $sth->fetchrow_array;
+	if ($x ne "foo") {
+		print "# when binding foo and bar, expected foo, got '$x'";
+		return undef;
+	}
+	if ($y ne "bar") {
+		print "# when binding foo and bar, expected bar, got '$y'";
+		return undef;
+	}
+
+	# with question marks
+	$sth->execute("foo?", "bar?");
+	($x, $y) = $sth->fetchrow_array;
+	if ($x ne "foo?") {
+		print "# when binding foo? and bar?, expected foo?, got '$x'";
+		return undef;
+	}
+	if ($y ne "bar?") {
+		print "# when binding foo? and bar?, expected bar?, got '$y'";
+		return undef;
+	}
+
+	return 1;
+}
+
 sub tab_insert
 {
   my $dbh  = shift;