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