line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::QuickDB::Driver::SQLite; |
2
|
5
|
|
|
5
|
|
176725
|
use strict; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
123
|
|
3
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
119
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
1110
|
use IPC::Cmd qw/can_run/; |
|
5
|
|
|
|
|
79476
|
|
|
5
|
|
|
|
|
250
|
|
6
|
5
|
|
|
5
|
|
31
|
use Scalar::Util qw/reftype/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
256
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.000022'; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
394
|
use parent 'DBIx::QuickDB::Driver'; |
|
5
|
|
|
|
|
231
|
|
|
5
|
|
|
|
|
26
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
316
|
use DBIx::QuickDB::Util::HashBase qw{-sqlite -started}; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
24
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ($SQLITE, $DBDSQLITE); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
BEGIN { |
17
|
5
|
|
|
5
|
|
22
|
local $@; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
24
|
$SQLITE = can_run('sqlite3'); |
20
|
5
|
|
|
|
|
1354
|
$DBDSQLITE = eval { require DBD::SQLite; 'DBD::SQLite' }; |
|
5
|
|
|
|
|
3297
|
|
|
0
|
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub version_string { |
24
|
0
|
|
|
0
|
1
|
0
|
my $binary; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Go in reverse order assuming the last param hash provided is most important |
27
|
0
|
|
|
|
|
0
|
for my $arg (reverse @_) { |
28
|
0
|
0
|
|
|
|
0
|
my $type = reftype($arg) or next; # skip if not a ref |
29
|
0
|
0
|
|
|
|
0
|
next unless $type eq 'HASH'; # We have a hashref, possibly blessed |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# If we find a launcher we are done looping, we want to use this binary. |
32
|
0
|
0
|
|
|
|
0
|
$binary = $arg->{+SQLITE} and last; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# If no args provided one to use we fallback to the default from $PATH |
36
|
0
|
|
0
|
|
|
0
|
$binary ||= $SQLITE; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Call the binary with '-V', capturing and returning the output using backticks. |
39
|
0
|
|
|
|
|
0
|
return `$binary -version`; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
7
|
|
|
7
|
|
38
|
sub _default_paths { return (sqlite => $SQLITE) } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub viable { |
45
|
7
|
|
|
7
|
1
|
24
|
my $this = shift; |
46
|
7
|
|
|
|
|
13
|
my ($spec) = @_; |
47
|
|
|
|
|
|
|
|
48
|
7
|
50
|
|
|
|
24
|
my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec); |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
15
|
my @bad; |
51
|
7
|
50
|
|
|
|
21
|
push @bad => "'DBD::SQLite' module could not be loaded, needed for everything" unless $DBDSQLITE; |
52
|
|
|
|
|
|
|
|
53
|
7
|
50
|
|
|
|
19
|
return (1, undef) unless @bad; |
54
|
7
|
|
|
|
|
34
|
return (0, join "\n" => @bad); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub init { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
$self->SUPER::init(); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my %defaults = $self->_default_paths; |
62
|
0
|
|
0
|
|
|
|
$self->{$_} ||= $defaults{$_} for keys %defaults; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->{+STARTED} = 1; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
|
|
sub bootstrap { return } |
70
|
0
|
|
|
0
|
1
|
|
sub start { return } |
71
|
0
|
|
|
0
|
1
|
|
sub stop { return } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub clone { |
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
local $self->{+STARTED} = 0; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $self->SUPER::clone(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub connect_string { |
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my ($db_name) = @_; |
84
|
0
|
0
|
|
|
|
|
$db_name = 'quickdb' unless defined $db_name; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $dir = $self->{+DIR}; |
87
|
0
|
|
|
|
|
|
my $path = "$dir/$db_name"; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
require DBD::SQLite; |
90
|
0
|
|
|
|
|
|
return "dbi:SQLite:dbname=$path"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub load_sql { |
94
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
95
|
0
|
|
|
|
|
|
my ($db_name, $file) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $dbh = $self->connect($db_name, sqlite_allow_multiple_statements => 1, RaiseError => 1, AutoCommit => 1); |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
open(my $fh, '<', $file) or die "Could not open file '$file': $!"; |
100
|
0
|
|
|
|
|
|
my $sql = join "" => <$fh>; |
101
|
0
|
|
|
|
|
|
close($fh); |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
$dbh->do($sql) or die $dbh->errstr; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub shell_command { |
107
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
my ($db_name) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $dir = $self->{+DIR}; |
111
|
0
|
|
|
|
|
|
my $path = "$dir/$db_name"; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return ($self->{+SQLITE}, $path); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |