File: 66_get_autocommit.t

package info (click to toggle)
libdbd-sqlite3-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,004 kB
  • sloc: ansic: 167,715; perl: 1,788; pascal: 277; makefile: 9
file content (57 lines) | stat: -rw-r--r-- 1,863 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
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest qw/connect_ok @CALL_FUNCS/;
use Test::More;
use if -d ".git", "Test::FailWarnings";

for my $func (@CALL_FUNCS) {
	my $dbh = connect_ok(PrintError => 0, RaiseError => 1);
    $dbh->do('create table foo (id)');

    note 'begin_work does not make autocommit false';
    my $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is true";
    ok $dbh->{AutoCommit}, "AutoCommit is also true";

    $dbh->begin_work;
    $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is still true";
    ok !$dbh->{AutoCommit}, "AutoCommit gets false";

    $dbh->do('insert into foo values (1)');
    $dbh->commit;

    $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is still true";
    ok $dbh->{AutoCommit}, "AutoCommit is true now";

    note 'nor turning AutoCommit off does not make autocommit false';
    $dbh->{AutoCommit} = 0;
    $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is still true";
    ok !$dbh->{AutoCommit}, "AutoCommit is false";

    $dbh->do('insert into foo values (1)');
    $dbh->commit;
    $dbh->{AutoCommit} = 1;

    $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is still true";
    ok $dbh->{AutoCommit}, "AutoCommit is true now";

    note 'explicit BEGIN make autocommit false';
    $dbh->do('BEGIN');
    $autocommit = $dbh->$func('get_autocommit');
    ok !$autocommit, "internal autocommit gets false";
    ok !$dbh->{AutoCommit}, "AutoCommit is also false";

    $dbh->do('insert into foo values (1)');
    $dbh->commit;

    $autocommit = $dbh->$func('get_autocommit');
    ok $autocommit, "internal autocommit is true now";
    ok $dbh->{AutoCommit}, "AutoCommit is true now";
}

done_testing;