File: 03_multi_pk.t

package info (click to toggle)
libclass-dbi-sqlite-perl 0.11-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 80 kB
  • sloc: perl: 66; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use strict;
use Test::More tests => 2;

use Class::DBI::SQLite;
use DBI;
use Carp qw( confess );

unlink './t/multi_pk.db' if -e './t/multi_pk.db';

my $dbh = DBI->connect(
    'dbi:SQLite:dbname=./t/multi_pk.db', '', '',
    {
	RaiseError => 1,
	PrintError => 1,
	AutoCommit => 1
    }
);

$dbh->do('CREATE TABLE multi_pk (revision INTEGER, version INTEGER, msg TEXT, PRIMARY KEY (revision,version) )');

package MultiPK;
use base qw(Class::DBI::SQLite);

__PACKAGE__->connection('dbi:SQLite:dbname=./t/multi_pk.db', '', '');
__PACKAGE__->set_up_table('multi_pk');

package main;

my @pks = sort MultiPK->primary_columns;
is_deeply( \@pks, [qw(revision version)] );

for (1..10) {
    MultiPK->create({
        revision  => $_,
	version  => $_,
	msg      => "version $_",
    });
}

my $obj = MultiPK->retrieve( revision => 3, version => 3 );
is($obj->msg, 'version 3');

END {
    unlink './t/multi_pk.db';
}