| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 3 | ## SQL API Abstraction - ~/lib/DB/Object/Mysql/Statement.pm | ||||||||||||||||||||||||||||
| 4 | ## Version v0.300.3 | ||||||||||||||||||||||||||||
| 5 | ## Copyright(c) 2024 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 6 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 7 | ## Created 2017/07/19 | ||||||||||||||||||||||||||||
| 8 | ## Modified 2026/10/01 | ||||||||||||||||||||||||||||
| 9 | ## All rights reserved | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | # This package's purpose is to automatically terminate the statement object and | ||||||||||||||||||||||||||||
| 15 | # separate them from the connection object (DB::Object). | ||||||||||||||||||||||||||||
| 16 | # Connection object last longer than statement objects | ||||||||||||||||||||||||||||
| 17 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 18 | package DB::Object::Mysql::Statement; | ||||||||||||||||||||||||||||
| 19 | BEGIN | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | warnings::register_categories( 'DB::Object' ); | |||||||||||||||||||||||||||
| 24 | 1 | ▶ | use parent qw( DB::Object::Statement ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use vars qw( $VERSION $DEBUG ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 27 | 1 | our $VERSION = 'v0.300.3'; | |||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 34 | # sub bind_param | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # sub commit is called by dbh, so it is in DB::Object::Postgres | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Customised for MySQL | ||||||||||||||||||||||||||||
| 39 | sub distinct | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
distinct: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 42 | my $query = $self->{query} || | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return( $self->error( "No query to set as to be ignored." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $type = uc( ( $query =~ /^\s*(\S+)\s+/ )[ 0 ] ); | |||||||||||||||||||||||||||
| 46 | # ALTER for table alteration statements (DB::Object::Tables | ||||||||||||||||||||||||||||
| 47 | 0 | my @allowed = qw( SELECT ); | |||||||||||||||||||||||||||
| 48 | 0 | my $allowed = CORE::join( '|', @allowed ); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if( !scalar( grep{ /^$type$/i } @allowed ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | return( $self->error( "You may not flag statement of type \U$type\E to be distinct:\n$query" ) ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | # Incompatible. Do not bother going further | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return( $self ) if( $query =~ /^[[:blank:]]*(?:$allowed)[[:blank:]]+(?:DISTINCT|DISTINCTROW|ALL)[[:blank:]]+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | $query =~ s/^([[:blank:]]*)($allowed)([[:blank:]]+)/$1$2 DISTINCT /; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $sth = $self->_cache_this( $query ) || | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
| |||||||||||||||||||||||||||||
| 58 | return( $self->error( "Error while preparing new ignored query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | return( $self->error( "Error while executing new ignored query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | return( $sth ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Customised for MySQL | ||||||||||||||||||||||||||||
| 68 | sub dump | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $args = @_ == 1 ? shift( @_ ) : { @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | my $vsep = ","; | |||||||||||||||||||||||||||
| 73 | 0 | my $hsep = "\n"; | |||||||||||||||||||||||||||
| 74 | 0 | my $width = 35; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | $self->_load_class( 'DateTime::Lite' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $self->_load_class( 'Module::Generic::File' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $fh = Module::Generic::File->stdout() || | ||||||||||||||||||||||||||
|
Condition0%0/2
'Module::Generic::File'->stdout || (return $self->pass_error('Module::Generic::File'->error))
MC/DC0%0/1
'Module::Generic::File'->stdout || (return $self->pass_error('Module::Generic::File'->error))
'Module::Generic::File'->stdout
Truth table0%0/2
A
A= 'Module::Generic::File'->stdout
| |||||||||||||||||||||||||||||
| 78 | return( $self->pass_error( Module::Generic::File->error ) ); | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $vsep = $args->{vsep} if( exists( $args->{vsep} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $hsep = $args->{hsep} if( exists( $args->{hsep} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $width = $args->{width} if( exists( $args->{width} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | my @fields = (); | |||||||||||||||||||||||||||
| 83 | # my @fields = @{$self->{sth}->FETCH( 'NAME' )}; | ||||||||||||||||||||||||||||
| 84 | 0 | my $fields_ref = $self->{sth}->{NAME}; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( defined( $fields_ref ) && ref( $fields_ref ) eq 'ARRAY' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $fields_ref and ref $fields_ref eq "ARRAY"
MC/DC0%0/2
defined $fields_ref and ref $fields_ref eq "ARRAY"
defined $fields_ref
ref $fields_ref eq "ARRAY"
Truth table0%0/3
A and B
A= defined $fields_refB= ref $fields_ref eq "ARRAY"
| |||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 0 | @fields = @$fields_ref; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | return( $self->error( "No array reference of fields could be retrieved from statement '$self->{sth}'." ) ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return( $self->error( "No query to dump." ) ) if( !exists( $self->{sth} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if( exists( $args->{file} ) ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | # new_file is inherited from Module::Generic and uses Module::Generic::File | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $file = $self->new_file( $args->{file} ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->new_file($args->{'file'}) || (return $self->pass_error)
MC/DC0%0/1
$self->new_file($args->{'file'}) || (return $self->pass_error)
$self->new_file($args->{'file'})
Truth table0%0/2
A
A= $self->new_file($args->{'file'})
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $fh = $file->open( '>', { binmode => 'utf8' }) || return( $self->error( "Unable to open file $file in write mode: $!" ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$file->open('>', {'binmode', 'utf8'}) || (return $self->error("Unable to open file $file in write mode: $!"))
MC/DC0%0/1
$file->open('>', {'binmode', 'utf8'}) || (return $self->error("Unable to open file $file in write mode: $!"))
$file->open('>', {'binmode', 'utf8'})
Truth table0%0/2
A
A= $file->open('>', {'binmode', 'utf8'})
| |||||||||||||||||||||||||||||
| 99 | 0 | my @header = sort{ $a <=> $b } @fields; | |||||||||||||||||||||||||||
| 100 | 0 | my $date = DateTime::Lite->now; | |||||||||||||||||||||||||||
| 101 | 0 | my $table = $self->{table}; | |||||||||||||||||||||||||||
| 102 | 0 | $fh->printf( "# Generated on %s for table $table\n", $date->strftime( '%c' ) ); | |||||||||||||||||||||||||||
| 103 | 0 | $fh->print( "# ", CORE::join( "\t", @header ), "\n" ); | |||||||||||||||||||||||||||
| 104 | 0 | my @data = (); | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | while( @data = $self->fetchrow() ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | 0 | $fh->print( CORE::join( "\t", @data ), "\n" ); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 0 | $fh->close(); | |||||||||||||||||||||||||||
| 110 | 0 | $self->finish(); | |||||||||||||||||||||||||||
| 111 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | elsif( exists( $args->{fh} ) ) | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if( !fileno( $args->{fh} ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 0 | return( $self->error( "The file descriptor provided does not seem to be valid (not open)" ) ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $fh = IO::File->new_from_fd( $args->{fh}, 'w' ) || return( $self->error( $! ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
'IO::File'->new_from_fd($args->{'fh'}, 'w') || (return $self->error($!))
MC/DC0%0/1
'IO::File'->new_from_fd($args->{'fh'}, 'w') || (return $self->error($!))
'IO::File'->new_from_fd($args->{'fh'}, 'w')
Truth table0%0/2
A
A= 'IO::File'->new_from_fd($args->{'fh'}, 'w')
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | my $max = 0; | |||||||||||||||||||||||||||
| 122 | # foreach my $field ( keys( %$fields ) ) | ||||||||||||||||||||||||||||
| 123 | 0 | foreach my $field ( @fields ) | |||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $max = length( $field ) if( length( $field ) > $max ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | my $template = ''; | |||||||||||||||||||||||||||
| 128 | # foreach my $field ( sort{ $fields->{ $a } <=> $fields->{ $b } } keys( %$fields ) ) | ||||||||||||||||||||||||||||
| 129 | 0 | foreach my $field ( @fields ) | |||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 0 | $template .= "$field" . ( '.' x ( $max - length( $field ) ) ) . ": %s\n"; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | $template .= "\n"; | |||||||||||||||||||||||||||
| 134 | 0 | my @data = (); | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | while( @data = $self->fetchrow() ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 0 | $fh->printf( $template, @data ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 0 | $self->finish(); | |||||||||||||||||||||||||||
| 140 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 144 | # sub execute | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 147 | # sub executed | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 150 | # sub fetchall_arrayref($@) | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 153 | # sub fetchcol($;$) | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 156 | # sub fetchhash(@) | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 159 | # sub fetchrow(@) | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 162 | # sub finish | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | sub ignore | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
ignore: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 167 | my $query = $self->{query} || | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return( $self->error( "No query to set as to be ignored." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
| |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my $type = uc( ( $query =~ /^[[:blank:]]*(\S+)[[:blank:]]+/ )[ 0 ] ); | |||||||||||||||||||||||||||
| 171 | # ALTER for table alteration statements (DB::Object::Tables | ||||||||||||||||||||||||||||
| 172 | 0 | my @allowed = qw( INSERT UPDATE ALTER ); | |||||||||||||||||||||||||||
| 173 | 0 | my $allowed = CORE::join( '|', @allowed ); | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | if( !scalar( grep{ /^$type$/i } @allowed ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||
| 176 | 0 | return( $self->error( "You may not flag statement of type \U$type\E to be ignored:\n$query" ) ); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | # Incompatible. Do not bother going further | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return( $self ) if( $query =~ /^[[:blank:]]*(?:$allowed)[[:blank:]]+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)[[:blank:]]+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return( $self ) if( $type eq 'ALTER' && $query !~ /^[[:blank:]]*$type[[:blank:]]+TABLE[[:blank:]]+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "ALTER" and not $query =~ /^[[:blank:]]*${type}[[:blank:]]+TABLE[[:blank:]]+/i
MC/DC0%0/2
$type eq "ALTER" and not $query =~ /^[[:blank:]]*${type}[[:blank:]]+TABLE[[:blank:]]+/i
$type eq "ALTER"
not $query =~ /^[[:blank:]]*${type}[[:blank:]]+TABLE[[:blank:]]+/i
Truth table0%0/3
A and not(B)
A= $type eq "ALTER"B= not $query =~ /^[[:blank:]]*${type}[[:blank:]]+TABLE[[:blank:]]+/i
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | $query =~ s/^([[:blank:]]*)($allowed)([[:blank:]]+)/$1$2 IGNORE /; | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $sth = $self->_cache_this( $query ) || | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
| |||||||||||||||||||||||||||||
| 184 | return( $self->error( "Error while preparing new ignored query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | return( $self->error( "Error while executing new ignored query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 0 | return( $sth ); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 194 | # sub join | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 197 | # sub object | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | sub only | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
only: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 201 | 0 | return( shift->error( "SELECT | DELETE | UPDATE ONLY is not supported by Mysql." ) ); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | sub priority | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
priority: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 206 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 207 | 0 | my $prio = shift( @_ ); | |||||||||||||||||||||||||||
| 208 | 0 | my $map = | |||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||
| 210 | 0 => 'LOW_PRIORITY', | ||||||||||||||||||||||||||||
| 211 | 1 => 'HIGH_PRIORITY', | ||||||||||||||||||||||||||||
| 212 | }; | ||||||||||||||||||||||||||||
| 213 | # Bad argument. Do not bother | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return( $self ) if( !exists( $map->{ $prio } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | my $query = $self->{query} || | ||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return( $self->error( "No query to set priority for was provided." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set priority for was provided.'))
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set priority for was provided.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
| |||||||||||||||||||||||||||||
| 218 | 0 | my $type = uc( ( $query =~ /^[[:blank:]]*(\S+)[[:blank:]]+/ )[ 0 ] ); | |||||||||||||||||||||||||||
| 219 | 0 | my @allowed = qw( DELETE INSERT REPLACE SELECT UPDATE ); | |||||||||||||||||||||||||||
| 220 | 0 | my $allowed = CORE::join( '|', @allowed ); | |||||||||||||||||||||||||||
| 221 | # Ignore if not allowed | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if( !scalar( grep{ /^$type$/i } @allowed ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||
| 224 | 0 | $self->error( "You may not set priority on statement of type \U$type\E:\n$query" ); | |||||||||||||||||||||||||||
| 225 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | # Incompatible. Do not bother going further | ||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return( $self ) if( $query =~ /^\s*(?:$allowed)\s+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)\s+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | # SELECT with something else than HIGH_PRIORITY is incompatible, so do not bother to go further | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | return( $self ) if( $prio != 1 && $type =~ /^(?:SELECT)$/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prio != 1 and $type =~ /^(?:SELECT)$/i
MC/DC0%0/2
$prio != 1 and $type =~ /^(?:SELECT)$/i
$prio != 1
$type =~ /^(?:SELECT)$/i
Truth table0%0/3
A and B
A= $prio != 1B= $type =~ /^(?:SELECT)$/i
| |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return( $self ) if( $prio != 0 && $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prio != 0 and $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
MC/DC0%0/2
$prio != 0 and $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
$prio != 0
$type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
Truth table0%0/3
A and B
A= $prio != 0B= $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | $query =~ s/^([[:blank:]]*)($allowed)([[:blank:]]+)/$1$2 $map->{ $prio } /i; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $sth = $self->_cache_this( $query ) || | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new low priority query:\n$query"))
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new low priority query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
| |||||||||||||||||||||||||||||
| 235 | return( $self->error( "Error while preparing new low priority query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||
| 238 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | return( $self->error( "Error while executing new low priority query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 0 | return( $sth ); | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # rollback is called using the dbh handler and is located in DB::Object::Postgres | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 247 | # sub rows(@) | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | # Inherited from DB::Object::Statement | ||||||||||||||||||||||||||||
| 250 | # sub undo | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | sub wait | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
wait: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 255 | my $query = $self->{query} || | ||||||||||||||||||||||||||||
| 256 | 0 | ▶ | return( $self->error( "No query to set as to be delayed." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set as to be delayed.'))
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set as to be delayed.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
| |||||||||||||||||||||||||||||
| 257 | 0 | my $type = ( $query =~ /^[[:blank:]]*(\S+)[[:blank:]]+/ )[ 0 ]; | |||||||||||||||||||||||||||
| 258 | 0 | my @allowed = qw( INSERT REPLACE ); | |||||||||||||||||||||||||||
| 259 | 0 | my $allowed = CORE::join( '|', @allowed ); | |||||||||||||||||||||||||||
| 260 | # Ignore if not allowed | ||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if( !scalar( grep{ /^$type$/i } @allowed ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||
| 263 | 0 | $self->error( "You may not use wait (delayed query) on statement of type \U$type\E:\n$query" ); | |||||||||||||||||||||||||||
| 264 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | # Incompatible. Do not bother going further | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | return( $self ) if( $query =~ /^[[:blank:]]*(?:$allowed)[[:blank:]]+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)[[:blank:]]+/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 0 | $query =~ s/^([[:blank:]]*)($allowed)([[:blank:]]+)/$1$2 DELAYED /i; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $sth = $self->_cache_this( $query ) || | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new delayed query:\n$query"))
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new delayed query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
| |||||||||||||||||||||||||||||
| 270 | return( $self->error( "Error while preparing new delayed query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | return( $self->error( "Error while executing new delayed query:\n$query" ) ); | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | 0 | return( $sth ); | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | DESTROY | ||||||||||||||||||||||||||||
| 280 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 281 | # Do nothing but existing so it is handled by this package | ||||||||||||||||||||||||||||
| 282 | # print( STDERR "DESTROY'ing statement $self ($self->{ 'query' })\n" ); | ||||||||||||||||||||||||||||
| 283 | }; | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 1 | 1; | |||||||||||||||||||||||||||
| 286 | # NOTE: POD | ||||||||||||||||||||||||||||
| 287 | __END__ | ||||||||||||||||||||||||||||