line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::SQLite::Transaction; |
2
|
6
|
|
|
6
|
|
38
|
use Mojo::Base -base; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
35
|
|
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
813
|
use Carp 'croak'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
2142
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '3.009'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has db => undef, weak => 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %behaviors = map { ($_ => 1) } qw(deferred immediate exclusive); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
25
|
|
|
25
|
1
|
80
|
my $self = shift->SUPER::new(@_, rollback => 1); |
14
|
25
|
|
|
|
|
619
|
my $dbh = $self->{dbh} = $self->db->dbh; |
15
|
25
|
100
|
|
|
|
152
|
if (my $behavior = $self->{behavior}) { |
16
|
22
|
50
|
|
|
|
75
|
croak qq{Invalid transaction behavior $behavior} unless exists $behaviors{lc $behavior}; |
17
|
22
|
|
|
|
|
110
|
$dbh->do("begin $behavior transaction"); |
18
|
|
|
|
|
|
|
} else { |
19
|
3
|
|
|
|
|
53
|
$dbh->begin_work; |
20
|
|
|
|
|
|
|
} |
21
|
25
|
|
|
|
|
851
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY { |
25
|
25
|
|
|
25
|
|
118
|
my $self = shift; |
26
|
25
|
100
|
66
|
|
|
120
|
if ($self->{rollback} && (my $dbh = $self->{dbh})) { $dbh->rollback } |
|
5
|
|
|
|
|
170
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub commit { |
30
|
20
|
|
|
20
|
1
|
32
|
my $self = shift; |
31
|
20
|
50
|
|
|
|
7225
|
$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 |