line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################# |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Apache::Session::Browseable::SQLite |
4
|
|
|
|
|
|
|
# Apache persistent user sessions in a SQLite database |
5
|
|
|
|
|
|
|
# Copyright(c) 2013 Xavier Guimard |
6
|
|
|
|
|
|
|
# Inspired by Apache::Session::Store::Postgres |
7
|
|
|
|
|
|
|
# (copyright(c) 1998, 1999, 2000 Jeffrey William Baker (jwbaker@acm.org)) |
8
|
|
|
|
|
|
|
# Distribute under the Perl License |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
############################################################################ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Apache::Session::Browseable::Store::SQLite; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
17
|
use DBI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
100
|
|
17
|
2
|
|
|
2
|
|
962
|
use Apache::Session::Store::DBI; |
|
2
|
|
|
|
|
1555
|
|
|
2
|
|
|
|
|
68
|
|
18
|
2
|
|
|
2
|
|
1042
|
use Apache::Session::Browseable::Store::DBI; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1052
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::DBI); |
21
|
|
|
|
|
|
|
our $VERSION = '1.2.7'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$Apache::Session::Browseable::Store::SQLite::DataSource = undef; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub connection { |
26
|
59
|
|
|
59
|
0
|
134
|
my $self = shift; |
27
|
59
|
|
|
|
|
137
|
my $session = shift; |
28
|
|
|
|
|
|
|
|
29
|
59
|
100
|
|
|
|
279
|
return if ( defined $self->{dbh} ); |
30
|
|
|
|
|
|
|
$session->{args}->{Commit} = |
31
|
30
|
100
|
|
|
|
153
|
exists( $session->{args}->{Commit} ) ? $session->{args}->{Commit} : 1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{'table_name'} = $session->{args}->{TableName} |
34
|
30
|
|
33
|
|
|
292
|
|| $Apache::Session::Store::DBI::TableName; |
35
|
|
|
|
|
|
|
|
36
|
30
|
50
|
|
|
|
131
|
if ( exists $session->{args}->{Handle} ) { |
37
|
0
|
|
|
|
|
0
|
$self->{dbh} = $session->{args}->{Handle}; |
38
|
0
|
|
|
|
|
0
|
$self->{commit} = $session->{args}->{Commit}; |
39
|
0
|
|
|
|
|
0
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $datasource = $session->{args}->{DataSource} |
43
|
30
|
|
33
|
|
|
104
|
|| $Apache::Session::Store::MySQL::DataSource; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->{dbh} = |
46
|
30
|
|
50
|
|
|
228
|
DBI->connect( $datasource, '', '', { RaiseError => 1, AutoCommit => 0 } ) |
47
|
|
|
|
|
|
|
|| die $DBI::errstr; |
48
|
30
|
|
|
|
|
17180
|
$self->{dbh}->{sqlite_unicode} = 1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#If we open the connection, we close the connection |
51
|
30
|
|
|
|
|
114
|
$self->{disconnect} = 1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#the programmer has to tell us what commit policy to use |
54
|
30
|
|
|
|
|
133
|
$self->{commit} = $session->{args}->{Commit}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub materialize { |
58
|
1
|
|
|
1
|
0
|
57
|
my $self = shift; |
59
|
1
|
|
|
|
|
3
|
my $session = shift; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
4
|
$self->connection($session); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
11
|
local $self->{dbh}->{RaiseError} = 1; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
23
|
if ( !defined $self->{materialize_sth} ) { |
66
|
|
|
|
|
|
|
$self->{materialize_sth} = $self->{dbh}->prepare_cached( |
67
|
1
|
|
|
|
|
12
|
qq{ |
68
|
|
|
|
|
|
|
SELECT a_session FROM $self->{'table_name'} WHERE id = ?} |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
410
|
$self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} ); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
113
|
$self->{materialize_sth}->execute; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
39
|
my $results = $self->{materialize_sth}->fetchrow_arrayref; |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
39
|
if ( !( defined $results ) ) { |
79
|
0
|
|
|
|
|
0
|
$self->{materialize_sth}->finish; |
80
|
0
|
|
|
|
|
0
|
die "Object does not exist in the data store"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
19
|
$self->{materialize_sth}->finish; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
17
|
$session->{serialized} = $results->[0]; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub DESTROY { |
89
|
177
|
|
|
177
|
|
2342
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
177
|
100
|
|
|
|
472
|
if ( $self->{commit} ) { |
92
|
30
|
|
|
|
|
463203
|
$self->{dbh}->commit; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
177
|
100
|
|
|
|
2341
|
if ( $self->{disconnect} ) { |
96
|
30
|
|
|
|
|
5275
|
$self->{dbh}->disconnect; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=pod |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Apache::Session::Browseable::Store::SQLite - Store persistent data in a SQLite |
107
|
|
|
|
|
|
|
database |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
use Apache::Session::Browseable::Store::SQLite; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $store = new Apache::Session::Browseable::Store::SQLite; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$store->insert($ref); |
116
|
|
|
|
|
|
|
$store->update($ref); |
117
|
|
|
|
|
|
|
$store->materialize($ref); |
118
|
|
|
|
|
|
|
$store->remove($ref); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Apache::Session::Browseable::Store::SQLite fulfills the storage interface of |
123
|
|
|
|
|
|
|
Apache::Session. Session data is stored in a SQLite database. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SCHEMA |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
To use this module, you will need at least these columns in a table |
128
|
|
|
|
|
|
|
called 'sessions', or another name if you supply the TableName parameter. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
id char(32) # or however long your session IDs are. |
131
|
|
|
|
|
|
|
a_session text # This has an ~8 KB limit :( |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
To create this schema, you can execute this command using the sqlite program: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
CREATE TABLE sessions ( |
136
|
|
|
|
|
|
|
id char(32) not null primary key, |
137
|
|
|
|
|
|
|
a_session text |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
If you use some other command, ensure that there is a unique index on the |
141
|
|
|
|
|
|
|
table's id column. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 CONFIGURATION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The module must know what datasource, username, and password to use when |
146
|
|
|
|
|
|
|
connecting to the database. These values can be set using the options hash |
147
|
|
|
|
|
|
|
(see Apache::Session documentation). The options are: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item DataSource |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item UserName |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item Password |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item Handle |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item TableName |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Example: |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
tie %hash, 'Apache::Session::Browseable::SQLite', $id, { |
166
|
|
|
|
|
|
|
DataSource => 'dbi:Pg:dbname=database', |
167
|
|
|
|
|
|
|
UserName => 'database_user', |
168
|
|
|
|
|
|
|
Password => 'K00l' |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Instead, you may pass in an already-opened DBI handle to your database. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
tie %hash, 'Apache::Session::Browseable::SQLite', $id, { |
174
|
|
|
|
|
|
|
Handle => $dbh |
175
|
|
|
|
|
|
|
}; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This modules was written by Jeffrey William Baker |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
A fix for the commit policy was contributed by Michael Schout |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L, L |