| 1 | package ObjectDBI; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use DBI::Const::GetInfoType; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | ObjectDBI - Perl Object Persistence in an RDBMS using DBI | ||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | Serializes, queries, unserializes and deletes perl objects in an SQL driven, | ||||||||||||||||||||||||||||||||||||||||||||
| 16 | DBI accessible RDBMS. | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 MODULE | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | Created to use RDBMS-es as perl object storage, even when very primitive | ||||||||||||||||||||||||||||||||||||||||||||
| 21 | RDBMS-es are involved. The advantage is portability of your project | ||||||||||||||||||||||||||||||||||||||||||||
| 22 | (you don't have to transport a dbm or flat files with your project that | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | is also RDBMS-based), a certain degree of discoverability | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | (you can use plain SQL yourself to see what's inside the database), and | ||||||||||||||||||||||||||||||||||||||||||||
| 25 | searchability (metadata and data don't get equated). You must create | ||||||||||||||||||||||||||||||||||||||||||||
| 26 | a table for this storage, and (an idea for) the SQL for that is given below: | ||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 SQL | ||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | PostgreSQL or Oracle: | ||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | create sequence perlobjectseq; | ||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | create table "perlobjects" ( | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | obj_id integer unique not null, | ||||||||||||||||||||||||||||||||||||||||||||
| 36 | obj_pid integer references perlobjects (obj_id), | ||||||||||||||||||||||||||||||||||||||||||||
| 37 | obj_gpid integer references perlobjects (obj_id), | ||||||||||||||||||||||||||||||||||||||||||||
| 38 | obj_name varchar(255), | ||||||||||||||||||||||||||||||||||||||||||||
| 39 | obj_type varchar(64), | ||||||||||||||||||||||||||||||||||||||||||||
| 40 | obj_value varchar(255) | ||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | MySQL: | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | create table perlobjects ( | ||||||||||||||||||||||||||||||||||||||||||||
| 46 | obj_id integer unique not null auto_increment, | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | obj_pid integer references perlobjects (obj_id), | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | obj_gpid integer references perlobjects (obj_id), | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | obj_name varchar(255), | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | obj_type varchar(64), | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | obj_value varchar(255) | ||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | Indexes: | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | create index perlobjects_name_i on perlobjects (obj_name); | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | create index perlobjects_type_i on perlobjects (obj_type); | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | create index perlobjects_value_i on perlobjects (obj_value); | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | create index perlobjects_pid_i on perlobjects (obj_pid); | ||||||||||||||||||||||||||||||||||||||||||||
| 60 | create index perlobjects_gpid_i on perlobjects (obj_gpid); | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | Now before y'all start shouting; | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | obviously, given your particular type of RDBMS, your mileage may vary | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | with respect to this SQL code, and you may not have primary or foreign | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | keys. You may not have indexes or sequences, and you may even have an easier | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | way to store infinite strings. This is all up to you, your cleverness and your | ||||||||||||||||||||||||||||||||||||||||||||
| 67 | needs. | ||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | If you plan to store perlhashes with keys of more than 255 character length | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | (which is an unwise thing in itself), for example, then you might consider | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | making 'obj_name' a bit longer. If you plan to store values with characters | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | outside of the 32-126 range and you're using Postgres, then you might want | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | to change the data type of 'obj_value' from 'varchar' to 'bytea'. | ||||||||||||||||||||||||||||||||||||||||||||
| 74 | This module isn't here to lecture you - just to make things easy. | ||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | If you're using MySQL, you'll have problems without a sequence, so you'll | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | have to make the 'obj_id' field auto-incrementing. For those users, | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | a special piece of code is added to withdraw the id of an | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | object after the fact of its insertion. | ||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | If you're using a RDBMS that doesn't do sequences OR auto-incrementing, | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | then IDs are generated out of thin air. Be prepared to work with large | ||||||||||||||||||||||||||||||||||||||||||||
| 83 | numbers though. If your RDBMS can't handle those - well, then I'm at | ||||||||||||||||||||||||||||||||||||||||||||
| 84 | my wit's end: please provide a 'sequencefnc' to the constructor. | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 API | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head2 B<my $objectdbi = ObjectDBI-E<gt>new (%options)> | ||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | Returns a blessed instance of this module. | ||||||||||||||||||||||||||||||||||||||||||||
| 91 | The arguments provide the object with a hash of options, which can be: | ||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'dbh' => DBI database handle. | ||||||||||||||||||||||||||||||||||||||||||||
| 94 | 'dbiuri' => DBI database connection URI. | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'dbiuser' => DBI database connection user. | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'dbipass' => DBI database connection password. | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'dbioptions' => DBI database connection options. | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'table' => Table name used ('perlobjects' is the default). | ||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'sequence' => Sequence name for easily retrieving new IDs. | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'sequencesql' => Sequence SQL for retrieving a new ID. | ||||||||||||||||||||||||||||||||||||||||||||
| 101 | 'sequencefnc' => A function ref to be used to retrieve a new ID. | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | 'overwrite' => Overwrite objects of the same type and name. | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | 'chunksize' => A number defining at what length values will get split. | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | 'debug' => Setting it at anything will make STDERR a busy stream. | ||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | About sequences: the first available method given will be used. So please | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | do yourself a favour, avoid confusion, and use only one of the available | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | methods out of 'sequence', 'sequencesql' and 'sequencefnc'. | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | About chunksize: the default value is 255. If you set it to zero, that'll | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | be interpreted as 'infinite'. If you set it to anything else, make sure | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | it matches the storage size of the 'obj_value' field in the RDBMS. | ||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | Also about both sequences and chunksize: in the case of postgres and oracle, | ||||||||||||||||||||||||||||||||||||||||||||
| 115 | autodiscovery of these items will be performed in case they're not given. | ||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | my $classname = ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | $self->{objtable} = $options{table} || 'perlobjects'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{'table'} || 'perlobjects'
MC/DC0%0/1
$options{'table'} || 'perlobjects'
$options{'table'}
Truth table50%1/2
A
A= $options{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | if ($options{dbh}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $self->{dbh} = $options{dbh}; | |||||||||||||||||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 128 | $self->{dbh} = DBI->connect( | ||||||||||||||||||||||||||||||||||||||||||||
| 129 | $options{dbiuri}, | ||||||||||||||||||||||||||||||||||||||||||||
| 130 | $options{dbiuser}, | ||||||||||||||||||||||||||||||||||||||||||||
| 131 | $options{dbipass}, | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | $options{dbioptions} | ||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return undef if (!defined($self->{dbh})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | $self->{sequence} = $options{sequence}; | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | $self->{sequencesql} = $options{sequencesql}; | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | $self->{sequencefnc} = $options{sequencefnc}; | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | $self->{overwrite} = $options{overwrite}; | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $self->{chunksize} = $options{chunksize}; | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->{dbtype} = $self->{dbh}->get_info($GetInfoType{SQL_DBMS_NAME}); | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $self->{debug} = $options{debug}; | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | bless $self, $classname; | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | $self->__auto_discover(); | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | =head2 B<my $id = $objectdbi-E<gt>put ($ref[,$name[,$overwrite]])> | ||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | Store a reference in the database, perhaps under a certain name. | ||||||||||||||||||||||||||||||||||||||||||||
| 151 | If 'overwrite' is set (either in the object or as a parameter), | ||||||||||||||||||||||||||||||||||||||||||||
| 152 | and the object with given type and name already | ||||||||||||||||||||||||||||||||||||||||||||
| 153 | exists, it is removed prior to this object being written. | ||||||||||||||||||||||||||||||||||||||||||||
| 154 | Returns the ID of the object of the newly created object. | ||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub put { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: called CC=5 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | my $overwrite = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | if (ref($name)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $name = "$name"; | |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | if (!defined($overwrite)) { $overwrite = $self->{overwrite}; } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | my @ids; | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | if ($overwrite) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | @ids = $self->__objects_find(ref($ref), $name); | |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | my $id = $self->__put(undef, undef, $name, $ref, {}); | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | if ($id) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | $self->del_all(@ids); | |||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | =head2 B<my @ids = $objectdbi-E<gt>find ([$type],[$name],[$value])> | ||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | Find IDs for objects that match type and/or name and/or value. | ||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub find { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my ($type, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (ref($type)) { $type = ref($type); } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my @ids = $self->__objects_search($type, $name, $value); | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return wantarray ? @ids : \@ids; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | =head2 B<my $ref = $objectdbi-E<gt>get ($id) or $objectdbi-E<gt>get ($type, $name)> | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | Returns the fully deserialized object with the given ID, or | ||||||||||||||||||||||||||||||||||||||||||||
| 195 | find the first object that matches type and name. | ||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | if (scalar(@_) eq '1' && $id !~ /^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ eq 1 and not $id =~ /^[0-9]+$/
MC/DC0%0/2
scalar @_ eq 1 and not $id =~ /^[0-9]+$/
scalar @_ eq 1
not $id =~ /^[0-9]+$/
Truth table33%1/3
A and not(B)
A= scalar @_ eq 1B= not $id =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $type = ref($id) ? ref($id) : $id; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $id = $self->__objects_find($type, $name); | |||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | my $rows = $self->__object_get($id); | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | my $parent = $self->__get_children($rows, undef); | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | return $self->__get($rows, $parent->[0], {}); | |||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | =head2 B<my ($type, $name, $id) = $objectdbi-E<gt>get_meta ($id)> | ||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | Returns an array of type and name for an object with given ID. | ||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | sub get_meta { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_meta: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return $self->__object_get_meta($id); | |||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | =head2 B<my @refs = $objectdbi-E<gt>get_all (@ids)> | ||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | Auxillary method. | ||||||||||||||||||||||||||||||||||||||||||||
| 227 | Returns an array or array reference of objects with the given IDs. | ||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub get_all { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | foreach my $id (@_) { | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $object = $self->get($id); | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | push @result, $object; | |||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return wantarray ? @result : \@result; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | =head2 B<my @ids = $objectdbi-E<gt>query ($querystring)> | ||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | Queries the database with a specific query string. The syntax for this | ||||||||||||||||||||||||||||||||||||||||||||
| 244 | query 'language' is as follows: | ||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | =over | ||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | expressions are separated by logical operators ('&&', '||') | ||||||||||||||||||||||||||||||||||||||||||||
| 251 | and round braces ('(' and ')') determine precedence. | ||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | expressions are made up of a path, and optionally an operator ('==', '!=') | ||||||||||||||||||||||||||||||||||||||||||||
| 256 | and a value. | ||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | a path is a series of elements, representing hash-keys or array-indexes | ||||||||||||||||||||||||||||||||||||||||||||
| 261 | separated by a forward slash ('/'). | ||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | both paths and values may be enclosed in single or double quotes, so as to | ||||||||||||||||||||||||||||||||||||||||||||
| 266 | forego escaping of certain characters or whitespace. | ||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | an element can have wildcards (an asterisk ('*')), or be a wildcard in itself. | ||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | a back slash escapes all tokens, one character at a time. | ||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | =item | ||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | outside of quoted strings and path elements, whitespace is ignored. | ||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | =back | ||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub query { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | return $self->__query($query); | |||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | =head2 B<my @types = $objectdbi-E<gt>get_types ()> | ||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | Returns a distinct list of all object types known to the database. | ||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub get_types { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_types: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return $self->__object_get_types(); | |||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | =head2 B<my $n = $objectdbi-E<gt>del ($id) or $objectdbi-E<gt>del ($type, $name)> | ||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | Deletes an object by the given ID, or deletes the first object which | ||||||||||||||||||||||||||||||||||||||||||||
| 304 | matches type and name. Returns zero or non zero depending on whether | ||||||||||||||||||||||||||||||||||||||||||||
| 305 | the operation failed or was successful, respectively. | ||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub del { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if (scalar(@_) eq '1' && $id !~ /^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @_ eq 1 and not $id =~ /^[0-9]+$/
MC/DC0%0/2
scalar @_ eq 1 and not $id =~ /^[0-9]+$/
scalar @_ eq 1
not $id =~ /^[0-9]+$/
Truth table0%0/3
A and not(B)
A= scalar @_ eq 1B= not $id =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | my $type = ref($id) ? ref($id) : $id; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $id = $self->__objects_find($type, $name); | |||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->__del($id); | |||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | =head2 B<my $n = $objectdbi-E<gt>del_all (@ids)> | ||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | Auxillary method. | ||||||||||||||||||||||||||||||||||||||||||||
| 323 | Deletes all objects with given IDs. | ||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | sub del_all { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del_all: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | foreach my $id (@_) { | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $n += $self->del($id); | |||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | return $n; | |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head2 B<my $n = $objectdbi-E<gt>count ([type], [query])> | ||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | Returns the amount of objects that answer to these conditions. | ||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($type, $query); | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if (defined($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $type = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if (defined($_[1])) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $query = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 353 | "SELECT DISTINCT(TABLE1.obj_gpid)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 354 | " from $self->{objtable} as TABLE1 where 1=1"; | ||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ($query) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my @tokens = ObjectDBI::__tokenize_query($query); | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | my $parsetree = ObjectDBI::__parse_query(@tokens) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
__parse_query(@tokens) || (return undef)
MC/DC0%0/1
__parse_query(@tokens) || (return undef)
__parse_query(@tokens)
Truth table0%0/2
A
A= __parse_query(@tokens)
| |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ($sql, @params) = $self->__tree_to_sql($parsetree); | |||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 362 | "SELECT DISTINCT(obj_gpid)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 363 | " FROM $self->{objtable}" . | ||||||||||||||||||||||||||||||||||||||||||||
| 364 | " WHERE obj_type=?" . | ||||||||||||||||||||||||||||||||||||||||||||
| 365 | " AND obj_pid is null" . | ||||||||||||||||||||||||||||||||||||||||||||
| 366 | " INTERSECT " . | ||||||||||||||||||||||||||||||||||||||||||||
| 367 | $sql; | ||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | unshift @params, $type; | |||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 370 | # $sql =~ s/^SELECT DISTINCT/SELECT COUNT/; | ||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $sql = "SELECT COUNT(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $result = $self->get_dbh()->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||
| 376 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 377 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | =head2 B<my $dbh = $objectdbi-E<gt>get_dbh ()> | ||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | Returns the DBI database handle. | ||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | ▶ | sub get_dbh { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_dbh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | return $self->{dbh}; | |||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | ##---- private stuff -------------------------------------------------------## | ||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | 4 | ▶ | sub __put { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__put: called CC=22 SCAR=41.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | my ($pid, $gpid, $name, $ref, $cache) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 4 | my $type = ref($ref); | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 4 | my $id; | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 4 | ▶ | if (!defined($ref)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $id = $self->__object_put($pid, $gpid, $name, undef, undef); | |||||||||||||||||||||||||||||||||||||||||||
| 401 | } elsif (my $cache_id = $cache->{"$ref"}) { | ||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | $id = $self->__object_put($pid, $gpid, $name, '@@REF', $cache_id); | |||||||||||||||||||||||||||||||||||||||||||
| 403 | } elsif (UNIVERSAL::isa($ref, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | $id = $self->__object_put($pid, $gpid, $name, $type, 'ARRAY') || | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->__object_put($pid, $gpid, $name, $type, 'ARRAY') || (return undef)
MC/DC0%0/1
$self->__object_put($pid, $gpid, $name, $type, 'ARRAY') || (return undef)
$self->__object_put($pid, $gpid, $name, $type, 'ARRAY')
Truth table50%1/2
A
A= $self->__object_put($pid, $gpid, $name, $type, 'ARRAY')
| |||||||||||||||||||||||||||||||||||||||||||||
| 405 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | $cache->{"$ref"} = $id; | |||||||||||||||||||||||||||||||||||||||||||
| 407 | # if (!defined($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if (!length($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | ▶ | for (my $i=0; $i<scalar(@{$ref}); $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | my $elt = $ref->[$i]; | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | return undef if (!$self->__put($id, $gpid, $i, $elt, $cache)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 413 | } elsif (UNIVERSAL::isa($ref, 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | $cache->{"$ref"} = $id; | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | ▶ | $id = $self->__object_put($pid, $gpid, $name, $type, 'HASH') || | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->__object_put($pid, $gpid, $name, $type, 'HASH') || (return undef)
MC/DC0%0/1
$self->__object_put($pid, $gpid, $name, $type, 'HASH') || (return undef)
$self->__object_put($pid, $gpid, $name, $type, 'HASH')
Truth table50%1/2
A
A= $self->__object_put($pid, $gpid, $name, $type, 'HASH')
| |||||||||||||||||||||||||||||||||||||||||||||
| 416 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 417 | # if (!defined($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | if (!length($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | foreach my $key (keys(%{$ref})) { | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | ▶ | return undef if (!$self->__put($id, $gpid, $key, $ref->{$key}, $cache)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 422 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | my $value = "$ref"; | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | ▶ | if ($self->{chunksize} && length($value) > $self->{chunksize}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"chunksize"} and length $value > $self->{"chunksize"}
MC/DC0%0/2
$self->{"chunksize"} and length $value > $self->{"chunksize"}
$self->{"chunksize"}
length $value > $self->{"chunksize"}
Truth table33%1/3
A and B
A= $self->{"chunksize"}B= length $value > $self->{"chunksize"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | $id = $self->__object_put($pid, $gpid, $name, '@@SUBSTR', '') || | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->__object_put($pid, $gpid, $name, '@@SUBSTR', '') || (return undef)
MC/DC0%0/1
$self->__object_put($pid, $gpid, $name, '@@SUBSTR', '') || (return undef)
$self->__object_put($pid, $gpid, $name, '@@SUBSTR', '')
Truth table0%0/2
A
A= $self->__object_put($pid, $gpid, $name, '@@SUBSTR', '')
| |||||||||||||||||||||||||||||||||||||||||||||
| 426 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 427 | # if (!defined($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if (!length($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $section = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | while (length($value) > $self->{chunksize}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $subvalue = substr($value, 0, $self->{chunksize}); | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $value = substr($value, $self->{chunksize}); | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | $self->__object_put($id, $gpid, $section++, undef, $subvalue) || | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 434 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $self->__object_put($id, $gpid, $section++, undef, $value) || | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 437 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 438 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | ▶ | $id = $self->__object_put($pid, $gpid, $name, undef, "$ref") || | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->__object_put($pid, $gpid, $name, undef, "$ref") || (return undef)
MC/DC0%0/1
$self->__object_put($pid, $gpid, $name, undef, "$ref") || (return undef)
$self->__object_put($pid, $gpid, $name, undef, "$ref")
Truth table50%1/2
A
A= $self->__object_put($pid, $gpid, $name, undef, "$ref")
| |||||||||||||||||||||||||||||||||||||||||||||
| 440 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||
| 441 | # if (!defined($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if (!length($gpid)) { $gpid = $id; } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | sub __get_children { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__get_children: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | my $rows = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 3 | my $pid = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 3 | my @result; | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 3 | ▶ | for (my $i=0; $i<scalar(@{$rows}); $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 454 | 8 | my $row = $rows->[$i]; | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 8 | ▶ | if ($row->{pid} eq $pid) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 456 | 4 | push @result, splice(@{$rows}, $i--, 1); | |||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 459 | 3 | @result = sort { $a->{id} <=> $b->{id} } @result; | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | return \@result; | |||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | ▶ | sub __get { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__get: called CC=14 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | my $rows = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | my $row = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | my $cache = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | my $object; | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | ▶ | if ($row->{type} && $row->{value} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
$row->{"type"} and $row->{"value"} eq "ARRAY"
MC/DC100%2/2
$row->{"type"} and $row->{"value"} eq "ARRAY"
$row->{"type"}
$row->{"value"} eq "ARRAY"
Truth table100%3/3
A and B
A= $row->{"type"}B= $row->{"value"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | $object = []; | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | $cache->{$row->{id}} = $object; | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | if ($row->{type} ne $row->{value}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | bless $object, $row->{type}; | |||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | my $subrows = $self->__get_children($rows, $row->{id}); | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | foreach my $subrow (@{$subrows}) { | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | $object->[int($subrow->{name})] = $self->__get($rows, $subrow, $cache); | |||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 479 | ▶ | } elsif ($row->{type} && $row->{value} eq 'HASH') { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$row->{"type"} and $row->{"value"} eq "HASH"
MC/DC100%2/2
$row->{"type"} and $row->{"value"} eq "HASH"
$row->{"type"}
$row->{"value"} eq "HASH"
Truth table100%3/3
A and B
A= $row->{"type"}B= $row->{"value"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | $object = {}; | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | $cache->{$row->{id}} = $object; | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | if ($row->{type} ne $row->{value}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | bless $object, $row->{type}; | |||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | my $subrows = $self->__get_children($rows, $row->{id}); | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | foreach my $subrow (@{$subrows}) { | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 2 | $object->{$subrow->{name}} = $self->__get($rows, $subrow, $cache); | |||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 489 | } elsif ($row->{type} eq '@@SUBSTR') { | ||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $subrows = $self->__get_children($rows, $row->{id}); | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my @subrows = sort { $a->{name} <=> $b->{name} } @{$subrows}; | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $value = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | foreach my $subrow (@subrows) { | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $value .= $subrow->{value}; | |||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||
| 497 | } elsif ($row->{type} eq '@@REF') { | ||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | return $cache->{$row->{value}}; | |||||||||||||||||||||||||||||||||||||||||||
| 499 | # } elsif (!defined($row->{type})) { | ||||||||||||||||||||||||||||||||||||||||||||
| 500 | } elsif (!length($row->{type})) { | ||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | return $row->{value}; | |||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | return wantarray ? ($object, $row->{name}) : $object; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | sub __del { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__del: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | $self->__object_del($id); | |||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub __query { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__query: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->__query_to_sql($query); | |||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub __tokenize_query { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__tokenize_query: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $curelt = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my @tokens; | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | while (length($query)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | if ($query =~ s/^\s+//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | if (length($curelt)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | push @tokens, $curelt; | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $curelt = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if ($query =~ s/^(!=|==|\(|\)|&&|\|\||\/)//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if (length($curelt)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | push @tokens, $curelt; | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $curelt = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | push @tokens, $1; | |||||||||||||||||||||||||||||||||||||||||||
| 535 | } elsif ($query =~ s/^([!=\(\)&\|])//) { | ||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $curelt .= $1; | |||||||||||||||||||||||||||||||||||||||||||
| 537 | } elsif ($query =~ s/^(['"])//) { | ||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $delim = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | if (length($curelt)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | push @tokens, $curelt; | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $curelt = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | while ($query =~ s/^([^$delim])//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my $char = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $query =~ s/^(.)//s; | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $curelt .= $1; | |||||||||||||||||||||||||||||||||||||||||||
| 548 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $curelt .= $char; | |||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $query =~ s/^.//; | |||||||||||||||||||||||||||||||||||||||||||
| 553 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | while ($query =~ s/^([^!=\(\)&\|\/\s])//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $char = $1; | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $query =~ s/^(.)//s; | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $curelt .= $1; | |||||||||||||||||||||||||||||||||||||||||||
| 559 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | $curelt .= $char; | |||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if (length($curelt)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | push @tokens, $curelt; | |||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | return @tokens; | |||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | sub __parse_query { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__parse_query: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my @tokens = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | my @operators = ( | |||||||||||||||||||||||||||||||||||||||||||
| 574 | '&&', | ||||||||||||||||||||||||||||||||||||||||||||
| 575 | '||', | ||||||||||||||||||||||||||||||||||||||||||||
| 576 | '==', | ||||||||||||||||||||||||||||||||||||||||||||
| 577 | '!=', | ||||||||||||||||||||||||||||||||||||||||||||
| 578 | '/', | ||||||||||||||||||||||||||||||||||||||||||||
| 579 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | foreach my $operator (@operators) { | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | for (my $i=0; $i<scalar(@tokens); $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my $token = $tokens[$i]; | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | next if (ref($token)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | if ($token eq '(') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my $begin = $i; | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $level = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | for (++$i; $i<scalar(@tokens); $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $token = $tokens[$i]; | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if ($token eq '(') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ++$level; | |||||||||||||||||||||||||||||||||||||||||||
| 591 | } elsif ($token eq ')') { | ||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if (--$level == 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my @bracketcontent = splice(@tokens, $begin, 1+$i-$begin); | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | pop @bracketcontent; | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | shift @bracketcontent; | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my $term = __parse_query(@bracketcontent) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
__parse_query(@bracketcontent) || (return undef)
MC/DC0%0/1
__parse_query(@bracketcontent) || (return undef)
__parse_query(@bracketcontent)
Truth table0%0/2
A
A= __parse_query(@bracketcontent)
| |||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $tokens[$begin] = $term; | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $i = $begin; | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | if ($level) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | return undef; # unmatched brackets | |||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 606 | } elsif ($token eq $operator) { | ||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my @operand2 = splice(@tokens, $i+1); | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my @operand1 = splice(@tokens, 0, $i); | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | my $operand1 = __parse_query(@operand1) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
__parse_query(@operand1) || (return undef)
MC/DC0%0/1
__parse_query(@operand1) || (return undef)
__parse_query(@operand1)
Truth table0%0/2
A
A= __parse_query(@operand1)
| |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | my $operand2 = __parse_query(@operand2) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
__parse_query(@operand2) || (return undef)
MC/DC0%0/1
__parse_query(@operand2) || (return undef)
__parse_query(@operand2)
Truth table0%0/2
A
A= __parse_query(@operand2)
| |||||||||||||||||||||||||||||||||||||||||||||
| 611 | return { | ||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | operator => $operator, | |||||||||||||||||||||||||||||||||||||||||||
| 613 | operands => [ $operand1, $operand2 ] | ||||||||||||||||||||||||||||||||||||||||||||
| 614 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 615 | # } elsif (!grep(@operators, $token)) { | ||||||||||||||||||||||||||||||||||||||||||||
| 616 | # $tokens[$i] = { | ||||||||||||||||||||||||||||||||||||||||||||
| 617 | # term => $token | ||||||||||||||||||||||||||||||||||||||||||||
| 618 | # }; | ||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | return $tokens[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | sub __tree_to_sql { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__tree_to_sql: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my $parsetree = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | my $hash = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $postprocess = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if (!defined($hash)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $hash = { n => 1, tables => 1, param => 0, params => {} }; | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $postprocess = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | my $n = $hash->{n}; | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ($parsetree->{operator} eq '&&') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | $n = $hash->{n} = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 638 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[0], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 640 | " AND 1=1"; | ||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | $n = $hash->{n} = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 642 | $result .= | ||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[1], $hash)); | |||||||||||||||||||||||||||||||||||||||||||
| 644 | } elsif ($parsetree->{operator} eq '||') { | ||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | $n = $hash->{n} = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 646 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 647 | "((1=1" . | ||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[0], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 649 | ") OR (1=1"; | ||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $n = $hash->{n} = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 651 | $result .= | ||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[1], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 653 | "))"; | ||||||||||||||||||||||||||||||||||||||||||||
| 654 | } elsif ($parsetree->{operator} eq '==') { | ||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | my $operand = "$parsetree->{operands}[1]"; | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my $operator = '='; | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | if ($operand =~ s/\*/\%/g) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | $operator = 'like'; | |||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 660 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[0], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 662 | " AND TABLE$n.obj_value $operator ?$hash->{param}"; | ||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | $hash->{params}{$hash->{param}++} = $operand; | |||||||||||||||||||||||||||||||||||||||||||
| 664 | } elsif ($parsetree->{operator} eq '!=') { | ||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | my $operand = "$parsetree->{operands}[1]"; | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | my $operator = '<>'; | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if ($operand =~ s/\*/\%/g) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | $operator = 'not like'; | |||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 670 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[0], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 672 | " AND TABLE$n.obj_value $operator ?$hash->{param}"; | ||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | $hash->{params}{$hash->{param}++} = $operand; | |||||||||||||||||||||||||||||||||||||||||||
| 674 | } elsif ($parsetree->{operator} eq '/') { | ||||||||||||||||||||||||||||||||||||||||||||
| 675 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 676 | "TABLE$n.obj_pid " . | ||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[1], $hash)); | |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | if (++($hash->{n}) > $hash->{tables}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $hash->{tables} = $hash->{n}; | |||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 681 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | (my $x = $self->__tree_to_sql($parsetree->{operands}[0], $hash)) . | |||||||||||||||||||||||||||||||||||||||||||
| 683 | " AND TABLE$hash->{n}.obj_id=$result"; | ||||||||||||||||||||||||||||||||||||||||||||
| 684 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | my $operand = "$parsetree"; | |||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $operator = '='; | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | if ($operand =~ s/\*/\%/g) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | $operator = 'like'; | |||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | $result = " AND TABLE$n.obj_name $operator ?$hash->{param}"; | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | $hash->{params}{$hash->{param}++} = $operand; | |||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | ▶ | if ($postprocess) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | my @tables; | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | for (my $i=1; $i<=$hash->{tables}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | push @tables, "$self->{objtable} TABLE$i"; | |||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my $tmp = $result; | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my $i=0; | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | while ($tmp =~ s/^[^\?]*\?([0-9]+)//) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $params[$i++] = $hash->{params}{$1}; | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | $result =~ s/\?$1/?/; | |||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 705 | $result = | ||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | "SELECT DISTINCT(TABLE1.obj_gpid) FROM " . join(',', @tables) . | |||||||||||||||||||||||||||||||||||||||||||
| 707 | " WHERE $result"; | ||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $result =~ s/where\s+and/where/i; | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $result =~ s/where\s+or/where/i; | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $result =~ s/1=1\s+and//i; | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | print STDERR "SQL: '$result' with params: '" . join("', '", @params) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | return wantarray ? ($result, @params) : $result; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | sub __query_to_sql { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__query_to_sql: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my @tokens = __tokenize_query($query); | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | my $parsetree = __parse_query(@tokens) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
__parse_query(@tokens) || (return undef)
MC/DC0%0/1
__parse_query(@tokens) || (return undef)
__parse_query(@tokens)
Truth table0%0/2
A
A= __parse_query(@tokens)
| |||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my ($sql, @params) = $self->__tree_to_sql($parsetree); | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | return $self->__object_select_col($sql, @params); | |||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||
| 727 | ##---- dbh stuff -----------------------------------------------------------## | ||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | ## | ||||||||||||||||||||||||||||||||||||||||||||
| 730 | ## Function to do some auto discovery on known database types. | ||||||||||||||||||||||||||||||||||||||||||||
| 731 | ## | ||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | sub __auto_discover_postgres { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__auto_discover_postgres: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if (!defined($self->{sequence}) && | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $self->{"sequence"} or defined $self->{"sequencesql"} or defined $self->{"sequencefnc"}
defined $self->{"sequence"} or defined $self->{"sequencesql"}
MC/DC0%0/3
defined $self->{"sequence"} or defined $self->{"sequencesql"} or defined $self->{"sequencefnc"}
defined $self->{"sequence"}
defined $self->{"sequencesql"}
defined $self->{"sequencefnc"}
Truth table0%0/4
A or B or C
A= defined $self->{"sequence"}B= defined $self->{"sequencesql"}C= defined $self->{"sequencefnc"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 736 | !defined($self->{sequencesql}) && | ||||||||||||||||||||||||||||||||||||||||||||
| 737 | !defined($self->{sequencefnc})) { | ||||||||||||||||||||||||||||||||||||||||||||
| 738 | my $sequences = $self->{dbh}->selectcol_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | "select relname from pg_class where relkind='S'" | |||||||||||||||||||||||||||||||||||||||||||
| 740 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | if (scalar(@{$sequences})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | $self->{sequence} = $sequences->[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 743 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | $self->{dbh}->do("create sequence perlobjectseq"); | |||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | $self->{sequence} = 'perlobjectseq'; | |||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | if (!defined($self->{chunksize})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 749 | my $size = $self->{dbh}->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | "select attlen from pg_attribute, pg_class" . | |||||||||||||||||||||||||||||||||||||||||||
| 751 | " where pg_attribute.attrelid=pg_class.oid" . | ||||||||||||||||||||||||||||||||||||||||||||
| 752 | " and pg_class.relkind='r'" . | ||||||||||||||||||||||||||||||||||||||||||||
| 753 | " and pg_class.relname='$self->{objtable}'" . | ||||||||||||||||||||||||||||||||||||||||||||
| 754 | " and pg_attribute.attname='obj_value'" | ||||||||||||||||||||||||||||||||||||||||||||
| 755 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ($size <= 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | $self->{chunksize} = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 758 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | $self->{chunksize} = $size; | |||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | sub __auto_discover_oracle { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__auto_discover_oracle: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if (!defined($self->{sequence}) && | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $self->{"sequence"} or defined $self->{"sequencesql"} or defined $self->{"sequencefnc"}
defined $self->{"sequence"} or defined $self->{"sequencesql"}
MC/DC0%0/3
defined $self->{"sequence"} or defined $self->{"sequencesql"} or defined $self->{"sequencefnc"}
defined $self->{"sequence"}
defined $self->{"sequencesql"}
defined $self->{"sequencefnc"}
Truth table0%0/4
A or B or C
A= defined $self->{"sequence"}B= defined $self->{"sequencesql"}C= defined $self->{"sequencefnc"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 767 | !defined($self->{sequencesql}) && | ||||||||||||||||||||||||||||||||||||||||||||
| 768 | !defined($self->{sequencefnc})) { | ||||||||||||||||||||||||||||||||||||||||||||
| 769 | my $sequences = $self->{dbh}->selectcol_arrayref( | ||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | "SELECT SEQUENCE_NAME FROM USER_SEQUENCES" | |||||||||||||||||||||||||||||||||||||||||||
| 771 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | if (scalar(@{$sequences})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | $self->{sequence} = $sequences->[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 774 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | $self->{dbh}->do("create sequence perlobjectseq"); | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | $self->{sequence} = 'perlobjectseq'; | |||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | if (!defined($self->{chunksize})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 780 | my $size = $self->{dbh}->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | "SELECT DATA_LENGTH FROM USER_TAB_COLUMNS" . | |||||||||||||||||||||||||||||||||||||||||||
| 782 | " WHERE TABLE_NAME='$self->{objtable}'" | ||||||||||||||||||||||||||||||||||||||||||||
| 783 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $self->{chunksize} = $size; | |||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | sub __auto_discover_mysql { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__auto_discover_mysql: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1 | ▶ | sub __auto_discover { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__auto_discover: called CC=8 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||||
| 793 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 794 | 1 | ▶ | if ($self->{dbtype} =~ /^(postgresql|postgres|pg|pgsql)$/i) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | print STDERR "AUTODISCOVER PostgreSQL backend.\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | $self->__auto_discover_postgres(); | |||||||||||||||||||||||||||||||||||||||||||
| 799 | } elsif ($self->{dbtype} =~ /^oracle$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $self->__auto_discover_oracle(); | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | print STDERR "AUTODISCOVER Oracle backend.\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 804 | } elsif ($self->{dbtype} =~ /^mysql$/i) { | ||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | $self->__auto_discover_mysql(); | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | print STDERR "AUTODISCOVER MySQL backend.\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1 | ▶ | if (!defined($self->{chunksize})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 811 | 1 | $self->{chunksize} = 255; | |||||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | sub __object_select_col { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_select_col: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | my ($sql, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | ▶ | my $sth = $self->{dbh}->prepare($sql) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbh'}->prepare($sql) || (return undef)
MC/DC0%0/1
$self->{'dbh'}->prepare($sql) || (return undef)
$self->{'dbh'}->prepare($sql)
Truth table0%0/2
A
A= $self->{'dbh'}->prepare($sql)
| |||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | $sth->execute(@args) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | while (my @row = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | push @result, $row[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | return wantarray ? @result : $result[0]; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | sub __objects_search { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__objects_search: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my ($type, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | my $recursive = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | my @cond; | |||||||||||||||||||||||||||||||||||||||||||
| 832 | my @args; | ||||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | push @cond, "obj_type=?"; | |||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | push @args, $type; | |||||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | if ($name) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | push @cond, "obj_name=?"; | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | push @args, $name; | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | $recursive = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | push @cond, "upper(obj_value) like ?"; | |||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | push @args, '%' . uc($value) . '%'; | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | $recursive = 1; | |||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | ▶ | if (!$recursive) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | push @cond, "obj_pid is null"; | |||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 851 | "select distinct(obj_gpid) from $self->{objtable} where " . | ||||||||||||||||||||||||||||||||||||||||||||
| 852 | join(" and ", @cond); | ||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | print STDERR "SQL '$sql' with params '" . join("', '", @args) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | my @ids = $self->__object_select_col($sql, @args); | |||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | return @ids; | |||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | sub __objects_find { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__objects_find: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | my ($type, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 864 | "select obj_id from $self->{objtable}" . | ||||||||||||||||||||||||||||||||||||||||||||
| 865 | " where obj_gpid=obj_id and obj_type=? and obj_name=?"; | ||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | print STDERR "SQL '$sql' with params '$type', '$name'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | my @ids = $self->__object_select_col($sql, $type, $name); | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | return wantarray ? @ids : $ids[0]; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||
| 873 | 1 | ▶ | sub __object_get { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_get: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||
| 874 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 875 | 1 | my $id = int(shift()); | |||||||||||||||||||||||||||||||||||||||||||
| 876 | 1 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 'select obj_id, obj_pid, obj_gpid,' . | ||||||||||||||||||||||||||||||||||||||||||||
| 878 | ' obj_name, obj_type, obj_value' . | ||||||||||||||||||||||||||||||||||||||||||||
| 879 | " from $self->{objtable} where obj_gpid='$id'" . | ||||||||||||||||||||||||||||||||||||||||||||
| 880 | " order by obj_pid, obj_id"; | ||||||||||||||||||||||||||||||||||||||||||||
| 881 | 1 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | print STDERR "SQL '$sql'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 884 | 1 | my $rows = $self->{dbh}->selectall_arrayref($sql); | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 1 | ▶ | if (!scalar(@{$rows})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 888 | 1 | my @result; | |||||||||||||||||||||||||||||||||||||||||||
| 889 | 1 | foreach my $row (@{$rows}) { | |||||||||||||||||||||||||||||||||||||||||||
| 890 | 4 | my $hash = { | |||||||||||||||||||||||||||||||||||||||||||
| 891 | id => $row->[0], | ||||||||||||||||||||||||||||||||||||||||||||
| 892 | pid => $row->[1], | ||||||||||||||||||||||||||||||||||||||||||||
| 893 | gpid => $row->[2], | ||||||||||||||||||||||||||||||||||||||||||||
| 894 | name => $row->[3], | ||||||||||||||||||||||||||||||||||||||||||||
| 895 | type => $row->[4], | ||||||||||||||||||||||||||||||||||||||||||||
| 896 | value => $row->[5], | ||||||||||||||||||||||||||||||||||||||||||||
| 897 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 898 | 4 | push @result, $hash; | |||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 900 | 1 | return \@result; | |||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | ▶ | sub __object_get_meta { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_get_meta: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | my $id = int(shift()); | |||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 907 | "select obj_type, obj_name, obj_id from $self->{objtable} where obj_id=$id"; | ||||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | print STDERR "SQL '$sql'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | return $self->{dbh}->selectrow_array($sql); | |||||||||||||||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | ▶ | sub __object_get_types { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_get_types: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 917 | "select distinct(obj_type) from $self->{objtable} where obj_gpid=obj_id"; | ||||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | print STDERR "SQL '$sql'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | return $self->{dbh}->selectcol_arrayref($sql); | |||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | ▶ | sub __object_put_mysql { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_put_mysql: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | my ($pid, $gpid, $name, $type, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 928 | "insert into $self->{objtable}" . | ||||||||||||||||||||||||||||||||||||||||||||
| 929 | " (obj_pid, obj_gpid, obj_name, obj_type, obj_value)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 930 | " values (?,?,?,?,?)"; | ||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | print STDERR "SQL '$sql' with params '" . join("', '", @_) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | ▶ | if ($self->{dbh}->do($sql, undef, @_)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | my $id = $self->{dbh}->do("select last_insert_id()"); | |||||||||||||||||||||||||||||||||||||||||||
| 936 | # if (!defined($gpid)) { | ||||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | ▶ | if (!length($gpid)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 938 | $self->{dbh}->do( | ||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | "update $self->{objtable} set obj_gpid=$id where obj_id=$id" | |||||||||||||||||||||||||||||||||||||||||||
| 940 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||
| 947 | 4 | ▶ | sub __object_put { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_put: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||||||||||||||||||
| 948 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 949 | 4 | my ($pid, $gpid, $name, $type, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||
| 950 | 4 | ▶ | if ($self->{dbtype} =~ /mysql/i) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | return $self->__object_put_mysql($pid, $gpid, $name, $type, $value); | |||||||||||||||||||||||||||||||||||||||||||
| 952 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 953 | 4 | my $id = $self->__new_id(); | |||||||||||||||||||||||||||||||||||||||||||
| 954 | 4 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 955 | "insert into $self->{objtable}" . | ||||||||||||||||||||||||||||||||||||||||||||
| 956 | " (obj_id, obj_pid, obj_gpid, obj_name, obj_type, obj_value)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 957 | " values (?,?,?,?,?,?)"; | ||||||||||||||||||||||||||||||||||||||||||||
| 958 | 4 | ▶ | my @params = ( | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 959 | # $id, $pid, (defined($gpid) ? $gpid : $id), $name, $type, $value | ||||||||||||||||||||||||||||||||||||||||||||
| 960 | $id, $pid, (length($gpid) ? $gpid : $id), $name, $type, $value | ||||||||||||||||||||||||||||||||||||||||||||
| 961 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 962 | 4 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | print STDERR "SQL '$sql' with params '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 965 | 4 | ▶ | if ($self->{dbh}->do($sql, undef, @params)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 966 | 4 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 967 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 971 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | sub __object_del { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__object_del: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | my $id = int(shift()); | |||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | my $sql = "delete from $self->{objtable} where obj_gpid=?"; | |||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | print STDERR "SQL '$sql' with params '$id'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | $self->{dbh}->do($sql, undef, $id); | |||||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||
| 983 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||
| 985 | 4 | ▶ | sub __new_id { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__new_id: called CC=7 SCAR=32.4
| |||||||||||||||||||||||||||||||||||||||||||||
| 986 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 987 | 4 | ▶ | if ($self->{sequence}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | my $sql = "select nextval('$self->{sequence}')"; | |||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | my $type = $self->{dbtype}; | |||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | if ($type =~ /oracle/i) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | $sql = "SELECT $self->{sequence}.NEXTVAL FROM DUAL"; | |||||||||||||||||||||||||||||||||||||||||||
| 992 | ▶ | } elsif ($type =~ /pg/i || $type =~ /postgres/i) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$type =~ /pg/i or $type =~ /postgres/i
MC/DC0%0/2
$type =~ /pg/i or $type =~ /postgres/i
$type =~ /pg/i
$type =~ /postgres/i
Truth table0%0/3
A or B
A= $type =~ /pg/iB= $type =~ /postgres/i
| |||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | $sql = "select nextval('$self->{sequence}')"; | |||||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | my $id = $self->{dbh}->selectrow_array($sql); | |||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 997 | } elsif ($self->{sequencesql}) { | ||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | my $id = $self->{dbh}->selectrow_array($self->{sequencesql}); | |||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 1000 | } elsif ($self->{sequencefnc}) { | ||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 4 | my $fnc = $self->{sequencefnc}; | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 4 | my $id = &$fnc(); | |||||||||||||||||||||||||||||||||||||||||||
| 1003 | 4 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | my $id = int(sprintf("%d%.4d", time(), ++$count)); | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | return $id; | |||||||||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | sub cursor { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | return ObjectDBI::Cursor->new($self, @_); | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||
| 1015 | package ObjectDBI::Cursor; | ||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||
| 1017 | =head1 CURSORS | ||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||
| 1019 | Cursors are there to obtain lists of objects in a 'streaming' (as opposed | ||||||||||||||||||||||||||||||||||||||||||||
| 1020 | to 'buffered') fashion. When the list of objects is (potentially) too long | ||||||||||||||||||||||||||||||||||||||||||||
| 1021 | to retrieve all at once, you'd use a cursor and iterate through it. | ||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||
| 1023 | =head2 B<my $cursor = $objectdbi-E<gt>cursor([query], [type]);> | ||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||
| 1025 | or | ||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||
| 1027 | =head2 B<my $cursor = ObjectDBI::Cursor-E<gt>new($objectdbi, [query], [type]);> | ||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||
| 1029 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||
| 1031 | my $cursor = $objectdbi->cursor("foo"); | ||||||||||||||||||||||||||||||||||||||||||||
| 1032 | while (my $ref = $cursor->next()) { | ||||||||||||||||||||||||||||||||||||||||||||
| 1033 | print Dumper($ref); | ||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||
| 1036 | Bear in mind that the query given when initializing the cursor is optional. | ||||||||||||||||||||||||||||||||||||||||||||
| 1037 | When no query is given, you simply iterate through the entire set of objects. | ||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||
| 1039 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $objectdbi = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | if (!UNIVERSAL::isa($objectdbi, 'ObjectDBI')) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | die "Need ObjectDBI reference as argument"; | |||||||||||||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | ▶ | my $classname = ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||
| 1049 | OBJECTDBI => $objectdbi, | ||||||||||||||||||||||||||||||||||||||||||||
| 1050 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | bless $self, $classname; | |||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | my $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 1053 | "SELECT DISTINCT(TABLE1.obj_gpid)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 1054 | " from $objectdbi->{objtable} as TABLE1 where 1=1"; | ||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | $self->{PARAMS} = \@params; | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | ▶ | if (defined($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | my $query = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | my @tokens = ObjectDBI::__tokenize_query($query); | |||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | ▶ | my $parsetree = ObjectDBI::__parse_query(@tokens) || return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
ObjectDBI::__parse_query(@tokens) || (return undef)
MC/DC0%0/1
ObjectDBI::__parse_query(@tokens) || (return undef)
ObjectDBI::__parse_query(@tokens)
Truth table0%0/2
A
A= ObjectDBI::__parse_query(@tokens)
| |||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | ($sql, @params) = $self->{OBJECTDBI}->__tree_to_sql($parsetree); | |||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | $self->{QUERY} = $query; | |||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | if (defined($_[1])) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | my $type = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | $sql = | |||||||||||||||||||||||||||||||||||||||||||
| 1067 | "SELECT DISTINCT(obj_gpid)" . | ||||||||||||||||||||||||||||||||||||||||||||
| 1068 | " FROM $objectdbi->{objtable}" . | ||||||||||||||||||||||||||||||||||||||||||||
| 1069 | " WHERE obj_type=?" . | ||||||||||||||||||||||||||||||||||||||||||||
| 1070 | " AND obj_pid is null" . | ||||||||||||||||||||||||||||||||||||||||||||
| 1071 | " INTERSECT " . | ||||||||||||||||||||||||||||||||||||||||||||
| 1072 | $sql; | ||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | unshift @params, $type; | |||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | $self->{SQL} = $sql; | |||||||||||||||||||||||||||||||||||||||||||
| 1076 | # $sql =~ s/^SELECT DISTINCT/SELECT MIN/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | $sql = "SELECT MIN(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1081 | $self->{ID} = | ||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | $objectdbi->get_dbh()->selectrow_array($sql, undef, @params); | |||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | my $result = $self->{OBJECTDBI}->get($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1092 | 0 | $sql .= " AND TABLE1.obj_gpid > $self->{ID}"; | |||||||||||||||||||||||||||||||||||||||||||
| 1093 | # $sql =~ s/^SELECT DISTINCT/SELECT MIN/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | $sql = "SELECT MIN(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 0 | $self->{ID} = $self->{OBJECTDBI}->get_dbh()->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 1100 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||||||||||||
| 1104 | =head2 B<my $err = $cursor-E<gt>skip($amount);> | ||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||
| 1106 | or | ||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||
| 1108 | =head2 B<my $err = $cursor-E<gt>skip_forward($amount);> | ||||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||||
| 1110 | Skips this many places in the cursor. | ||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||
| 1112 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | sub skip { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | return $self->skip_forward(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | sub skip_forward { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip_forward: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | my $amount = int(shift(@_)); | |||||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1125 | # $sql =~ s/^SELECT DISTINCT/SELECT MIN/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | $sql .= " AND TABLE1.obj_gpid > $self->{ID}"; | |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | $sql = " SELECT obj_gpid FROM ($sql) FOO ORDER BY obj_gpid ASC"; | |||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||
| 1129 | ## POSTGRES SPECIFIC | ||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | $sql .= " LIMIT $amount"; | |||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | my $ids = $self->{OBJECTDBI}->get_dbh()->selectcol_arrayref( | |||||||||||||||||||||||||||||||||||||||||||
| 1136 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 1137 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | $self->{ID} = $ids->[ $amount - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||
| 1140 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||
| 1142 | =head2 B<my $err = $cursor-E<gt>skip_backward($amount);> | ||||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||||
| 1144 | Skips this many places in the cursor in the opposite direction. | ||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||
| 1146 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | ▶ | sub skip_backward { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip_backward: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | my $amount = int(shift(@_)); | |||||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | # $sql =~ s/^SELECT DISTINCT/SELECT MAX/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | $sql .= " AND TABLE1.obj_gpid < $self->{ID}"; | |||||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | $sql = " SELECT obj_gpid FROM ($sql) FOO ORDER BY obj_gpid DESC"; | |||||||||||||||||||||||||||||||||||||||||||
| 1157 | # $sql .= " ORDER BY TABLE1.obj_gpid DESC"; | ||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||
| 1159 | ## POSTGRES SPECIFIC | ||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 0 | $sql .= " LIMIT $amount"; | |||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $ids = $self->{OBJECTDBI}->get_dbh()->selectcol_arrayref( | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 1167 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | $self->{ID} = $ids->[ $amount - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||||
| 1172 | =head2 B<my $err = $cursor-E<gt>first();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||||
| 1174 | Move to the first possible position of the cursor. | ||||||||||||||||||||||||||||||||||||||||||||
| 1175 | Doesn't need to be called when your previous call is $cursor->new(), | ||||||||||||||||||||||||||||||||||||||||||||
| 1176 | because a new cursor is always at its first possible position. | ||||||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||||
| 1178 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | ▶ | sub first { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | $sql = "SELECT MIN(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1185 | # $sql =~ s/^SELECT DISTINCT/SELECT MIN/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1189 | $self->{ID} = | ||||||||||||||||||||||||||||||||||||||||||||
| 1190 | $self->{OBJECTDBI}->get_dbh()->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | $sql, undef, @{$self->{PARAMS}} | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||||
| 1196 | =head2 B<my $err = $cursor-E<gt>last();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||||
| 1198 | Move to the last possible position of the cursor. | ||||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||||
| 1200 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | ▶ | sub last { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1206 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | # $sql =~ s/^SELECT DISTINCT/SELECT MAX/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | $sql = "SELECT MAX(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1212 | $self->{ID} = | ||||||||||||||||||||||||||||||||||||||||||||
| 1213 | $self->{OBJECTDBI}->get_dbh()->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | $sql, undef, @{$self->{PARAMS}} | |||||||||||||||||||||||||||||||||||||||||||
| 1215 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||||
| 1219 | =head2 B<my $ref = $cursor-E<gt>next();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||||
| 1221 | Move to the next position of the cursor. Returns the object at the current | ||||||||||||||||||||||||||||||||||||||||||||
| 1222 | position. | ||||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||||
| 1224 | =head2 B<my $ref = $cursor-E<gt>prev();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||||
| 1226 | Move to the previous position of the cursor. Returns the object at the current | ||||||||||||||||||||||||||||||||||||||||||||
| 1227 | position. | ||||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||||
| 1229 | =head2 B<my $ref = $cursor-E<gt>current();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||
| 1231 | Returns the object at the current position. | ||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||
| 1233 | =head2 B<my ($name, $type, $id) = $cursor-E<gt>meta_data();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||
| 1235 | Returns the meta data (name, type, id) of the object at the current position. | ||||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||||
| 1237 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 0 | ▶ | sub prev { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prev: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | my $result = $self->{OBJECTDBI}->get($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1245 | 0 | $sql .= " AND TABLE1.obj_gpid < $self->{ID}"; | |||||||||||||||||||||||||||||||||||||||||||
| 1246 | # $sql =~ s/^SELECT DISTINCT/SELECT MAX/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1247 | 0 | $sql = "SELECT MAX(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 0 | $self->{ID} = $self->{OBJECTDBI}->get_dbh()->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||
| 1252 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 1253 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 0 | ▶ | sub current { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 0 | my $result = $self->{OBJECTDBI}->get($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 1262 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | ▶ | sub meta_data { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 0 | return $self->{OBJECTDBI}->__object_get_meta($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||
| 1270 | =head2 B<my $ref = $cursor-E<gt>del();> | ||||||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||||
| 1272 | Deletes the current element under the cursor and moves to cursor one up. | ||||||||||||||||||||||||||||||||||||||||||||
| 1273 | A small concurrency warning is in order here: when two conncurrent users use | ||||||||||||||||||||||||||||||||||||||||||||
| 1274 | cursors, and one of them start to manipulate the state of the db, the other | ||||||||||||||||||||||||||||||||||||||||||||
| 1275 | one *might* risk suddenly dropping out of it. | ||||||||||||||||||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||||||||||||||||||
| 1277 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | ▶ | sub del { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | ▶ | return undef if (!defined($self->{ID})); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | my $result = $self->{OBJECTDBI}->get($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | $self->{OBJECTDBI}->__del($self->{ID}); | |||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | my @params = @{$self->{PARAMS}}; | |||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | my $sql = $self->{SQL}; | |||||||||||||||||||||||||||||||||||||||||||
| 1286 | 0 | $sql .= " AND TABLE1.obj_gpid > $self->{ID}"; | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | $sql = "SELECT MIN(obj_gpid) FROM ($sql) FOO"; | |||||||||||||||||||||||||||||||||||||||||||
| 1288 | # $sql =~ s/^SELECT DISTINCT/SELECT MIN/; | ||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | ▶ | if ($self->{OBJECTDBI}{debug}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | print STDERR "SQL: '$sql' with params: '" . join("', '", @params) . "'\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 1291 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | $self->{ID} = $self->{OBJECTDBI}->get_dbh()->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||
| 1293 | $sql, undef, @params | ||||||||||||||||||||||||||||||||||||||||||||
| 1294 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||||||||||||||||||
| 1300 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||