1use strict; 2use warnings; 3 4use DBI; 5 6use vars qw($test_dsn $test_user $test_password); 7require "t/lib.pl"; 8 9use Test::More; 10 11my $dbh; 12eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password, 13 { RaiseError => 1, PrintError => 0, AutoCommit => 1 });}; 14if ($@) { 15 plan skip_all => "no database connection"; 16} 17 18if (!MinimumVersion($dbh, '5.1')) { 19 plan skip_all => 20 "You must have MySQL version 5.1 or greater for this test" 21} 22 23plan tests => 8; 24 25my ( $sth, $i ); 26my @test = qw(AA Aa aa aA); 27 28for my $charset (qw(latin1 utf8)) { 29 for my $unique ( "", "unique" ) { 30 31 my $table = "dbd-mysql-$charset-$unique"; 32 my $create = 33"CREATE TEMPORARY TABLE `$table` (name VARCHAR(8) CHARACTER SET $charset COLLATE ${charset}_bin $unique)"; 34 35 $dbh->do($create) or die $DBI::errstr; 36 for (@test) { 37 $dbh->do("insert into `$table` values ('$_')"); 38 } 39 my $q1 = "select name from `$table`"; 40 $sth = $dbh->prepare($q1); 41 $sth->execute; 42 $i = 0; 43 while ( my @row = $sth->fetchrow ) { 44 $i++; 45 } 46 is( $i, scalar @test, $q1 ); 47 $sth->finish; 48 49 my $q2 = "select name from `$table` where " 50 . join( " OR ", map { "name = '$_'" } @test ); 51 $sth = $dbh->prepare($q2); 52 $sth->execute; 53 $i = 0; 54 while ( my @row = $sth->fetchrow ) { 55 $i++; 56 } 57 is( $i, scalar @test, $q2 ); 58 } 59} 60