| 1 | package Wiki::Toolkit::Store::SQLite; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use vars qw( @ISA $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Wiki::Toolkit::Store::Database; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp qw/carp croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | @ISA = qw( Wiki::Toolkit::Store::Database ); | |||||||||||||||||||||||||||
| 11 | 3 | $VERSION = 0.06; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Wiki::Toolkit::Store::SQLite - SQLite storage backend for Wiki::Toolkit | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | See Wiki::Toolkit::Store::Database | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Internal method to return the data source string required by DBI. | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _dsn { | ||||||||||||||||||||||||||
|
Subroutine
_dsn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($self, $dbname) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | return "dbi:SQLite:dbname=$dbname"; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 METHODS | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =over 4 | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =item B<new> | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | my $store = Wiki::Toolkit::Store::SQLite->new( dbname => "wiki" ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | The dbname parameter is mandatory. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 43 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 44 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 45 | 1 | @args{qw(dbuser dbpass)} = ("", ""); # for the parent class _init | |||||||||||||||||||||||||||
| 46 | 1 | return $self->_init(%args); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =item B<check_and_write_node> | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $store->check_and_write_node( node => $node, | ||||||||||||||||||||||||||||
| 52 | checksum => $checksum, | ||||||||||||||||||||||||||||
| 53 | %other_args ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Locks the node, verifies the checksum, calls | ||||||||||||||||||||||||||||
| 56 | C<write_node_post_locking> with all supplied arguments, unlocks the | ||||||||||||||||||||||||||||
| 57 | node. Returns the version of the updated node on successful writing, 0 if | ||||||||||||||||||||||||||||
| 58 | checksum doesn't match, -1 if the change was not applied, croaks on error. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =back | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub check_and_write_node { | ||||||||||||||||||||||||||
|
Subroutine
check_and_write_node: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | my ($node, $checksum) = @args{qw( node checksum )}; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my $dbh = $self->{_dbh}; | |||||||||||||||||||||||||||
| 69 | 0 | $dbh->begin_work; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my $ok = eval { | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $self->verify_checksum($node, $checksum) or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->write_node_post_locking( %args ); | |||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $error = $@; | |||||||||||||||||||||||||||
| 77 | 0 | $dbh->rollback; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( $error =~ /database is locked/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$error =~ /database is locked/ or $error =~ /DBI connect.+failed/
MC/DC0%0/2
$error =~ /database is locked/ or $error =~ /DBI connect.+failed/
$error =~ /database is locked/
$error =~ /DBI connect.+failed/
Truth table0%0/3
A or B
A= $error =~ /database is locked/B= $error =~ /DBI connect.+failed/
| |||||||||||||||||||||||||||||
| 79 | or $error =~ /DBI connect.+failed/ ) { | ||||||||||||||||||||||||||||
| 80 | 0 | return 0; | |||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||
| 82 | 0 | croak "Unhandled error: [$error]"; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||
| 85 | 0 | $dbh->commit; | |||||||||||||||||||||||||||
| 86 | 0 | return $ok; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Get the attributes for the database connection. We set | ||||||||||||||||||||||||||||
| 91 | # sqlite_use_immediate_transaction to false because we use database locking | ||||||||||||||||||||||||||||
| 92 | # explicitly in check_and_write_node. This is required for DBD::SQLite 1.38. | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub _get_dbh_connect_attr { | ||||||||||||||||||||||||||
|
Subroutine
_get_dbh_connect_attr: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 0 | my $attrs = $self->SUPER::_get_dbh_connect_attr; | |||||||||||||||||||||||||||
| 96 | return { | ||||||||||||||||||||||||||||
| 97 | 0 | %$attrs, | |||||||||||||||||||||||||||
| 98 | sqlite_use_immediate_transaction => 0 | ||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _get_lowercase_compare_sql { | ||||||||||||||||||||||||||
|
Subroutine
_get_lowercase_compare_sql: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 103 | 0 | my ($self, $column) = @_; | |||||||||||||||||||||||||||
| 104 | 0 | return "$column LIKE ?"; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _get_comparison_sql { | ||||||||||||||||||||||||||
|
Subroutine
_get_comparison_sql: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 108 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $args{ignore_case} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | return "$args{thing1} LIKE $args{thing2}"; | |||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 0 | return "$args{thing1} = $args{thing2}"; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub _get_node_exists_ignore_case_sql { | ||||||||||||||||||||||||||
|
Subroutine
_get_node_exists_ignore_case_sql: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 117 | 0 | return "SELECT name FROM node WHERE name LIKE ? "; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | 1; | |||||||||||||||||||||||||||