File: 20savepoints.t

package info (click to toggle)
libdbd-pg-perl 3.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,428 kB
  • sloc: perl: 10,202; ansic: 5,977; makefile: 15
file content (64 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
64
#!perl

## Test savepoint functionality

use 5.008001;
use strict;
use warnings;
use lib 'blib/lib', 'blib/arch', 't';
use Test::More;
use DBI ':sql_types';
require 'dbdpg_test_setup.pl';
select(($|=1,select(STDERR),$|=1)[1]);

my $dbh = connect_database();

if (! $dbh) {
    plan skip_all => 'Connection to database failed, cannot continue testing';
}
plan tests => 3;

isnt ($dbh, undef, 'Connect to database for savepoint testing');

my $t;

my $str = 'Savepoint Test';
my $sth = $dbh->prepare('INSERT INTO dbd_pg_test (id,pname) VALUES (?,?)');

## Create 500 without a savepoint
$sth->execute(500,$str);

## Create 501 inside a savepoint and roll it back
$dbh->pg_savepoint('dbd_pg_test_savepoint');
$sth->execute(501,$str);

$dbh->pg_rollback_to('dbd_pg_test_savepoint');
$dbh->pg_rollback_to('dbd_pg_test_savepoint'); ## Yes, we call it twice

## Create 502 after the rollback:
$sth->execute(502,$str);

$dbh->commit;

$t='Only row 500 and 502 should be committed';
my $ids = $dbh->selectcol_arrayref('SELECT id FROM dbd_pg_test WHERE pname = ?',undef,$str);
ok (eq_set($ids, [500, 502]), $t);

## Create 503, then release the savepoint
$dbh->pg_savepoint('dbd_pg_test_savepoint');
$sth->execute(503,$str);
$dbh->pg_release('dbd_pg_test_savepoint');

## Create 504 outside of any savepoint
$sth->execute(504,$str);
$dbh->commit;

$t='Implicit rollback on deallocate should rollback to last savepoint';
$ids = $dbh->selectcol_arrayref('SELECT id FROM dbd_pg_test WHERE pname = ?',undef,$str);
ok (eq_set($ids, [500, 502, 503, 504]), $t);

$dbh->do('DELETE FROM dbd_pg_test');
$dbh->commit();

cleanup_database($dbh,'test');
$dbh->disconnect();