1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00
DBD-SQLite-SQLcipher/t/rt_81536_multi_column_primary_key_info.t
Kenichi Ishigaki 8fae2f1dee resolved #81536
2012-11-29 13:57:06 +00:00

50 lines
1.3 KiB
Perl

#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test qw/connect_ok/;
use Test::More;
use Test::NoWarnings;
plan tests => 10 + 1;
# single column integer primary key
{
my $dbh = connect_ok();
$dbh->do("create table foo (id integer primary key, type text)");
my $sth = $dbh->primary_key_info(undef, undef, 'foo');
my @pk_info;
while(my $row = $sth->fetchrow_hashref) { push @pk_info, $row };
is @pk_info => 1, "found 1 pks";
is $pk_info[0]{COLUMN_NAME} => 'id', "first pk name is id";
}
# single column not-integer primary key
{
my $dbh = connect_ok();
$dbh->do("create table foo (id text primary key, type text)");
my $sth = $dbh->primary_key_info(undef, undef, 'foo');
my @pk_info;
while(my $row = $sth->fetchrow_hashref) { push @pk_info, $row };
is @pk_info => 1, "found 1 pks";
is $pk_info[0]{COLUMN_NAME} => 'id', "first pk name is id";
}
# multi-column primary key
{
my $dbh = connect_ok();
$dbh->do("create table foo (id id, type text, primary key(type, id))");
my $sth = $dbh->primary_key_info(undef, undef, 'foo');
my @pk_info;
while(my $row = $sth->fetchrow_hashref) { push @pk_info, $row };
is @pk_info => 2, "found 1 pks";
is $pk_info[0]{COLUMN_NAME} => 'type', "first pk name is type";
is $pk_info[1]{COLUMN_NAME} => 'id', "second pk name is id";
}