1use strict; 2use warnings; 3 4use Test::More; 5use DBI; 6use lib 't', '.'; 7require 'lib.pl'; 8$|= 1; 9 10use vars qw($test_dsn $test_user $test_password); 11my $dbh; 12eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password, 13 { RaiseError => 1, PrintError => 1, AutoCommit => 0 });}; 14 15if ($@) { 16 plan skip_all => "no database connection"; 17} 18plan tests => 7; 19 20$dbh->{mysql_server_prepare}= 0; 21 22ok(defined $dbh, "Connected to database for key info tests"); 23 24ok($dbh->do("DROP TABLE IF EXISTS dbd_mysql_keyinfo"), "Dropped table"); 25 26# Non-primary key is there as a regression test for Bug #26786. 27ok($dbh->do("CREATE TABLE dbd_mysql_keyinfo (a int, b varchar(20), c int, 28 primary key (a,b(10)), key (c))"), 29 "Created table dbd_mysql_keyinfo"); 30 31my $sth= $dbh->primary_key_info(undef, undef, 'dbd_mysql_keyinfo'); 32ok($sth, "Got primary key info"); 33 34my $key_info= $sth->fetchall_arrayref; 35 36my $expect= [ 37 [ undef, undef, 'dbd_mysql_keyinfo', 'a', '1', 'PRIMARY' ], 38 [ undef, undef, 'dbd_mysql_keyinfo', 'b', '2', 'PRIMARY' ], 39 ]; 40is_deeply($key_info, $expect, "Check primary_key_info results"); 41 42is_deeply([ $dbh->primary_key(undef, undef, 'dbd_mysql_keyinfo') ], [ 'a', 'b' ], 43 "Check primary_key results"); 44 45ok($dbh->do("DROP TABLE dbd_mysql_keyinfo"), "Dropped table"); 46 47$dbh->disconnect(); 48