/
06-compound-keys.t
54 lines (41 loc) · 920 Bytes
/
06-compound-keys.t
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
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl6
use lib 'lib';
use lib 't/lib';
use DB::Xoos::SQLite;
use Test;
use DB::Xoos::Test;
use DBIish;
plan 2;
configure-sqlite;
my $cwd = $*CWD;
$*CWD = 't'.IO;
my DB::Xoos::SQLite $d .=new;
my $db = DBIish.connect('SQLite', database => 'test.sqlite3');
$d.connect(:$db, :options({
prefix => 'X',
}));
my ($sth, $scratch);
my $e = $d.model('Multikey');
my $c = $e.new-row;
$c.key1('customer 1');
$c.key2('joe schmoe');
$c.val('xyz');
$c.update;
my $c2 = $e.new-row;
$c2.key1('customer 1');
$c2.key2('joe schmoe');
$c2.val('val');
my $err;
my $upd = -> {
try {
CATCH { default { $err = $_; } };
$c2.update;
$err = Any;
};
};
$upd();
ok $err.^can('message') && $err.message ~~ m{'Primary key constraint violated: '}, 'update should fail because of key constraint';
$c2.key1('customer 2');
$upd();
ok Any ~~ $err, 'update should succeed with key1 changed';
$*CWD = $cwd;