|
Packit |
723767 |
#!/usr/bin/perl
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use strict;
|
|
Packit |
723767 |
BEGIN {
|
|
Packit |
723767 |
$| = 1;
|
|
Packit |
723767 |
$^W = 1;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use Test::More tests => 21;
|
|
Packit |
723767 |
use lib "t/lib";
|
|
Packit |
723767 |
use SQLiteTest;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# 1-4. Connect & create tables
|
|
Packit |
723767 |
my $dbh = connect_ok(dbfile => 'foo');
|
|
Packit |
723767 |
ok $dbh->do('CREATE TABLE meta1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1))'), 'Create table meta1';
|
|
Packit |
723767 |
ok $dbh->do('CREATE TABLE meta2 (f1 VARCHAR(2), f2 CHAR(1), PRIMARY KEY (f1))'), 'Create table meta2';
|
|
Packit |
723767 |
ok $dbh->do('CREATE TABLE meta3 (f2 CHAR(1), f1 VARCHAR(2) PRIMARY KEY)'), 'Create table meta3';
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$dbh->trace(0);
|
|
Packit |
723767 |
$DBI::neat_maxlen = 4000;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# 5-10. Get & check primary_key_info
|
|
Packit |
723767 |
for my $table (qw(meta1 meta2 meta3)) {
|
|
Packit |
723767 |
ok my $sth = $dbh->primary_key_info(undef, undef, $table), "Get primary_key_info for $table";
|
|
Packit |
723767 |
my $pki = $sth->fetchall_arrayref([3,4]);
|
|
Packit |
723767 |
#use Data::Dumper; print Dumper($pki);
|
|
Packit |
723767 |
is_deeply $pki, [['f1', 1]], "Correct primary_key_info returned for $table";
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# 11-14. Multi column primary key
|
|
Packit |
723767 |
ok $dbh->do('CREATE TABLE meta4 (f1 VARCHAR(2), f2 CHAR(1), PRIMARY KEY (f1,f2))'), 'Create table meta4';
|
|
Packit |
723767 |
ok my $sth = $dbh->primary_key_info(undef, undef, 'meta4'), 'Get primary_key_info for meta4';
|
|
Packit |
723767 |
my $pki = $sth->fetchall_arrayref({COLUMN_NAME => 1, KEY_SEQ => 1});
|
|
Packit |
723767 |
#use Data::Dumper; print Dumper($pki);
|
|
Packit |
723767 |
is @$pki, 2, 'Primary key contains 2 columns';
|
|
Packit |
723767 |
is_deeply $pki, [{COLUMN_NAME => 'f1', KEY_SEQ => 1},{COLUMN_NAME => 'f2', KEY_SEQ => 2}],
|
|
Packit |
723767 |
'Correct primary_key_info returned for meta4';
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# 15,16. Test primary_key
|
|
Packit |
723767 |
ok my @pk = $dbh->primary_key(undef, undef, 'meta4'), 'Get primary_key for meta4';
|
|
Packit |
723767 |
is_deeply \@pk, [qw(f1 f2)], 'Correct primary_key returned for meta4';
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# 17-21. I'm not sure what this is testing
|
|
Packit |
723767 |
$dbh->do("INSERT INTO meta4 VALUES ('xyz', 'b')");
|
|
Packit |
723767 |
$sth = $dbh->prepare('SELECT * FROM meta4');
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
$sth->fetch;
|
|
Packit |
723767 |
my $types = $sth->{TYPE};
|
|
Packit |
723767 |
my $names = $sth->{NAME};
|
|
Packit |
723767 |
# diag "Types: @$types\nNames: @$names";
|
|
Packit |
723767 |
is scalar @$types, scalar @$names, '$sth->{TYPE} array is same length as $sth->{NAME} array';
|
|
Packit |
723767 |
# FIXME: This is wrong! $sth->{TYPE} should return an array of integers see: rt #46873
|
|
Packit |
723767 |
TODO: {
|
|
Packit |
723767 |
local $TODO = '$sth->{TYPE} should return an array of integers.';
|
|
Packit |
723767 |
isnt $types->[0], 'VARCHAR(2)', '$sth->{TYPE}[0] doesn\'t return a string';
|
|
Packit |
723767 |
isnt $types->[1], 'CHAR(1)', '$sth->{TYPE}[1] doesn\'t return a string';
|
|
Packit |
723767 |
like $types->[0], qr/^-?\d+$/, '$sth->{TYPE}[0] returns an integer';
|
|
Packit |
723767 |
like $types->[1], qr/^-?\d+$/, '$sth->{TYPE}[1] returns an integer';
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|