line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::SQLite::Transaction; |
2
|
6
|
|
|
6
|
|
39
|
use Mojo::Base -base; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
986
|
use Carp 'croak'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
2298
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '3.007'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has db => undef, weak => 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %behaviors = map { ($_ => 1) } qw(deferred immediate exclusive); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
23
|
|
|
23
|
1
|
90
|
my $self = shift->SUPER::new(@_, rollback => 1); |
14
|
23
|
|
|
|
|
612
|
my $dbh = $self->{dbh} = $self->db->dbh; |
15
|
23
|
50
|
|
|
|
151
|
if (my $behavior = $self->{behavior}) { |
16
|
0
|
0
|
|
|
|
0
|
croak qq{Invalid transaction behavior $behavior} unless exists $behaviors{lc $behavior}; |
17
|
0
|
|
|
|
|
0
|
$dbh->do("begin $behavior transaction"); |
18
|
|
|
|
|
|
|
} else { |
19
|
23
|
|
|
|
|
106
|
$dbh->begin_work; |
20
|
|
|
|
|
|
|
} |
21
|
23
|
|
|
|
|
303
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY { |
25
|
23
|
|
|
23
|
|
116
|
my $self = shift; |
26
|
23
|
100
|
66
|
|
|
117
|
if ($self->{rollback} && (my $dbh = $self->{dbh})) { $dbh->rollback } |
|
5
|
|
|
|
|
163
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub commit { |
30
|
18
|
|
|
18
|
1
|
30
|
my $self = shift; |
31
|
18
|
50
|
|
|
|
1798
|
$self->{dbh}->commit if delete $self->{rollback}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Mojo::SQLite::Transaction - Transaction |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use Mojo::SQLite::Transaction; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $tx = Mojo::SQLite::Transaction->new(db => $db); |
45
|
|
|
|
|
|
|
$tx->commit; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
L is a scope guard for L transactions |
50
|
|
|
|
|
|
|
used by L. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L implements the following attributes. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 db |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $db = $tx->db; |
59
|
|
|
|
|
|
|
$tx = $tx->db(Mojo::SQLite::Database->new); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L object this transaction belongs to. Note that this |
62
|
|
|
|
|
|
|
attribute is weakened. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 METHODS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L inherits all methods from L and |
67
|
|
|
|
|
|
|
implements the following new ones. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 new |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $tx = Mojo::SQLite::Transaction->new; |
72
|
|
|
|
|
|
|
my $tx = Mojo::SQLite::Transaction->new(db => Mojo::SQLite::Database->new); |
73
|
|
|
|
|
|
|
my $tx = Mojo::SQLite::Transaction->new({db => Mojo::SQLite::Database->new}); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Construct a new L object. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 commit |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$tx->commit; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Commit transaction. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 BUGS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Dan Book, C |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Copyright 2015, Dan Book. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or modify it under |
96
|
|
|
|
|
|
|
the terms of the Artistic License version 2.0. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |