File: 70-nested-sth.t

package info (click to toggle)
libdbd-firebird-perl 0.91-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 680 kB
  • sloc: perl: 4,085; ansic: 2,262; makefile: 14
file content (98 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (8)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/local/bin/perl -w
#
#
#   This is a test for nested statement handles.
#

use strict;
use warnings;

use Test::More;
use lib 't','.';

use TestFirebird;
my $T = TestFirebird->new;

my ( $dbh, $error_str ) = $T->connect_to_database( { AutoCommit => 1 } );

if ($error_str) {
    BAIL_OUT("Unknown: $error_str!");
}

unless ( $dbh->isa('DBI::db') ) {
    plan skip_all => 'Connection to database failed, cannot continue testing';
}
else {
    plan tests => 24;
}

ok($dbh, 'Connected to the database');

# ------- TESTS ------------------------------------------------------------- #

my $table = find_new_table($dbh);
ok($table);

{
    my $def = "CREATE TABLE $table(id INTEGER, name VARCHAR(20))";
    ok($dbh->do($def));

    my $stmt = "INSERT INTO $table(id, name) VALUES(?, ?)";
    ok($dbh->do($stmt, undef, 1, 'Crocodile'));
}

# now ready to work

# BOTH hard and soft commit WORKS under AC off
{
    local $dbh->{AutoCommit} = 0;
    TRY_HARD_SOFT_COMMIT:
    {
        my $sth1 = $dbh->prepare("SELECT * FROM $table");
        ok($sth1);

        my $sth2 = $dbh->prepare("SELECT * FROM $table WHERE id = ?");
        ok($sth2);

        ok($sth1->execute);

        while (my $row = $sth1->fetchrow_arrayref) {
            ok($sth2->execute($row->[0]));

            my $res = $sth2->fetchall_arrayref;
            ok($res and @$res);
        }

        ok($dbh->commit);
        not $dbh->{ib_softcommit} and $dbh->{ib_softcommit} = 1
            and goto TRY_HARD_SOFT_COMMIT;
    }
}

# now try AC on
ok($dbh->{AutoCommit});

# AC on ONLY works provided that ib_softcommit is on
$dbh->{ib_softcommit} = 1;

{
    my $sth1 = $dbh->prepare("SELECT * FROM $table");
    ok($sth1);

    my $sth2 = $dbh->prepare("SELECT * FROM $table WHERE id = ?");
    ok($sth2);

    ok($sth1->execute);

    while (my $row = $sth1->fetchrow_arrayref) {
        ok($sth2->execute($row->[0]));

        my $res = $sth2->fetchall_arrayref;
        ok($res and @$res);
    }
}

#  Drop the test table
ok($dbh->do("DROP TABLE $table"));
ok($dbh->disconnect);