line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
6
|
|
|
6
|
|
3921
|
use 5.008001; |
|
6
|
|
|
|
|
17
|
|
2
|
6
|
|
|
6
|
|
32
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
161
|
|
3
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
1744
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Metabase::Backend::SQLite; |
6
|
|
|
|
|
|
|
# ABSTRACT: Metabase backend implemented using SQLite |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.001'; |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
3281
|
use MooseX::Types::Path::Class; |
|
6
|
|
|
|
|
636919
|
|
|
6
|
|
|
|
|
41
|
|
11
|
6
|
|
|
6
|
|
4743
|
use Moose::Role; |
|
6
|
|
|
|
|
35
|
|
|
6
|
|
|
|
|
61
|
|
12
|
6
|
|
|
6
|
|
30034
|
use DBD::SQLite; |
|
6
|
|
|
|
|
126974
|
|
|
6
|
|
|
|
|
238
|
|
13
|
6
|
|
|
6
|
|
65
|
use namespace::autoclean; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
65
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Metabase::Backend::SQL'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'filename' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => 'Path::Class::File', |
20
|
|
|
|
|
|
|
coerce => 1, |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'synchronous' => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
isa => 'Bool', |
27
|
|
|
|
|
|
|
default => 0, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has 'page_size' => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
isa => 'Int', |
33
|
|
|
|
|
|
|
predicate => 'has_page_size', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'cache_size' => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => 'Int', |
39
|
|
|
|
|
|
|
predicate => 'has_cache_size', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _build_dsn { |
43
|
79
|
|
|
79
|
|
169
|
my $self = shift; |
44
|
79
|
|
|
|
|
2749
|
return "dbi:SQLite:dbname=" . $self->filename; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
79
|
|
|
79
|
|
2399
|
sub _build_db_user { return "" } |
48
|
|
|
|
|
|
|
|
49
|
79
|
|
|
79
|
|
2584
|
sub _build_db_pass { return "" } |
50
|
|
|
|
|
|
|
|
51
|
79
|
|
|
79
|
|
2405
|
sub _build_db_type { return "SQLite" } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
around _build_dbis => sub { |
54
|
|
|
|
|
|
|
my $orig = shift; |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
my $dbis = $self->$orig; |
57
|
|
|
|
|
|
|
my $toggle = $self->synchronous ? "ON" : "OFF"; |
58
|
|
|
|
|
|
|
$dbis->query("PRAGMA synchronous = $toggle"); |
59
|
|
|
|
|
|
|
for my $pragma ( qw/page_size cache_size/ ) { |
60
|
|
|
|
|
|
|
my $pred = "has_$pragma"; |
61
|
|
|
|
|
|
|
if ( $self->$pred ) { |
62
|
|
|
|
|
|
|
$dbis->query("PRAGMA $pragma = " . $self->$pragma); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
return $dbis; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _fixup_sql_diff { |
69
|
80
|
|
|
80
|
|
264
|
my ($self, $diff) = @_; |
70
|
|
|
|
|
|
|
# Fix up BEGIN/COMMIT |
71
|
80
|
|
|
|
|
677
|
$diff =~ s/BEGIN;/BEGIN TRANSACTION;/mg; |
72
|
80
|
|
|
|
|
539
|
$diff =~ s/COMMIT;/COMMIT TRANSACTION;/mg; |
73
|
|
|
|
|
|
|
# Strip comments |
74
|
80
|
|
|
|
|
526
|
$diff =~ s/^--[^\n]*$//msg; |
75
|
|
|
|
|
|
|
# strip empty lines |
76
|
80
|
|
|
|
|
1002
|
$diff =~ s/^\n//msg; |
77
|
80
|
|
|
|
|
581
|
return $diff; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _build__guid_field_params { |
81
|
|
|
|
|
|
|
return { |
82
|
79
|
|
|
79
|
|
2832
|
data_type => 'char', |
83
|
|
|
|
|
|
|
size => 36, |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _build__blob_field_params { |
88
|
|
|
|
|
|
|
return { |
89
|
9
|
|
|
9
|
|
306
|
data_type => 'blob' |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $hex = qr/[0-9a-f]/i; |
94
|
|
|
|
|
|
|
sub _munge_guid { |
95
|
208
|
|
|
208
|
|
464
|
my ($self, $guid) = @_; |
96
|
208
|
100
|
|
|
|
2450
|
$guid = "00000000-0000-0000-0000-000000000000" |
97
|
|
|
|
|
|
|
unless $guid =~ /${hex}{8}-${hex}{4}-${hex}{4}-${hex}{4}-${hex}{12}/; |
98
|
208
|
|
|
|
|
695
|
return $guid; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _unmunge_guid { |
102
|
20
|
|
|
20
|
|
43
|
my ($self, $guid) = @_; |
103
|
20
|
|
|
|
|
621
|
return $guid; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# vim: ts=2 sts=2 sw=2 et: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=pod |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=encoding UTF-8 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 NAME |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Metabase::Backend::SQLite - Metabase backend implemented using SQLite |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 VERSION |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
version 1.001 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
require Metabase::Archive::SQLite; |
128
|
|
|
|
|
|
|
require Metabase::Index::SQLite; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $archive = Metabase::Archive::SQLite->new( |
131
|
|
|
|
|
|
|
filename => $sqlite_file, |
132
|
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $index = Metabase::Index::SQLite->new( |
135
|
|
|
|
|
|
|
filename => $sqlite_file, |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DESCRIPTION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This distribution provides several backends for L<Metabase> using SQLite. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L<Metabase::Archive::SQLite> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<Metabase::Archive::SQLite::Sharded>. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<Metabase::Index::SQLite> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Metabase::Index::SQLite::Sharded>. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
They can be used separately or together (see L<Metabase::Librarian> for |
163
|
|
|
|
|
|
|
details). |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The L<Metabase::Backend::SQLite> module is a L<Moose::Role> that provides |
166
|
|
|
|
|
|
|
common attributes and private helpers and is not intended to be used directly. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Common attributes are described further below. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 filename |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Path to an SQLite database |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 synchronous |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Controls how SQLite should set the C<synchronous> pragma. Defaults to false, |
179
|
|
|
|
|
|
|
which is faster, but less safe. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=for Pod::Coverage method_names_here |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHORS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over 4 |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
David Golden <dagolden@cpan.org> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Leon Brocard <acme@astray.org> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=back |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This software is Copyright (c) 2011 by David Golden. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This is free software, licensed under: |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |