| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bif::DBW; |
|
2
|
45
|
|
|
45
|
|
1450
|
use strict; |
|
|
45
|
|
|
|
|
74
|
|
|
|
45
|
|
|
|
|
1142
|
|
|
3
|
45
|
|
|
45
|
|
233
|
use warnings; |
|
|
45
|
|
|
|
|
91
|
|
|
|
45
|
|
|
|
|
1134
|
|
|
4
|
45
|
|
|
45
|
|
18350
|
use Bif::DB; |
|
|
45
|
|
|
|
|
145
|
|
|
|
45
|
|
|
|
|
388
|
|
|
5
|
45
|
|
|
45
|
|
1636
|
use DBIx::ThinSQL qw//; |
|
|
45
|
|
|
|
|
100
|
|
|
|
45
|
|
|
|
|
931
|
|
|
6
|
45
|
|
|
45
|
|
35985
|
use DBIx::ThinSQL::SQLite ':all'; |
|
|
45
|
|
|
|
|
106497
|
|
|
|
45
|
|
|
|
|
326
|
|
|
7
|
45
|
|
|
45
|
|
6019
|
use Log::Any '$log'; |
|
|
45
|
|
|
|
|
136
|
|
|
|
45
|
|
|
|
|
227
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.1.5_6'; |
|
10
|
|
|
|
|
|
|
our @ISA = ('Bif::DB'); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
create_methods(qw/nextval currval/); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _connected { |
|
15
|
132
|
|
|
132
|
|
286
|
my $dbh = shift; |
|
16
|
132
|
|
|
|
|
249
|
my $debug = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
132
|
50
|
|
0
|
|
447
|
$dbh->sqlite_trace( sub { $log->debug(@_) } ) if $debug; |
|
|
0
|
|
|
|
|
0
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
132
|
|
|
|
|
986
|
$dbh->do('PRAGMA foreign_keys = ON;'); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# $dbh->do('PRAGMA foreign_keys = OFF;'); |
|
23
|
132
|
|
|
|
|
16925
|
$dbh->do('PRAGMA temp_store = MEMORY;'); |
|
24
|
132
|
|
|
|
|
11007
|
$dbh->do('PRAGMA recursive_triggers = ON;'); |
|
25
|
132
|
|
|
|
|
10249
|
$dbh->do('PRAGMA synchronous = NORMAL;'); |
|
26
|
132
|
50
|
|
|
|
651764
|
$dbh->do('PRAGMA synchronous = OFF;') if $main::BIF_DB_NOSYNC; |
|
27
|
|
|
|
|
|
|
|
|
28
|
132
|
|
|
|
|
11608
|
create_functions( $dbh, |
|
29
|
|
|
|
|
|
|
qw/debug warn create_sequence nextval currval sha1_hex agg_sha1_hex/ ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# TODO remove the following two statements before the first |
|
32
|
|
|
|
|
|
|
# production release. |
|
33
|
132
|
|
|
|
|
197790
|
$dbh->do('PRAGMA reverse_unordered_selects = ON;'); |
|
34
|
|
|
|
|
|
|
$dbh->sqlite_create_function( |
|
35
|
|
|
|
|
|
|
'check_fks', |
|
36
|
|
|
|
|
|
|
-1, |
|
37
|
|
|
|
|
|
|
sub { |
|
38
|
0
|
|
|
0
|
|
0
|
$dbh->check_fks; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
132
|
|
|
|
|
12574
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
132
|
|
|
|
|
860
|
return; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub connect { |
|
46
|
132
|
|
|
132
|
1
|
21854
|
my $class = shift; |
|
47
|
132
|
|
|
|
|
256
|
my $dsn = shift; |
|
48
|
132
|
|
|
|
|
280
|
my ( $user, $password, $attrs, $debug ) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$attrs ||= { |
|
51
|
|
|
|
|
|
|
RaiseError => 1, |
|
52
|
|
|
|
|
|
|
PrintError => 0, |
|
53
|
|
|
|
|
|
|
ShowErrorStatement => 1, |
|
54
|
|
|
|
|
|
|
sqlite_see_if_its_a_number => 1, |
|
55
|
|
|
|
|
|
|
sqlite_unicode => 1, |
|
56
|
|
|
|
|
|
|
Callbacks => { |
|
57
|
132
|
|
|
132
|
|
134025
|
connected => sub { _connected( shift, $debug ) } |
|
58
|
|
|
|
|
|
|
}, |
|
59
|
132
|
|
50
|
|
|
2080
|
}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
132
|
|
|
|
|
980
|
return $class->SUPER::connect( $dsn, $user, $password, $attrs ); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package Bif::DBW::db; |
|
65
|
|
|
|
|
|
|
our @ISA = ('Bif::DB::db'); |
|
66
|
|
|
|
|
|
|
|
|
67
|
45
|
|
|
45
|
|
20306
|
use DBIx::ThinSQL qw/case qv sq/; |
|
|
45
|
|
|
|
|
95
|
|
|
|
45
|
|
|
|
|
308
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub deploy { |
|
70
|
85
|
|
|
85
|
|
221
|
my $db = shift; |
|
71
|
85
|
|
33
|
|
|
378
|
my $version = shift || Carp::croak('deploy(VERSION)'); |
|
72
|
|
|
|
|
|
|
|
|
73
|
85
|
|
|
|
|
32569
|
require DBIx::ThinSQL::Deploy; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$db->txn( |
|
76
|
|
|
|
|
|
|
sub { |
|
77
|
85
|
50
|
|
85
|
|
29725
|
if ( defined &static::find ) { |
|
78
|
|
|
|
|
|
|
my $src = |
|
79
|
0
|
|
|
|
|
0
|
'auto/share/dist/App-bif/' . $db->{Driver}->{Name} . '.sql'; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $sql = static::find($src) |
|
82
|
0
|
0
|
|
|
|
0
|
or die 'unsupported database type: ' . $db->{Driver}->{Name}; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
DBIx::ThinSQL::SQLite::create_sqlite_sequence($db); |
|
85
|
0
|
|
|
|
|
0
|
return $db->deploy_sql($sql); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
85
|
|
|
|
|
33600
|
require File::ShareDir; |
|
89
|
85
|
|
|
|
|
263887
|
require Path::Tiny; |
|
90
|
|
|
|
|
|
|
|
|
91
|
85
|
|
33
|
|
|
762
|
my $share_dir = $main::BIF_SHARE_DIR |
|
92
|
|
|
|
|
|
|
|| File::ShareDir::dist_dir('App-bif'); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $deploy_dir = Path::Tiny::path( |
|
95
|
|
|
|
|
|
|
$share_dir, |
|
96
|
|
|
|
|
|
|
$db->{Driver}->{Name}, |
|
97
|
85
|
|
|
|
|
2800
|
'db-v' . $version |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
85
|
50
|
|
|
|
4246
|
die "\nDirectory not found: " . $deploy_dir |
|
101
|
|
|
|
|
|
|
unless -d $deploy_dir; |
|
102
|
|
|
|
|
|
|
|
|
103
|
85
|
|
|
|
|
3798
|
DBIx::ThinSQL::SQLite::create_sqlite_sequence($db); |
|
104
|
85
|
|
|
|
|
37724
|
return $db->deploy_dir($deploy_dir); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
85
|
|
|
|
|
126915
|
); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
package Bif::DBW::st; |
|
111
|
|
|
|
|
|
|
our @ISA = ('Bif::DB::st'); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=for bif-doc #perl |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Bif::DBW - read-write helper methods for a bif database |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 VERSION |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
0.1.5_6 (2015-10-20) |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use strict; |
|
128
|
|
|
|
|
|
|
use warnings; |
|
129
|
|
|
|
|
|
|
use Bif::DBW; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Bif::DBW inherits Bif::DB -> DBIx::ThinSQL -> DBI. |
|
132
|
|
|
|
|
|
|
my $dbw = Bif::DBW->connect( $dsn ); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Read and write operations on a bif database: |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$dbw->txn(sub { |
|
137
|
|
|
|
|
|
|
my ($old,$new) = $dbw->deploy; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$dbw->xdo( |
|
140
|
|
|
|
|
|
|
insert_into => 'changes', |
|
141
|
|
|
|
|
|
|
values => $hashref, |
|
142
|
|
|
|
|
|
|
); |
|
143
|
|
|
|
|
|
|
}); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
B is a L derivative that provides various read-write |
|
148
|
|
|
|
|
|
|
methods for retrieving information from a L repository. For a |
|
149
|
|
|
|
|
|
|
read-only equivalent see L. The read-only and read-write parts |
|
150
|
|
|
|
|
|
|
are separated for security and performance reasons. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 DBH METHODS |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item nextval( $name ) -> Int |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Advance the sequence C<$name> to its next value and return that value. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item currval( $name ) -> Int |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Return the current value of the sequence <$name>. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item deploy -> (Int, Int) |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Deploys the current Bif distribution schema to the database, returning |
|
167
|
|
|
|
|
|
|
the previous (possibly 0) and newly deployed versions. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SQLITE FUNCTIONS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The following SQL functions created using the user-defined-function |
|
174
|
|
|
|
|
|
|
feature of SQLite. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=over |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item create_sequence() |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
TODO |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item nextval( $name ) -> Int |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Advance the sequence C<$name> to its next value and return that value. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item currval( $name ) -> Int |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Return the current value of the sequence <$name>. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item debug() |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
TODO |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item sha1_hex() |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
TODO |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item agg_sha1_hex() |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
TODO |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L, L |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 AUTHOR |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Mark Lawrence Enomad@null.netE |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Copyright 2013-2015 Mark Lawrence |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
217
|
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the |
|
218
|
|
|
|
|
|
|
Free Software Foundation; either version 3 of the License, or (at your |
|
219
|
|
|
|
|
|
|
option) any later version. |
|
220
|
|
|
|
|
|
|
|