/
07-cursor.t
49 lines (30 loc) · 959 Bytes
/
07-cursor.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
use Test;
use Test::When <extended>;
use DB::Pg;
plan 9;
my $pg = DB::Pg.new;
lives-ok { $pg.execute(q:to//) }, 'create table test';
create table test
(
x int,
y text
)
my $db = $pg.db;
lives-ok { $db.begin }, 'begin';
ok my $sth = $db.prepare('insert into test values ($1, $2)'), 'prepare';
$sth.execute($_, "line $_ here") for ^10000;
lives-ok { $db.commit }, 'commit';
$db.finish;
is $pg.query('select count(*) from test').value, 10000, '10000 rows inserted';
my @cursor = $pg.cursor('select * from test order by x', :hash);
my $count = 0;
for @cursor -> $row
{
$count++ if $row eqv %( x => $count, y => "line $count here");
}
is $count, 10000, '10000 rows retrieved';
lives-ok { $pg.execute('delete from test') }, 'Delete rows';
@cursor = $pg.cursor('select * from test', :hash);
is-deeply @cursor, [], 'No rows from cursor';
lives-ok { $pg.execute('drop table test') }, 'drop table test';
done-testing;