| 1 | #====================================================================== | ||||||||||||||
| 2 | package DBD::SQLite::VirtualTable; | ||||||||||||||
| 3 | #====================================================================== | ||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 10 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 10 | our $VERSION = '1.78'; | |||||||||||||
| 9 | 10 | our @ISA; | |||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | #---------------------------------------------------------------------- | ||||||||||||||
| 13 | # methods for registering/destroying the module | ||||||||||||||
| 14 | #---------------------------------------------------------------------- | ||||||||||||||
| 15 | |||||||||||||||
| 16 | 13 | ▶ | sub CREATE_MODULE { my ($class, $mod_name) = @_; } | ||||||||||||
|
Subroutine
CREATE_MODULE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 17 | 10 | ▶ | sub DESTROY_MODULE { my ($class, $mod_name) = @_; } | ||||||||||||
|
Subroutine
DESTROY_MODULE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | #---------------------------------------------------------------------- | ||||||||||||||
| 20 | # methods for creating/destroying instances | ||||||||||||||
| 21 | #---------------------------------------------------------------------- | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 18 | ▶ | sub CREATE { my $class = shift; return $class->NEW(@_); } | ||||||||||||
|
Subroutine
CREATE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 24 | 2 | ▶ | sub CONNECT { my $class = shift; return $class->NEW(@_); } | ||||||||||||
|
Subroutine
CONNECT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 20 | ▶ | sub _PREPARE_SELF { | ||||||||||||
|
Subroutine
_PREPARE_SELF: called CC=3 SCAR=11.0
| |||||||||||||||
| 27 | 20 | my ($class, $dbh_ref, $module_name, $db_name, $vtab_name, @args) = @_; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 20 | my @columns; | |||||||||||||
| 30 | my %options; | ||||||||||||||
| 31 | |||||||||||||||
| 32 | # args containing '=' are options; others are column declarations | ||||||||||||||
| 33 | 20 | foreach my $arg (@args) { | |||||||||||||
| 34 | 61 | ▶ | if ($arg =~ /^([^=\s]+)\s*=\s*(.*)/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 20 | my ($key, $val) = ($1, $2); | |||||||||||||
| 36 | 20 | $val =~ s/^"(.*)"$/$1/; | |||||||||||||
| 37 | 20 | $options{$key} = $val; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | 41 | push @columns, $arg; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | # build $self | ||||||||||||||
| 45 | 20 | 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 | weaken $self->{dbh_ref}; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 20 | return $self; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 5 | ▶ | sub NEW { | ||||||||||||
|
Subroutine
NEW: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 59 | 5 | my $class = shift; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 5 | my $self = $class->_PREPARE_SELF(@_); | |||||||||||||
| 62 | 5 | bless $self, $class; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | |||||||||||||||
| 66 | 20 | ▶ | sub VTAB_TO_DECLARE { | ||||||||||||
|
Subroutine
VTAB_TO_DECLARE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 67 | 20 | my $self = shift; | |||||||||||||
| 68 | |||||||||||||||
| 69 | 20 | local $" = ", "; | |||||||||||||
| 70 | 20 | my $sql = "CREATE TABLE $self->{vtab_name}(@{$self->{columns}})"; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 20 | return $sql; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | ▶ | sub DROP { my $self = shift; } | ||||||||||||
|
Subroutine
DROP: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 76 | 16 | ▶ | sub DISCONNECT { my $self = shift; } | ||||||||||||
|
Subroutine
DISCONNECT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | |||||||||||||||
| 79 | #---------------------------------------------------------------------- | ||||||||||||||
| 80 | # methods for initiating a search | ||||||||||||||
| 81 | #---------------------------------------------------------------------- | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 1 | ▶ | sub BEST_INDEX { | ||||||||||||
|
Subroutine
BEST_INDEX: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||
| 84 | 1 | my ($self, $constraints, $order_by) = @_; | |||||||||||||
| 85 | |||||||||||||||
| 86 | 1 | my $ix = 0; | |||||||||||||
| 87 | 0 | foreach my $constraint (grep {$_->{usable}} @$constraints) { | |||||||||||||
| 88 | 0 | $constraint->{argvIndex} = $ix++; | |||||||||||||
| 89 | 0 | $constraint->{omit} = 0; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | # stupid default values -- subclasses should put real values instead | ||||||||||||||
| 93 | 1 | my $outputs = { | |||||||||||||
| 94 | idxNum => 1, | ||||||||||||||
| 95 | idxStr => "", | ||||||||||||||
| 96 | orderByConsumed => 0, | ||||||||||||||
| 97 | estimatedCost => 1.0, | ||||||||||||||
| 98 | estimatedRows => undef, | ||||||||||||||
| 99 | }; | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 1 | return $outputs; | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | |||||||||||||||
| 104 | |||||||||||||||
| 105 | 122 | ▶ | sub OPEN { | ||||||||||||
|
Subroutine
OPEN: called CC=1 SCAR=0.0
| |||||||||||||||
| 106 | 122 | my $self = shift; | |||||||||||||
| 107 | 122 | my $class = ref $self; | |||||||||||||
| 108 | |||||||||||||||
| 109 | 122 | my $cursor_class = $class . "::Cursor"; | |||||||||||||
| 110 | 122 | return $cursor_class->NEW($self, @_); | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | |||||||||||||||
| 114 | #---------------------------------------------------------------------- | ||||||||||||||
| 115 | # methods for insert/delete/update | ||||||||||||||
| 116 | #---------------------------------------------------------------------- | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 5 | ▶ | sub _SQLITE_UPDATE { | ||||||||||||
|
Subroutine
_SQLITE_UPDATE: called CC=3 SCAR=15.1
| |||||||||||||||
| 119 | 5 | my ($self, $old_rowid, $new_rowid, @values) = @_; | |||||||||||||
| 120 | |||||||||||||||
| 121 | 5 | ▶ | if (! defined $old_rowid) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 122 | 5 | return $self->INSERT($new_rowid, @values); | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | elsif (!@values) { | ||||||||||||||
| 125 | 0 | return $self->DELETE($old_rowid); | |||||||||||||
| 126 | } | ||||||||||||||
| 127 | else { | ||||||||||||||
| 128 | 0 | return $self->UPDATE($old_rowid, $new_rowid, @values); | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 0 | ▶ | sub INSERT { | ||||||||||||
|
Subroutine
INSERT: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 133 | 0 | my ($self, $new_rowid, @values) = @_; | |||||||||||||
| 134 | |||||||||||||||
| 135 | 0 | die "INSERT() should be redefined in subclass"; | |||||||||||||
| 136 | } | ||||||||||||||
| 137 | |||||||||||||||
| 138 | 0 | ▶ | sub DELETE { | ||||||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||||||
| 139 | 0 | my ($self, $old_rowid) = @_; | |||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | die "DELETE() should be redefined in subclass"; | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | sub UPDATE { | ||||||||||||
|
Subroutine
UPDATE: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 145 | 0 | my ($self, $old_rowid, $new_rowid, @values) = @_; | |||||||||||||
| 146 | |||||||||||||||
| 147 | 0 | die "UPDATE() should be redefined in subclass"; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | |||||||||||||||
| 150 | #---------------------------------------------------------------------- | ||||||||||||||
| 151 | # remaining methods of the sqlite API | ||||||||||||||
| 152 | #---------------------------------------------------------------------- | ||||||||||||||
| 153 | |||||||||||||||
| 154 | 3 | ▶ | sub BEGIN_TRANSACTION {return 0} | ||||||||||||
|
Subroutine
BEGIN_TRANSACTION: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 155 | 21 | ▶ | sub SYNC_TRANSACTION {return 0} | ||||||||||||
|
Subroutine
SYNC_TRANSACTION: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 156 | 21 | ▶ | sub COMMIT_TRANSACTION {return 0} | ||||||||||||
|
Subroutine
COMMIT_TRANSACTION: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 157 | 0 | ▶ | sub ROLLBACK_TRANSACTION {return 0} | ||||||||||||
|
Subroutine
ROLLBACK_TRANSACTION: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 158 | 0 | ▶ | sub SAVEPOINT {return 0} | ||||||||||||
|
Subroutine
SAVEPOINT: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 159 | 0 | ▶ | sub RELEASE {return 0} | ||||||||||||
|
Subroutine
RELEASE: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 160 | 0 | ▶ | sub ROLLBACK_TO {return 0} | ||||||||||||
|
Subroutine
ROLLBACK_TO: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 161 | 1 | ▶ | sub FIND_FUNCTION {return 0} | ||||||||||||
|
Subroutine
FIND_FUNCTION: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 162 | 0 | ▶ | sub RENAME {return 0} | ||||||||||||
|
Subroutine
RENAME: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 163 | |||||||||||||||
| 164 | |||||||||||||||
| 165 | #---------------------------------------------------------------------- | ||||||||||||||
| 166 | # utility methods | ||||||||||||||
| 167 | #---------------------------------------------------------------------- | ||||||||||||||
| 168 | |||||||||||||||
| 169 | 72 | ▶ | sub dbh { | ||||||||||||
|
Subroutine
dbh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 170 | 72 | my $self = shift; | |||||||||||||
| 171 | 72 | return ${$self->{dbh_ref}}; | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | |||||||||||||||
| 174 | |||||||||||||||
| 175 | 14 | ▶ | sub sqlite_table_info { | ||||||||||||
|
Subroutine
sqlite_table_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 176 | 14 | my $self = shift; | |||||||||||||
| 177 | |||||||||||||||
| 178 | 14 | my $sql = "PRAGMA table_info($self->{vtab_name})"; | |||||||||||||
| 179 | 14 | return $self->dbh->selectall_arrayref($sql, {Slice => {}}); | |||||||||||||
| 180 | } | ||||||||||||||
| 181 | |||||||||||||||
| 182 | #====================================================================== | ||||||||||||||
| 183 | package DBD::SQLite::VirtualTable::Cursor; | ||||||||||||||
| 184 | #====================================================================== | ||||||||||||||
| 185 | 10 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 186 | 10 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 187 | |||||||||||||||
| 188 | 122 | ▶ | sub NEW { | ||||||||||||
|
Subroutine
NEW: called CC=1 SCAR=0.0
| |||||||||||||||
| 189 | 122 | my ($class, $vtable, @args) = @_; | |||||||||||||
| 190 | 122 | my $self = {vtable => $vtable, | |||||||||||||
| 191 | args => \@args}; | ||||||||||||||
| 192 | 122 | bless $self, $class; | |||||||||||||
| 193 | } | ||||||||||||||
| 194 | |||||||||||||||
| 195 | |||||||||||||||
| 196 | 0 | ▶ | sub FILTER { | ||||||||||||
|
Subroutine
FILTER: not called CC=1 SCAR=6.9
| |||||||||||||||
| 197 | 0 | my ($self, $idxNum, $idxStr, @values) = @_; | |||||||||||||
| 198 | 0 | die "FILTER() should be redefined in cursor subclass"; | |||||||||||||
| 199 | } | ||||||||||||||
| 200 | |||||||||||||||
| 201 | 0 | ▶ | sub EOF { | ||||||||||||
|
Subroutine
EOF: not called CC=1 SCAR=6.9
| |||||||||||||||
| 202 | 0 | my ($self) = @_; | |||||||||||||
| 203 | 0 | die "EOF() should be redefined in cursor subclass"; | |||||||||||||
| 204 | } | ||||||||||||||
| 205 | |||||||||||||||
| 206 | 0 | ▶ | sub NEXT { | ||||||||||||
|
Subroutine
NEXT: not called CC=1 SCAR=6.9
| |||||||||||||||
| 207 | 0 | my ($self) = @_; | |||||||||||||
| 208 | 0 | die "NEXT() should be redefined in cursor subclass"; | |||||||||||||
| 209 | } | ||||||||||||||
| 210 | |||||||||||||||
| 211 | 0 | ▶ | sub COLUMN { | ||||||||||||
|
Subroutine
COLUMN: not called CC=1 SCAR=6.9
| |||||||||||||||
| 212 | 0 | my ($self, $idxCol) = @_; | |||||||||||||
| 213 | 0 | die "COLUMN() should be redefined in cursor subclass"; | |||||||||||||
| 214 | } | ||||||||||||||
| 215 | |||||||||||||||
| 216 | 0 | ▶ | sub ROWID { | ||||||||||||
|
Subroutine
ROWID: not called CC=1 SCAR=6.9
| |||||||||||||||
| 217 | 0 | my ($self) = @_; | |||||||||||||
| 218 | 0 | die "ROWID() should be redefined in cursor subclass"; | |||||||||||||
| 219 | } | ||||||||||||||
| 220 | |||||||||||||||
| 221 | |||||||||||||||
| 222 | 10 | 1; | |||||||||||||
| 223 | |||||||||||||||
| 224 | __END__ | ||||||||||||||