Mercurial > hg > monetdb-perl
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:a2a23aa2bf8e | 54:b0ac51c36919 |
---|---|
14 use DBD_TEST(); | 14 use DBD_TEST(); |
15 | 15 |
16 use Test::More; | 16 use Test::More; |
17 | 17 |
18 if (defined $ENV{DBI_DSN}) { | 18 if (defined $ENV{DBI_DSN}) { |
19 plan tests => 6; | 19 plan tests => 7; |
20 } else { | 20 } else { |
21 plan skip_all => 'Cannot test without DB info'; | 21 plan skip_all => 'Cannot test without DB info'; |
22 } | 22 } |
23 | 23 |
24 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n"; | 24 my $dbh = DBI->connect or die "Connect failed: $DBI::errstr\n"; |
35 ]; | 35 ]; |
36 | 36 |
37 ok( tab_insert( $dbh, $data ),'Insert test data'); | 37 ok( tab_insert( $dbh, $data ),'Insert test data'); |
38 | 38 |
39 ok( tab_select( $dbh ),'Select test data'); | 39 ok( tab_select( $dbh ),'Select test data'); |
40 | |
41 ok( tab_bind_question_marks( $dbh ), 'Bind data with question marks'); | |
40 | 42 |
41 ok( DBD_TEST::tab_delete( $dbh ),'Drop test table'); | 43 ok( DBD_TEST::tab_delete( $dbh ),'Drop test table'); |
42 | 44 |
43 ok( $dbh->disconnect,'Disconnect'); | 45 ok( $dbh->disconnect,'Disconnect'); |
44 | 46 |
60 return undef; | 62 return undef; |
61 } | 63 } |
62 } | 64 } |
63 } | 65 } |
64 return 1; | 66 return 1; |
67 } | |
68 | |
69 sub tab_bind_question_marks | |
70 { | |
71 my $dbh = shift; | |
72 | |
73 my $sth = $dbh->prepare("SELECT ? AS x, ? AS y"); | |
74 unless ( $sth ) { | |
75 print $DBI::errstr; | |
76 return 0; | |
77 } | |
78 | |
79 # without question marks | |
80 $sth->execute("foo", "bar"); | |
81 my($x, $y) = $sth->fetchrow_array; | |
82 if ($x ne "foo") { | |
83 print "# when binding foo and bar, expected foo, got '$x'"; | |
84 return undef; | |
85 } | |
86 if ($y ne "bar") { | |
87 print "# when binding foo and bar, expected bar, got '$y'"; | |
88 return undef; | |
89 } | |
90 | |
91 # with question marks | |
92 $sth->execute("foo?", "bar?"); | |
93 ($x, $y) = $sth->fetchrow_array; | |
94 if ($x ne "foo?") { | |
95 print "# when binding foo? and bar?, expected foo?, got '$x'"; | |
96 return undef; | |
97 } | |
98 if ($y ne "bar?") { | |
99 print "# when binding foo? and bar?, expected bar?, got '$y'"; | |
100 return undef; | |
101 } | |
102 | |
103 return 1; | |
65 } | 104 } |
66 | 105 |
67 sub tab_insert | 106 sub tab_insert |
68 { | 107 { |
69 my $dbh = shift; | 108 my $dbh = shift; |