Author: timbo
Date: Sat May  2 09:12:35 2009
New Revision: 12734

Modified:
   dbi/trunk/t/50dbm.t

Log:
Add tests for placeholder support in DBD::DBM (and thus DBD::File)
which seems to have got broken recently.


Modified: dbi/trunk/t/50dbm.t
==============================================================================
--- dbi/trunk/t/50dbm.t (original)
+++ dbi/trunk/t/50dbm.t Sat May  2 09:12:35 2009
@@ -74,7 +74,7 @@
 
 for my $mldbm ( '', @mldbm_types ) {
     my $sql = ($mldbm) ? $three_col_sql : $two_col_sql;
-    my @sql = split /\s*;\n/, $sql;
+    my @sql = split /\n/, $sql;
     for my $dbm_type ( @dbm_types ) {
        print "\n--- Using $dbm_type ($mldbm) ---\n";
         eval { do_test( $dbm_type, \...@sql, $mldbm ) }
@@ -142,16 +142,25 @@
             1 => 'oranges',
             2 => 'apples',
             3 => $null,
+            5 => 'via placeholders',
         };
         $expected_results = {
             1 => '11',
             2 => '12',
             3 => '13',
+            5 => '15',
         } if $mldbm;
+
        print " $sql\n";
+        $sql =~ s/\s*;\s*(?:#(.*))//;
+        my $comment = $1;
+
         my $sth = $dbh->prepare($sql) or die $dbh->errstr;
-        $sth->execute;
+        my @bind;
+        @bind = split /,/, $comment if $sth->{NUM_OF_PARAMS};
+        $sth->execute(@bind);
         die $sth->errstr if $sth->err and $sql !~ /DROP/;
+
         next unless $sql =~ /SELECT/;
         my $results='';
         # Note that we can't rely on the order here, it's not portable,
@@ -173,6 +182,7 @@
 INSERT INTO  fruit VALUES (2,'to_change' );
 INSERT INTO  fruit VALUES (3, NULL       );
 INSERT INTO  fruit VALUES (4,'to delete' );
+INSERT INTO  fruit VALUES (?,?); #5,via placeholders
 UPDATE fruit SET dVal='apples' WHERE dKey=2;
 DELETE FROM  fruit WHERE dVal='to delete';
 SELECT * FROM fruit;
@@ -184,6 +194,7 @@
 INSERT INTO  multi_fruit VALUES (2,'apples'   ,  0 );
 INSERT INTO  multi_fruit VALUES (3, NULL      , 13 );
 INSERT INTO  multi_fruit VALUES (4,'to_delete', 14 );
+INSERT INTO  multi_fruit VALUES (?,?,?); #5,via placeholders,15
 UPDATE multi_fruit SET qux='12' WHERE dKey=2;
 DELETE FROM  multi_fruit WHERE dKey=4;
 SELECT dKey,qux FROM multi_fruit;

Reply via email to