| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#====================================================================== |
|
2
|
|
|
|
|
|
|
package DBD::SQLite::VirtualTable; |
|
3
|
|
|
|
|
|
|
#====================================================================== |
|
4
|
10
|
|
|
10
|
|
9354
|
use strict; |
|
|
10
|
|
|
|
|
31
|
|
|
|
10
|
|
|
|
|
298
|
|
|
5
|
10
|
|
|
10
|
|
57
|
use warnings; |
|
|
10
|
|
|
|
|
33
|
|
|
|
10
|
|
|
|
|
326
|
|
|
6
|
10
|
|
|
10
|
|
58
|
use Scalar::Util qw/weaken/; |
|
|
10
|
|
|
|
|
41
|
|
|
|
10
|
|
|
|
|
11247
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.74'; |
|
9
|
|
|
|
|
|
|
our @ISA; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
13
|
|
|
|
|
|
|
# methods for registering/destroying the module |
|
14
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
15
|
|
|
|
|
|
|
|
|
16
|
13
|
|
|
13
|
1
|
4323
|
sub CREATE_MODULE { my ($class, $mod_name) = @_; } |
|
17
|
10
|
|
|
10
|
1
|
1652
|
sub DESTROY_MODULE { my ($class, $mod_name) = @_; } |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
20
|
|
|
|
|
|
|
# methods for creating/destroying instances |
|
21
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
22
|
|
|
|
|
|
|
|
|
23
|
18
|
|
|
18
|
1
|
116
|
sub CREATE { my $class = shift; return $class->NEW(@_); } |
|
|
18
|
|
|
|
|
93
|
|
|
24
|
2
|
|
|
2
|
1
|
26
|
sub CONNECT { my $class = shift; return $class->NEW(@_); } |
|
|
2
|
|
|
|
|
15
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _PREPARE_SELF { |
|
27
|
20
|
|
|
20
|
|
168
|
my ($class, $dbh_ref, $module_name, $db_name, $vtab_name, @args) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
20
|
|
|
|
|
48
|
my @columns; |
|
30
|
|
|
|
|
|
|
my %options; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# args containing '=' are options; others are column declarations |
|
33
|
20
|
|
|
|
|
57
|
foreach my $arg (@args) { |
|
34
|
61
|
100
|
|
|
|
303
|
if ($arg =~ /^([^=\s]+)\s*=\s*(.*)/) { |
|
35
|
20
|
|
|
|
|
87
|
my ($key, $val) = ($1, $2); |
|
36
|
20
|
|
|
|
|
140
|
$val =~ s/^"(.*)"$/$1/; |
|
37
|
20
|
|
|
|
|
173
|
$options{$key} = $val; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
else { |
|
40
|
41
|
|
|
|
|
99
|
push @columns, $arg; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# build $self |
|
45
|
20
|
|
|
|
|
156
|
my $self = { |
|
46
|
|
|
|
|
|
|
dbh_ref => $dbh_ref, |
|
47
|
|
|
|
|
|
|
module_name => $module_name, |
|
48
|
|
|
|
|
|
|
db_name => $db_name, |
|
49
|
|
|
|
|
|
|
vtab_name => $vtab_name, |
|
50
|
|
|
|
|
|
|
columns => \@columns, |
|
51
|
|
|
|
|
|
|
options => \%options, |
|
52
|
|
|
|
|
|
|
}; |
|
53
|
20
|
|
|
|
|
104
|
weaken $self->{dbh_ref}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
20
|
|
|
|
|
75
|
return $self; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub NEW { |
|
59
|
5
|
|
|
5
|
1
|
28
|
my $class = shift; |
|
60
|
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
37
|
my $self = $class->_PREPARE_SELF(@_); |
|
62
|
5
|
|
|
|
|
50
|
bless $self, $class; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub VTAB_TO_DECLARE { |
|
67
|
20
|
|
|
20
|
1
|
44
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
|
|
69
|
20
|
|
|
|
|
51
|
local $" = ", "; |
|
70
|
20
|
|
|
|
|
107
|
my $sql = "CREATE TABLE $self->{vtab_name}(@{$self->{columns}})"; |
|
|
20
|
|
|
|
|
101
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
20
|
|
|
|
|
958
|
return $sql; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
|
|
1
|
1
|
32
|
sub DROP { my $self = shift; } |
|
76
|
16
|
|
|
16
|
1
|
17328
|
sub DISCONNECT { my $self = shift; } |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
80
|
|
|
|
|
|
|
# methods for initiating a search |
|
81
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub BEST_INDEX { |
|
84
|
1
|
|
|
1
|
1
|
8
|
my ($self, $constraints, $order_by) = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
4
|
my $ix = 0; |
|
87
|
1
|
|
|
|
|
6
|
foreach my $constraint (grep {$_->{usable}} @$constraints) { |
|
|
0
|
|
|
|
|
0
|
|
|
88
|
0
|
|
|
|
|
0
|
$constraint->{argvIndex} = $ix++; |
|
89
|
0
|
|
|
|
|
0
|
$constraint->{omit} = 0; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# stupid default values -- subclasses should put real values instead |
|
93
|
1
|
|
|
|
|
8
|
my $outputs = { |
|
94
|
|
|
|
|
|
|
idxNum => 1, |
|
95
|
|
|
|
|
|
|
idxStr => "", |
|
96
|
|
|
|
|
|
|
orderByConsumed => 0, |
|
97
|
|
|
|
|
|
|
estimatedCost => 1.0, |
|
98
|
|
|
|
|
|
|
estimatedRows => undef, |
|
99
|
|
|
|
|
|
|
}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
27
|
return $outputs; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub OPEN { |
|
106
|
122
|
|
|
122
|
|
5222
|
my $self = shift; |
|
107
|
122
|
|
|
|
|
259
|
my $class = ref $self; |
|
108
|
|
|
|
|
|
|
|
|
109
|
122
|
|
|
|
|
283
|
my $cursor_class = $class . "::Cursor"; |
|
110
|
122
|
|
|
|
|
580
|
return $cursor_class->NEW($self, @_); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
115
|
|
|
|
|
|
|
# methods for insert/delete/update |
|
116
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _SQLITE_UPDATE { |
|
119
|
5
|
|
|
5
|
|
15
|
my ($self, $old_rowid, $new_rowid, @values) = @_; |
|
120
|
|
|
|
|
|
|
|
|
121
|
5
|
50
|
|
|
|
11
|
if (! defined $old_rowid) { |
|
|
|
0
|
|
|
|
|
|
|
122
|
5
|
|
|
|
|
13
|
return $self->INSERT($new_rowid, @values); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
elsif (!@values) { |
|
125
|
0
|
|
|
|
|
0
|
return $self->DELETE($old_rowid); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
else { |
|
128
|
0
|
|
|
|
|
0
|
return $self->UPDATE($old_rowid, $new_rowid, @values); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub INSERT { |
|
133
|
0
|
|
|
0
|
1
|
0
|
my ($self, $new_rowid, @values) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
die "INSERT() should be redefined in subclass"; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub DELETE { |
|
139
|
0
|
|
|
0
|
|
0
|
my ($self, $old_rowid) = @_; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
0
|
die "DELETE() should be redefined in subclass"; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub UPDATE { |
|
145
|
0
|
|
|
0
|
1
|
0
|
my ($self, $old_rowid, $new_rowid, @values) = @_; |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
die "UPDATE() should be redefined in subclass"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
151
|
|
|
|
|
|
|
# remaining methods of the sqlite API |
|
152
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
153
|
|
|
|
|
|
|
|
|
154
|
3
|
|
|
3
|
1
|
27
|
sub BEGIN_TRANSACTION {return 0} |
|
155
|
21
|
|
|
21
|
1
|
64649
|
sub SYNC_TRANSACTION {return 0} |
|
156
|
21
|
|
|
21
|
0
|
344
|
sub COMMIT_TRANSACTION {return 0} |
|
157
|
0
|
|
|
0
|
1
|
0
|
sub ROLLBACK_TRANSACTION {return 0} |
|
158
|
0
|
|
|
0
|
1
|
0
|
sub SAVEPOINT {return 0} |
|
159
|
0
|
|
|
0
|
1
|
0
|
sub RELEASE {return 0} |
|
160
|
0
|
|
|
0
|
1
|
0
|
sub ROLLBACK_TO {return 0} |
|
161
|
1
|
|
|
1
|
1
|
19
|
sub FIND_FUNCTION {return 0} |
|
162
|
0
|
|
|
0
|
1
|
0
|
sub RENAME {return 0} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
166
|
|
|
|
|
|
|
# utility methods |
|
167
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub dbh { |
|
170
|
72
|
|
|
72
|
1
|
132
|
my $self = shift; |
|
171
|
72
|
|
|
|
|
118
|
return ${$self->{dbh_ref}}; |
|
|
72
|
|
|
|
|
413
|
|
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub sqlite_table_info { |
|
176
|
14
|
|
|
14
|
0
|
29
|
my $self = shift; |
|
177
|
|
|
|
|
|
|
|
|
178
|
14
|
|
|
|
|
55
|
my $sql = "PRAGMA table_info($self->{vtab_name})"; |
|
179
|
14
|
|
|
|
|
74
|
return $self->dbh->selectall_arrayref($sql, {Slice => {}}); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#====================================================================== |
|
183
|
|
|
|
|
|
|
package DBD::SQLite::VirtualTable::Cursor; |
|
184
|
|
|
|
|
|
|
#====================================================================== |
|
185
|
10
|
|
|
10
|
|
95
|
use strict; |
|
|
10
|
|
|
|
|
22
|
|
|
|
10
|
|
|
|
|
292
|
|
|
186
|
10
|
|
|
10
|
|
66
|
use warnings; |
|
|
10
|
|
|
|
|
29
|
|
|
|
10
|
|
|
|
|
2344
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub NEW { |
|
189
|
122
|
|
|
122
|
|
310
|
my ($class, $vtable, @args) = @_; |
|
190
|
122
|
|
|
|
|
396
|
my $self = {vtable => $vtable, |
|
191
|
|
|
|
|
|
|
args => \@args}; |
|
192
|
122
|
|
|
|
|
1097
|
bless $self, $class; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub FILTER { |
|
197
|
0
|
|
|
0
|
|
|
my ($self, $idxNum, $idxStr, @values) = @_; |
|
198
|
0
|
|
|
|
|
|
die "FILTER() should be redefined in cursor subclass"; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub EOF { |
|
202
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
203
|
0
|
|
|
|
|
|
die "EOF() should be redefined in cursor subclass"; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub NEXT { |
|
207
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
208
|
0
|
|
|
|
|
|
die "NEXT() should be redefined in cursor subclass"; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub COLUMN { |
|
212
|
0
|
|
|
0
|
|
|
my ($self, $idxCol) = @_; |
|
213
|
0
|
|
|
|
|
|
die "COLUMN() should be redefined in cursor subclass"; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub ROWID { |
|
217
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
218
|
0
|
|
|
|
|
|
die "ROWID() should be redefined in cursor subclass"; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
__END__ |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 NAME |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
DBD::SQLite::VirtualTable -- SQLite virtual tables implemented in Perl |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# register the virtual table module within sqlite |
|
233
|
|
|
|
|
|
|
$dbh->sqlite_create_module(mod_name => "DBD::SQLite::VirtualTable::Subclass"); |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# create a virtual table |
|
236
|
|
|
|
|
|
|
$dbh->do("CREATE VIRTUAL TABLE vtbl USING mod_name(arg1, arg2, ...)") |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# use it as any regular table |
|
239
|
|
|
|
|
|
|
my $sth = $dbh->prepare("SELECT * FROM vtbl WHERE ..."); |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
B<Note> : VirtualTable subclasses or instances are not called |
|
242
|
|
|
|
|
|
|
directly from Perl code; everything happens indirectly through SQL |
|
243
|
|
|
|
|
|
|
statements within SQLite. |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This module is an abstract class for implementing SQLite virtual tables, |
|
249
|
|
|
|
|
|
|
written in Perl. Such tables look like regular tables, and are accessed |
|
250
|
|
|
|
|
|
|
through regular SQL instructions and regular L<DBI> API; but the implementation |
|
251
|
|
|
|
|
|
|
is done through hidden calls to a Perl class. |
|
252
|
|
|
|
|
|
|
This is the same idea as Perl's L<tied variables|perltie>, but |
|
253
|
|
|
|
|
|
|
at the SQLite level. |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
The current abstract class cannot be used directly, so the |
|
256
|
|
|
|
|
|
|
synopsis above is just to give a general idea. Concrete, usable |
|
257
|
|
|
|
|
|
|
classes bundled with the present distribution are : |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item * |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
L<DBD::SQLite::VirtualTable::FileContent> : implements a virtual |
|
264
|
|
|
|
|
|
|
column that exposes file contents. This is especially useful |
|
265
|
|
|
|
|
|
|
in conjunction with a fulltext index; see L<DBD::SQLite::Fulltext_search>. |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L<DBD::SQLite::VirtualTable::PerlData> : binds to a Perl array |
|
270
|
|
|
|
|
|
|
within the Perl program. This can be used for simple import/export |
|
271
|
|
|
|
|
|
|
operations, for debugging purposes, for joining data from different |
|
272
|
|
|
|
|
|
|
sources, etc. |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=back |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Other Perl virtual tables may also be published separately on CPAN. |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
The following chapters document the structure of the abstract class |
|
279
|
|
|
|
|
|
|
and explain how to write new subclasses; this is meant for |
|
280
|
|
|
|
|
|
|
B<module authors>, not for end users. If you just need to use a |
|
281
|
|
|
|
|
|
|
virtual table module, refer to that module's documentation. |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 ARCHITECTURE |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head2 Classes |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
A virtual table module for SQLite is implemented through a pair |
|
289
|
|
|
|
|
|
|
of classes : |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=over |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
the B<table> class implements methods for creating or connecting |
|
296
|
|
|
|
|
|
|
a virtual table, for destroying it, for opening new searches, etc. |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=item * |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
the B<cursor> class implements methods for performing a specific |
|
301
|
|
|
|
|
|
|
SQL statement |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=back |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head2 Methods |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Most methods in both classes are not called directly from Perl |
|
309
|
|
|
|
|
|
|
code : instead, they are callbacks, called from the sqlite kernel. |
|
310
|
|
|
|
|
|
|
Following common Perl conventions, such methods have names in |
|
311
|
|
|
|
|
|
|
uppercase. |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 TABLE METHODS |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 Class methods for registering the module |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head3 CREATE_MODULE |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
$class->CREATE_MODULE($sqlite_module_name); |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Called when the client code invokes |
|
323
|
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
$dbh->sqlite_create_module($sqlite_module_name => $class); |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
The default implementation is empty. |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head3 DESTROY_MODULE |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
$class->DESTROY_MODULE(); |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
Called automatically when the database handle is disconnected. |
|
334
|
|
|
|
|
|
|
The default implementation is empty. |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=head2 Class methods for creating a vtable instance |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head3 CREATE |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
$class->CREATE($dbh_ref, $module_name, $db_name, $vtab_name, @args); |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Called when sqlite receives a statement |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
CREATE VIRTUAL TABLE $db_name.$vtab_name USING $module_name(@args) |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
The default implementation just calls L</NEW>. |
|
349
|
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=head3 CONNECT |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
$class->CONNECT($dbh_ref, $module_name, $db_name, $vtab_name, @args); |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
Called when attempting to access a virtual table that had been created |
|
355
|
|
|
|
|
|
|
during previous database connection. The creation arguments were stored |
|
356
|
|
|
|
|
|
|
within the sqlite database and are passed again to the CONNECT method. |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
The default implementation just calls L</NEW>. |
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=head3 _PREPARE_SELF |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
$class->_PREPARE_SELF($dbh_ref, $module_name, $db_name, $vtab_name, @args); |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
Prepares the datastructure for a virtual table instance. C<@args> is |
|
366
|
|
|
|
|
|
|
just the collection of strings (comma-separated) that were given |
|
367
|
|
|
|
|
|
|
within the C<CREATE VIRTUAL TABLE> statement; each subclass should |
|
368
|
|
|
|
|
|
|
decide what to do with this information, |
|
369
|
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
The method parses C<@args> to differentiate between I<options> |
|
371
|
|
|
|
|
|
|
(strings of shape C<$key>=C<$value> or C<$key>=C<"$value">, stored in |
|
372
|
|
|
|
|
|
|
C<< $self->{options} >>), and I<columns> (other C<@args>, stored in |
|
373
|
|
|
|
|
|
|
C<< $self->{columns} >>). It creates a hashref with the following fields : |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=over |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=item C<dbh_ref> |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
a weak reference to the C<$dbh> database handle (see |
|
380
|
|
|
|
|
|
|
L<Scalar::Util> for an explanation of weak references). |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
=item C<module_name> |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
name of the module as declared to sqlite (not to be confounded |
|
385
|
|
|
|
|
|
|
with the Perl class name). |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=item C<db_name> |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
name of the database (usuallly C<'main'> or C<'temp'>), but it |
|
390
|
|
|
|
|
|
|
may also be an attached database |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
=item C<vtab_name> |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
name of the virtual table |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=item C<columns> |
|
397
|
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
arrayref of column declarations |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=item C<options> |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
hashref of option declarations |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=back |
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
This method should not be redefined, since it performs |
|
407
|
|
|
|
|
|
|
general work which is supposed to be useful for all subclasses. |
|
408
|
|
|
|
|
|
|
Instead, subclasses may override the L</NEW> method. |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
=head3 NEW |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
$class->NEW($dbh_ref, $module_name, $db_name, $vtab_name, @args); |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
Instantiates a virtual table. |
|
416
|
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=head2 Instance methods called from the sqlite kernel |
|
419
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
=head3 DROP |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
Called whenever a virtual table is destroyed from the |
|
424
|
|
|
|
|
|
|
database through the C<DROP TABLE> SQL instruction. |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
Just after the C<DROP()> call, the Perl instance |
|
427
|
|
|
|
|
|
|
will be destroyed (and will therefore automatically |
|
428
|
|
|
|
|
|
|
call the C<DESTROY()> method if such a method is present). |
|
429
|
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
The default implementation for DROP is empty. |
|
431
|
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
B<Note> : this corresponds to the C<xDestroy> method |
|
433
|
|
|
|
|
|
|
in the SQLite documentation; here it was not named |
|
434
|
|
|
|
|
|
|
C<DESTROY>, to avoid any confusion with the standard |
|
435
|
|
|
|
|
|
|
Perl method C<DESTROY> for object destruction. |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
=head3 DISCONNECT |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
Called for every virtual table just before the database handle |
|
441
|
|
|
|
|
|
|
is disconnected. |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
Just after the C<DISCONNECT()> call, the Perl instance |
|
444
|
|
|
|
|
|
|
will be destroyed (and will therefore automatically |
|
445
|
|
|
|
|
|
|
call the C<DESTROY()> method if such a method is present). |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
The default implementation for DISCONNECT is empty. |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=head3 VTAB_TO_DECLARE |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
This method is called automatically just after L</CREATE> or L</CONNECT>, |
|
452
|
|
|
|
|
|
|
to register the columns of the virtual table within the sqlite kernel. |
|
453
|
|
|
|
|
|
|
The method should return a string containing a SQL C<CREATE TABLE> statement; |
|
454
|
|
|
|
|
|
|
but only the column declaration parts will be considered. |
|
455
|
|
|
|
|
|
|
Columns may be declared with the special keyword "HIDDEN", which means that |
|
456
|
|
|
|
|
|
|
they are used internally for the the virtual table implementation, and are |
|
457
|
|
|
|
|
|
|
not visible to users -- see L<http://sqlite.org/c3ref/declare_vtab.html> |
|
458
|
|
|
|
|
|
|
and L<http://www.sqlite.org/vtab.html#hiddencol> for detailed explanations. |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
The default implementation returns: |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
CREATE TABLE $self->{vtab_name}(@{$self->{columns}}) |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=head3 BEST_INDEX |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
my $index_info = $vtab->BEST_INDEX($constraints, $order_by) |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
This is the most complex method to redefined in subclasses. |
|
469
|
|
|
|
|
|
|
This method will be called at the beginning of a new query on the |
|
470
|
|
|
|
|
|
|
virtual table; the job of the method is to assemble some information |
|
471
|
|
|
|
|
|
|
that will be used |
|
472
|
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=over |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
=item a) |
|
476
|
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
by the sqlite kernel to decide about the best search strategy |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
=item b) |
|
480
|
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
by the cursor L</FILTER> method to produce the desired subset |
|
482
|
|
|
|
|
|
|
of rows from the virtual table. |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=back |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
By calling this method, the SQLite core is saying to the virtual table |
|
487
|
|
|
|
|
|
|
that it needs to access some subset of the rows in the virtual table |
|
488
|
|
|
|
|
|
|
and it wants to know the most efficient way to do that access. The |
|
489
|
|
|
|
|
|
|
C<BEST_INDEX> method replies with information that the SQLite core can |
|
490
|
|
|
|
|
|
|
then use to conduct an efficient search of the virtual table. |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
The method takes as input a list of C<$constraints> and a list |
|
493
|
|
|
|
|
|
|
of C<$order_by> instructions. It returns a hashref of indexing |
|
494
|
|
|
|
|
|
|
properties, described below; furthermore, the method also adds |
|
495
|
|
|
|
|
|
|
supplementary information within the input C<$constraints>. |
|
496
|
|
|
|
|
|
|
Detailed explanations are given in |
|
497
|
|
|
|
|
|
|
L<http://sqlite.org/vtab.html#xbestindex>. |
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=head4 Input constraints |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
Elements of the C<$constraints> arrayref correspond to |
|
502
|
|
|
|
|
|
|
specific clauses of the C<WHERE ...> part of the SQL query. |
|
503
|
|
|
|
|
|
|
Each constraint is a hashref with keys : |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=over |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=item C<col> |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
the integer index of the column on the left-hand side of the constraint |
|
510
|
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
=item C<op> |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
the comparison operator, expressed as string containing |
|
514
|
|
|
|
|
|
|
C<< '=' >>, C<< '>' >>, C<< '>=' >>, C<< '<' >>, C<< '<=' >> or C<< 'MATCH' >>. |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=item C<usable> |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
a boolean indicating if that constraint is usable; some constraints |
|
519
|
|
|
|
|
|
|
might not be usable because of the way tables are ordered in a join. |
|
520
|
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=back |
|
522
|
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
The C<$constraints> arrayref is used both for input and for output. |
|
524
|
|
|
|
|
|
|
While iterating over the array, the method should |
|
525
|
|
|
|
|
|
|
add the following keys into usable constraints : |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=over |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=item C<argvIndex> |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
An index into the C<@values> array that will be passed to |
|
532
|
|
|
|
|
|
|
the cursor's L</FILTER> method. In other words, if the current |
|
533
|
|
|
|
|
|
|
constraint corresponds to the SQL fragment C<WHERE ... AND foo < 123 ...>, |
|
534
|
|
|
|
|
|
|
and the corresponding C<argvIndex> takes value 5, this means that |
|
535
|
|
|
|
|
|
|
the C<FILTER> method will receive C<123> in C<$values[5]>. |
|
536
|
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=item C<omit> |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
A boolean telling to the sqlite core that it can safely omit |
|
540
|
|
|
|
|
|
|
to double check that constraint before returning the resultset |
|
541
|
|
|
|
|
|
|
to the calling program; this means that the FILTER method has fulfilled |
|
542
|
|
|
|
|
|
|
the filtering job on that constraint and there is no need to do any |
|
543
|
|
|
|
|
|
|
further checking. |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
=back |
|
546
|
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
The C<BEST_INDEX> method will not necessarily receive all constraints |
|
548
|
|
|
|
|
|
|
from the SQL C<WHERE> clause : for example a constraint like |
|
549
|
|
|
|
|
|
|
C<< col1 < col2 + col3 >> cannot be handled at this level. |
|
550
|
|
|
|
|
|
|
Furthemore, the C<BEST_INDEX> might decide to ignore some of the |
|
551
|
|
|
|
|
|
|
received constraints. This is why a second pass over the results |
|
552
|
|
|
|
|
|
|
will be performed by the sqlite core. |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
=head4 "order_by" input information |
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
The C<$order_by> arrayref corresponds to the C<ORDER BY> clauses |
|
558
|
|
|
|
|
|
|
in the SQL query. Each entry is a hashref with keys : |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=over |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=item C<col> |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
the integer index of the column being ordered |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=item C<desc> |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
a boolean telling of the ordering is DESCending or ascending |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
=back |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
This information could be used by some subclasses for |
|
573
|
|
|
|
|
|
|
optimizing the query strategfy; but usually the sqlite core will |
|
574
|
|
|
|
|
|
|
perform another sorting pass once all results are gathered. |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
=head4 Hashref information returned by BEST_INDEX |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
The method should return a hashref with the following keys : |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
=over |
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=item C<idxNum> |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
An arbitrary integer associated with that index; this information will |
|
585
|
|
|
|
|
|
|
be passed back to L</FILTER>. |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=item C<idxStr> |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
An arbitrary str associated with that index; this information will |
|
590
|
|
|
|
|
|
|
be passed back to L</FILTER>. |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
=item C<orderByConsumed> |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
A boolean telling the sqlite core if the C<$order_by> information |
|
595
|
|
|
|
|
|
|
has been taken into account or not. |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
=item C<estimatedCost> |
|
598
|
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
A float that should be set to the estimated number of disk access |
|
600
|
|
|
|
|
|
|
operations required to execute this query against the virtual |
|
601
|
|
|
|
|
|
|
table. The SQLite core will often call BEST_INDEX multiple times with |
|
602
|
|
|
|
|
|
|
different constraints, obtain multiple cost estimates, then choose the |
|
603
|
|
|
|
|
|
|
query plan that gives the lowest estimate. |
|
604
|
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
=item C<estimatedRows> |
|
606
|
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
An integer giving the estimated number of rows returned by that query. |
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=back |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
=head3 OPEN |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
Called to instantiate a new cursor. |
|
616
|
|
|
|
|
|
|
The default implementation appends C<"::Cursor"> to the current |
|
617
|
|
|
|
|
|
|
classname and calls C<NEW()> within that cursor class. |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=head3 _SQLITE_UPDATE |
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
This is the dispatch method implementing the C<xUpdate()> callback |
|
622
|
|
|
|
|
|
|
for virtual tables. The default implementation applies the algorithm |
|
623
|
|
|
|
|
|
|
described in L<http://sqlite.org/vtab.html#xupdate> to decide |
|
624
|
|
|
|
|
|
|
to call L</INSERT>, L</DELETE> or L</UPDATE>; so there is no reason |
|
625
|
|
|
|
|
|
|
to override this method in subclasses. |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
=head3 INSERT |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
my $rowid = $vtab->INSERT($new_rowid, @values); |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
This method should be overridden in subclasses to implement |
|
632
|
|
|
|
|
|
|
insertion of a new row into the virtual table. |
|
633
|
|
|
|
|
|
|
The size of the C<@values> array corresponds to the |
|
634
|
|
|
|
|
|
|
number of columns declared through L</VTAB_TO_DECLARE>. |
|
635
|
|
|
|
|
|
|
The C<$new_rowid> may be explicitly given, or it may be |
|
636
|
|
|
|
|
|
|
C<undef>, in which case the method must compute a new id |
|
637
|
|
|
|
|
|
|
and return it as the result of the method call. |
|
638
|
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
=head3 DELETE |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
$vtab->INSERT($old_rowid); |
|
642
|
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
This method should be overridden in subclasses to implement |
|
644
|
|
|
|
|
|
|
deletion of a row from the virtual table. |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
=head3 UPDATE |
|
647
|
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
$vtab->UPDATE($old_rowid, $new_rowid, @values); |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
This method should be overridden in subclasses to implement |
|
651
|
|
|
|
|
|
|
a row update within the virtual table. Usually C<$old_rowid> is equal |
|
652
|
|
|
|
|
|
|
to C<$new_rowid>, which is a regular update; however, the rowid |
|
653
|
|
|
|
|
|
|
could be changed from a SQL statement such as |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
UPDATE table SET rowid=rowid+1 WHERE ...; |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=head3 FIND_FUNCTION |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
$vtab->FIND_FUNCTION($num_args, $func_name); |
|
660
|
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
When a function uses a column from a virtual table as its first |
|
662
|
|
|
|
|
|
|
argument, this method is called to see if the virtual table would like |
|
663
|
|
|
|
|
|
|
to overload the function. Parameters are the number of arguments to |
|
664
|
|
|
|
|
|
|
the function, and the name of the function. If no overloading is |
|
665
|
|
|
|
|
|
|
desired, this method should return false. To overload the function, |
|
666
|
|
|
|
|
|
|
this method should return a coderef to the function implementation. |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
Each virtual table keeps a cache of results from L<FIND_FUNCTION> calls, |
|
669
|
|
|
|
|
|
|
so the method will be called only once for each pair |
|
670
|
|
|
|
|
|
|
C<< ($num_args, $func_name) >>. |
|
671
|
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
=head3 BEGIN_TRANSACTION |
|
674
|
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
Called to begin a transaction on the virtual table. |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=head3 SYNC_TRANSACTION |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Called to signal the start of a two-phase commit on the virtual table. |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=head3 SYNC_TRANSACTION |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
Called to commit a virtual table transaction. |
|
684
|
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
=head3 ROLLBACK_TRANSACTION |
|
686
|
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
Called to rollback a virtual table transaction. |
|
688
|
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
=head3 RENAME |
|
690
|
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
$vtab->RENAME($new_name) |
|
692
|
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
Called to rename a virtual table. |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
=head3 SAVEPOINT |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
$vtab->SAVEPOINT($savepoint) |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
Called to signal the virtual table to save its current state |
|
700
|
|
|
|
|
|
|
at savepoint C<$savepoint> (an integer). |
|
701
|
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
=head3 ROLLBACK_TO |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
$vtab->ROLLBACK_TO($savepoint) |
|
705
|
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
Called to signal the virtual table to return to the state |
|
707
|
|
|
|
|
|
|
C<$savepoint>. This will invalidate all savepoints with values |
|
708
|
|
|
|
|
|
|
greater than C<$savepoint>. |
|
709
|
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
=head3 RELEASE |
|
711
|
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
$vtab->RELEASE($savepoint) |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
Called to invalidate all savepoints with values |
|
715
|
|
|
|
|
|
|
greater or equal to C<$savepoint>. |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
=head2 Utility instance methods |
|
719
|
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
Methods in this section are in lower case, because they |
|
721
|
|
|
|
|
|
|
are not called directly from the sqlite kernel; these |
|
722
|
|
|
|
|
|
|
are utility methods to be called from other methods |
|
723
|
|
|
|
|
|
|
described above. |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
=head3 dbh |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
This method returns the database handle (C<$dbh>) associated with |
|
728
|
|
|
|
|
|
|
the current virtual table. |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
=head1 CURSOR METHODS |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=head2 Class methods |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
=head3 NEW |
|
736
|
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
my $cursor = $cursor_class->NEW($vtable, @args) |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
Instantiates a new cursor. |
|
740
|
|
|
|
|
|
|
The default implementation just returns a blessed hashref |
|
741
|
|
|
|
|
|
|
with keys C<vtable> and C<args>. |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
=head2 Instance methods |
|
744
|
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
=head3 FILTER |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
$cursor->FILTER($idxNum, $idxStr, @values); |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
This method begins a search of a virtual table. |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
The C<$idxNum> and C<$idxStr> arguments correspond to values returned |
|
752
|
|
|
|
|
|
|
by L</BEST_INDEX> for the chosen index. The specific meanings of |
|
753
|
|
|
|
|
|
|
those values are unimportant to SQLite, as long as C<BEST_INDEX> and |
|
754
|
|
|
|
|
|
|
C<FILTER> agree on what that meaning is. |
|
755
|
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
The C<BEST_INDEX> method may have requested the values of certain |
|
757
|
|
|
|
|
|
|
expressions using the C<argvIndex> values of the |
|
758
|
|
|
|
|
|
|
C<$constraints> list. Those values are passed to C<FILTER> through |
|
759
|
|
|
|
|
|
|
the C<@values> array. |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
If the virtual table contains one or more rows that match the search |
|
762
|
|
|
|
|
|
|
criteria, then the cursor must be left point at the first |
|
763
|
|
|
|
|
|
|
row. Subsequent calls to L</EOF> must return false. If there are |
|
764
|
|
|
|
|
|
|
no rows match, then the cursor must be left in a state that will cause |
|
765
|
|
|
|
|
|
|
L</EOF> to return true. The SQLite engine will use the |
|
766
|
|
|
|
|
|
|
L</COLUMN> and L</ROWID> methods to access that row content. The L</NEXT> |
|
767
|
|
|
|
|
|
|
method will be used to advance to the next row. |
|
768
|
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
=head3 EOF |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
This method must return false if the cursor currently points to a |
|
773
|
|
|
|
|
|
|
valid row of data, or true otherwise. This method is called by the SQL |
|
774
|
|
|
|
|
|
|
engine immediately after each L</FILTER> and L</NEXT> invocation. |
|
775
|
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=head3 NEXT |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
This method advances the cursor to the next row of a |
|
779
|
|
|
|
|
|
|
result set initiated by L</FILTER>. If the cursor is already pointing at |
|
780
|
|
|
|
|
|
|
the last row when this method is called, then the cursor no longer |
|
781
|
|
|
|
|
|
|
points to valid data and a subsequent call to the L</EOF> method must |
|
782
|
|
|
|
|
|
|
return true. If the cursor is successfully advanced to |
|
783
|
|
|
|
|
|
|
another row of content, then subsequent calls to L</EOF> must return |
|
784
|
|
|
|
|
|
|
false. |
|
785
|
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
=head3 COLUMN |
|
787
|
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
my $value = $cursor->COLUMN($idxCol); |
|
789
|
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
The SQLite core invokes this method in order to find the value for the |
|
791
|
|
|
|
|
|
|
N-th column of the current row. N is zero-based so the first column is |
|
792
|
|
|
|
|
|
|
numbered 0. |
|
793
|
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=head3 ROWID |
|
795
|
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
my $value = $cursor->ROWID; |
|
797
|
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
Returns the I<rowid> of row that the cursor is currently pointing at. |
|
799
|
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
802
|
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
L<SQLite::VirtualTable> is another module for virtual tables written |
|
804
|
|
|
|
|
|
|
in Perl, but designed for the reverse use case : instead of starting a |
|
805
|
|
|
|
|
|
|
Perl program, and embedding the SQLite library into it, the intended |
|
806
|
|
|
|
|
|
|
use is to start an sqlite program, and embed the Perl interpreter |
|
807
|
|
|
|
|
|
|
into it. |
|
808
|
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
=head1 AUTHOR |
|
810
|
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
Laurent Dami E<lt>dami@cpan.orgE<gt> |
|
812
|
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
815
|
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
Copyright Laurent Dami, 2014. |
|
817
|
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
Parts of the code are borrowed from L<SQLite::VirtualTable>, |
|
819
|
|
|
|
|
|
|
copyright (C) 2006, 2009 by Qindel Formacion y Servicios, S. L. |
|
820
|
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
822
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
823
|
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
=cut |