| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## SQL API Abstraction - ~/lib/DB/Object/Mysql/Tables.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Version v1.1.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Copyright(c) 2026 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 separate the object of the tables from the main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ## DB::Object package so that when they get DESTROY'ed, it does not interrupt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ## the SQL connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | package DB::Object::Mysql::Tables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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::Tables ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use vars qw( $VERSION $DEBUG $TYPE_TO_CONSTANT ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # <https://dev.mysql.com/doc/refman/8.0/en/data-types.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # the 'constant' property in the dictionary hash is added in structure() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # See also: SELECT DISTINCT(data_type) FROM information_schema.columns ORDER by data_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # but this does not provide a complete list of datatype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | our $TYPE_TO_CONSTANT = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | qr/^(bit)/ => { constant => '', name => 'SQL_BIT', type => 'bit' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | qr/^(tinyint)/ => { constant => '', name => 'SQL_TINYINT', type => 'tinyint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | qr/^(smallint)/ => { constant => '', name => 'SQL_SMALLINT', type => 'smallint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | qr/^(mediumint)/ => { constant => '', name => 'SQL_BIT', type => 'mediumint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | qr/^(integer|int)/ => { constant => '', name => 'SQL_INTEGER', type => 'int' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | qr/^(bigint)/ => { constant => '', name => 'SQL_BIGINT', type => 'bigint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | qr/^(dec|decimal)/ => { constant => '', name => 'SQL_DECIMAL', type => 'decimal' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | qr/^(float)/ => { constant => '', name => 'SQL_FLOAT', type => 'float' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | qr/^(double\s+precision|double)/ => { constant => '', name => 'SQL_DOUBLE', type => 'double' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | qr/^(date)\b/ => { constant => '', name => 'SQL_DATE', type => 'date' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | qr/^(datetime)/ => { constant => '', name => 'SQL_DATETIME', type => 'datetime' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | qr/^(timestamp)/ => { constant => '', name => 'SQL_TIMESTAMP', type => 'timestamp' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | qr/^(year)/ => { constant => '', name => 'SQL_INTERVAL_YEAR', type => 'year' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | qr/^(character|char)\b(?![[:blank:]]+varying)/ => { constant => '', name => 'SQL_VARCHAR', type => 'varchar' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | qr/^(character varying|varchar)/ => { constant => '', name => 'SQL_WVARCHAR', type => 'varchar' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | qr/^blob/ => { constant => '', name => 'SQL_BLOB', type => 'blob' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | qr/^text/ => { constant => '', name => 'SQL_LONGVARCHAR', type => 'text' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | qr/^binary/ => { constant => '', name => 'SQL_BINARY', type => 'binary' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | qr/^varbinary/ => { constant => '', name => 'SQL_VARBINARY', type => 'varbinary' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | qr/^(tinyblob)\b/ => { constant => '', name => 'SQL_BLOB', type => 'tinyblob' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | qr/^(mediumblob)\b/ => { constant => '', name => 'SQL_BLOB', type => 'mediumblob' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | qr/^(longlob)\b/ => { constant => '', name => 'SQL_BLOB', type => 'longlob' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | qr/^(tinytext)\b/ => { constant => '', name => 'SQL_LONGVARCHAR', type => 'tinytext' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | qr/^(mediumtext)\b/ => { constant => '', name => 'SQL_LONGVARCHAR', type => 'mediumtext' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | qr/^(longtext)\b/ => { constant => '', name => 'SQL_LONGVARCHAR', type => 'longtext' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | qr/^(enum)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'enum' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | qr/^(set)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'set' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | qr/^(geometry)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'geometry' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | qr/^(linestring)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'linestring' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | qr/^(point)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'point' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | qr/^(polygon)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'polygon' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | qr/^(curve)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'curve' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | qr/^(multipolygon)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'multipolygon' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | qr/^(multilinestring)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'multilinestring' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | qr/^(multipoint)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'multipoint' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | qr/^(geometrycollection)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'geometrycollection' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | qr/^(multicurve)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'multicurve' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | qr/^(json)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'json' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | our $VERSION = 'v1.1.2'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return( shift->DB::Object::Tables::init( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # NOTE] sub alter is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # sub alter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return( $self->error( 'No table was provided to check' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to check'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to check'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $opt = shift( @_ ) if( @_ == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my %arg = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $opt = \%arg if( !$opt && %arg ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $opt and %arg
MC/DC0%0/2
not $opt and %arg
not $opt
%arg
Truth table0%0/3
not(A) and B
A= not $optB= %arg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $query = "CHECK TABLE $table"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $query .= " TYPE = QUICK" if( $opt->{ 'quick' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to check table '${table}':\n$query\n", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to check table '${table}':\n$query\n", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | return( $self->error( "Error while preparing query to check table '$table':\n$query\n", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | return( $self->error( "Error while executing query to check table '$table':\n$query\n", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub create | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # $tbl->create( [ 'ROW 1', 'ROW 2'... ], { 'temporary' => 1, 'TYPE' => ISAM }, $obj ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $data = shift( @_ ) || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || []
MC/DC0%0/1
shift @_ || []
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $opt = shift( @_ ) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || {}
MC/DC0%0/1
shift @_ || {}
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $sth = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $table = $self->{table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # Set temporary in the object, so we can use it to recreate the table creation info as string: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # $table->create( [ ... ], { ... }, $obj )->as_string(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $temp = $self->{temporary} = delete( $opt->{temporary} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Check possible options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $allowed = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | type => qr/^(ISAM|MYISAM|HEAP)$/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | auto_increment => qr/^(1|0)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | avg_row_length => qr/^\d+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | checksum => qr/^(1|0)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | comment => qr//, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | max_rows => qr/^\d+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | min_rows => qr/^\d+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | pack_keys => qr/^(1|0)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | password => qr//, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | delay_key_write => qr/^\d+$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | row_format => qr/^(default|dynamic|static|compressed)$/i, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | raid_type => qr/^(?:1|STRIPED|RAID0|RAID_CHUNKS\s*=\s*\d+|RAID_CHUNKSIZE\s*=\s*\d+)$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my @options = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my @errors = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Avoid working for nothing, make this condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if( %$opt ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my %lc_opt = map{ lc( $_ ) => $opt->{ $_ } } keys( %$opt ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $opt = \%lc_opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | foreach my $key ( keys( %$opt ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | next if( $opt->{ $key } =~ /^\s*$/ || !exists( $allowed->{ $key } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{$key} =~ /^\s*$/ or not exists $allowed->{$key}
MC/DC0%0/2
$opt->{$key} =~ /^\s*$/ or not exists $allowed->{$key}
$opt->{$key} =~ /^\s*$/
not exists $allowed->{$key}
Truth table0%0/3
A or not(B)
A= $opt->{$key} =~ /^\s*$/B= not exists $allowed->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if( $opt->{ $key } !~ /$allowed->{ $key }/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | push( @errors, $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | push( @options, $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $opt->{comment} = "'" . quotemeta( $opt->{comment} ) . "'" if( exists( $opt->{comment} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $opt->{password} = "'" . $opt->{password} . "'" if( exists( $opt->{password} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if( @errors ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | warn( "The options '", join( ', ', @errors ), "' were either not recognized or malformed and thus were ignored." ) if( $self->_is_warnings_enabled( 'DB::Object' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # Check statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $select = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if( $sth && ref( $sth ) && ( $sth->isa( "DB::Object::Statement" ) || $sth->can( 'as_string' ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$sth and ref $sth and $sth->isa("DB::Object::Statement") || $sth->can("as_string")
$sth and ref $sth
$sth->isa("DB::Object::Statement") or $sth->can("as_string")
MC/DC0%0/4
$sth and ref $sth and $sth->isa("DB::Object::Statement") || $sth->can("as_string")
$sth
ref $sth
$sth->isa("DB::Object::Statement")
$sth->can("as_string")
Truth table0%0/5
A and B and C or D
A= $sthB= ref $sthC= $sth->isa("DB::Object::Statement")D= $sth->can("as_string")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $select = $sth->as_string(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if( $select !~ /^\s*(?:IGNORE|REPLACE)*\s*\bSELECT\s+/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return( $self->error( "SELECT statement to use to create table is invalid:\n$select" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if( $self->exists() == 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $query = 'CREATE ' . ( $temp ? 'TEMPORARY ' : '' ) . "TABLE $table "; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Structure of table if any - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # structure may very well be provided using a select statement, such as: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # CREATE TEMPORARY TABLE ploppy TYPE=HEAP COMMENT='this is kewl' MAX_ROWS=10 SELECT * FROM some_table LIMIT 0,0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $def = "(\n" . CORE::join( ",\n", @$data ) . "\n)" if( $data && ref( $data ) && @$data ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$data and ref $data and @$data
$data and ref $data
MC/DC0%0/3
$data and ref $data and @$data
$data
ref $data
@$data
Truth table0%0/4
A and B and C
A= $dataB= ref $dataC= @$data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $tdef = CORE::join( ' ', map{ "\U$_\E = $opt->{ $_ }" } @options ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if( !$def && !$select ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$def or $select
MC/DC0%0/2
$def or $select
$def
$select
Truth table0%0/3
A or B
A= $defB= $select
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return( $self->error( "Lacking table '$table' structure information to create it." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $query .= join( ' ', $def, $tdef, $select ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $new = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to create table '${table}':\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to create table '${table}':\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | return( $self->error( "Error while preparing query to create table '$table':\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Trick so other method may follow, such as as_string(), fetchrow(), rows() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # print( STDERR "create(): wantarrays in void context.\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $new->execute || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | return( $self->error( "Error while executing query to create table '$table':\n$query", $new->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->reset_structure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return( $self->error( "Table '$table' already exists." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub create_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_info: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $table = $self->{table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $self->structure || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $struct = $self->{structure}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $fields = $self->{fields}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $default = $self->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $primary = $self->{primary}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my @output = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | foreach my $field ( sort{ $fields->{ $a } <=> $fields->{ $b } } keys( %$fields ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | push( @output, "$field $struct->{ $field }" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | push( @output, "PRIMARY KEY(" . CORE::join( ',', @$primary ) . ")" ) if( $primary && @$primary ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$primary and @$primary
MC/DC0%0/2
$primary and @$primary
$primary
@$primary
Truth table0%0/3
A and B
A= $primaryB= @$primary
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $info = $self->stat( $table ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my @opt = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | push( @opt, "TYPE = $info->{type}" ) if( $info->{type} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $addons = $info->{create_options}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if( $addons ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $addons =~ s/(\A|\s+)([\w\_]+)\s*=\s*/$1\U$2\E=/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | push( @opt, $addons ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | push( @opt, "COMMENT='" . quotemeta( $info->{ 'comment' } ) . "'" ) if( $info->{comment} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $str = "CREATE TABLE $table (\n\t" . CORE::join( ",\n\t", @output ) . "\n)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $str .= ' ' . CORE::join( ' ', @opt ) if( @opt ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $str .= ';'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return( @output ? $str : undef() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # NOTE: sub default is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # sub default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sub drop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return( $self->error( "No table was provided to drop." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to drop.'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to drop.'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $query = "DROP TABLE $table"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to drop table '${table}':\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to drop table '${table}':\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | return( $self->error( "Error while preparing query to drop table '$table':\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $sth->execute || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | return( $self->error( "Error while executing query to drop table '$table':\n$query", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->reset_structure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # NOTE: exists is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | sub lock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # There is two arguments, the first one does not look like an exiting table name and the second is a number... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # It pretty much looks like a statement lock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if( @_ == 2 && ( !$self->exists( $_[ 0 ] ) || $_[ 1 ] =~ /^\d+$/ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@_ == 2 and !$self->exists($_[0]) || $_[1] =~ /^\d+$/
not $self->exists($_[0]) or $_[1] =~ /^\d+$/
MC/DC0%0/3
@_ == 2 and !$self->exists($_[0]) || $_[1] =~ /^\d+$/
@_ == 2
not $self->exists($_[0])
$_[1] =~ /^\d+$/
Truth table0%0/4
A and not(B) or C
A= @_ == 2B= not $self->exists($_[0])C= $_[1] =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | return( $self->SUPER::lock( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my @tables = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | my $chk_opt = sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $table = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $opt = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $alias = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if( $opt !~ /^(READ|READ\s+LOCAL|(LOW_PRIORITY\s+)?WRITE)$/i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return( $self->error( "Bad table '$table' locking option '$opt'." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if( $alias ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if( $self->_simple_exist( $alias ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return( $self->error( "Alias '$alias' for table '$table' seems to match an already existing table." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif( $alias !~ /^[\w\_]+$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return( $self->error( "Illegal characters for table '$table' alias name '$alias'." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return( 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # No parameter, so we default to WRITE for read/write access, but with a low priority | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if( !@_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | push( @tables, "$self->{table} LOW_PRIORITY WRITE" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | elsif( @_ == 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $arg = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $alias = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $opt = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Array reference means 'table alias', 'access mode' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if( $self->_is_array( $arg ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ( $alias, $opt ) = @$arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Otherwise just 'access mode' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $opt = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $opt ||= 'LOW_PRIORITY WRITE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt ||= "LOW_PRIORITY WRITE"
MC/DC0%0/1
$opt ||= "LOW_PRIORITY WRITE"
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | $chk_opt->( $self, $self->{table}, $opt, $alias ) || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my @lck = ( $self->{table} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | push( @lck, "AS $alias" ) if( $alias ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | push( @lck, uc( $opt ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | push( @tables, CORE::join( ' ', @lck ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my %arg = ( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my( $tbl, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | while( ( $tbl, $value ) = each( %arg ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my( $alias, $opt ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if( !$value ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $opt = 'LOW_PRIORITY WRITE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | elsif( ref( $value ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ( $alias, $opt ) = @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $opt = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $opt ||= 'LOW_PRIORITY WRITE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt ||= "LOW_PRIORITY WRITE"
MC/DC0%0/1
$opt ||= "LOW_PRIORITY WRITE"
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | $chk_opt->( $self, $tbl, $opt, $alias ) || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my @lck = ( $tbl ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | push( @lck, "AS $alias" ) if( $alias ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | push( @lck, uc( $opt ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | push( @tables, CORE::join( ' ', @lck ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $query = 'LOCK TABLES ' . CORE::join( ', ', @tables ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to do tables locking:\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to do tables locking:\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | return( $self->error( "Error while preparing query to do tables locking:\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | $sth->execute || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | return( $self->error( "Error while executing query to do tables locking:\n$query", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # NOTE: sub name is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # sub name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # NOTE: sub null is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # sub null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | sub on_conflict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_conflict: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $q = $self->_reset_query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # Void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | return( $q->on_conflict( @_ ) ) if( !defined( wantarray() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if( wantarray() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my( @val ) = $q->on_conflict( @_ ) || return( $self->pass_error( $q->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$q->on_conflict(@_) || (return $self->pass_error($q->error))
MC/DC0%0/1
$q->on_conflict(@_) || (return $self->pass_error($q->error))
$q->on_conflict(@_)
Truth table0%0/2
A
A= $q->on_conflict(@_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return( @val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $val = $q->on_conflict( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | return( $self->pass_error( $q->error ) ) if( !defined( $val ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return( $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | sub optimize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optimize: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | return( $self->error( 'No table was provided to optmize' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to optmize'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to optmize'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | return( $self->error( "Table '$table' does not exist." ) ) if( !$self->exists( $table ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $query = "OPTIMIZE TABLE $table"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to optimize table '${table}':\n$query\n", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to optimize table '${table}':\n$query\n", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | return( $self->error( "Error while preparing query to optimize table '$table':\n$query\n", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | return( $self->error( "Error while executing query to optimize table '$table':\n$query\n", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # NOTE: sub primary is inherited from DB::Object::Tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # sub primary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | sub qualified_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qualified_name: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my @val = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | my $dbo = $self->database_object || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | return( $self->error( "No database handle could be found." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | CORE::push( @val, $dbo->database ) if( $self->{prefixed} > 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | CORE::push( @val, $self->name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return( CORE::join( '.', @val ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | sub rename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | return( $self->error( 'No table was provided to rename' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to rename'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to rename'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $new = shift( @_ ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error("No new table name was provided to rename table '${table}'."))
MC/DC0%0/1
shift @_ || (return $self->error("No new table name was provided to rename table '${table}'."))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | return( $self->error( "No new table name was provided to rename table '$table'." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if( $new !~ /^[\w\_]+$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | return( $self->error( "Bad new table name '$new'." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $query = "ALTER TABLE $table RENAME TO $new"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to rename table '${table}' into '${new}':\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to rename table '${table}' into '${new}':\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | return( $self->error( "Error while preparing query to rename table '$table' into '$new':\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | return( $self->error( "Error while executing query to rename table '$table' into '$new':\n$query", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $self->reset_structure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | sub repair | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repair: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | return( $self->error( 'No table was provided to repair' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table was provided to repair'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table was provided to repair'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | return( $self->error( "Table '$table' does not exist." ) ) if( !$self->exists( $table ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $query = "REPAIR TABLE $table"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | $query .= ' TYPE = QUICK' if( $opts->{quick} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to repair table '${table}':\n$query\n", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to repair table '${table}':\n$query\n", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | return( $self->error( "Error while preparing query to repair table '$table':\n$query\n", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | return( $self->error( "Error while executing query to repair table '$table':\n$query\n", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | sub stat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # If no $table argument is provided, we will stat all tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $table = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $db = $self->{database}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | my $query = $table ? "SHOW TABLE STATUS FROM $db LIKE '$table'" : "SHOW TABLE STATUS FROM $db"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->prepare($query) || (return $self->error('Error while preparing query to get the status of table', $table ? " '${table}'" : 's', ":\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error('Error while preparing query to get the status of table', $table ? " '${table}'" : 's', ":\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | return( $self->error( "Error while preparing query to get the status of table", ( $table ? " '$table'" : 's' ), ":\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | $sth->execute || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | return( $self->error( "Error while executing query to get the status of table", ( $table ? " '$table'" : 's' ), ":\n$query", $sth->errstr ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $tables = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my $ref = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | while( $ref = $sth->fetchrow_hashref() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my %data = map{ lc( $_ ) => $ref->{ $_ } } keys( %$ref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $name = $data{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # map{ $tables->{ $name }->{ $_ } = $data{ $_ } } keys( %data ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $tables->{ $name } = \%data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | return( wantarray() ? () : undef() ) if( !%$tables ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | return( wantarray() ? %{ $tables->{ $table } } : $tables->{ $table } ) if( $table && exists( $tables->{ $table } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$table and exists $tables->{$table}
MC/DC0%0/2
$table and exists $tables->{$table}
$table
exists $tables->{$table}
Truth table0%0/3
A and B
A= $tableB= exists $tables->{$table}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | return( wantarray() ? %$tables : $tables ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # TODO: Must implement a cache mechanism for DB::Object::Mysql::structure() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | sub structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
structure: not called CC=44 SCAR=75.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | return( $self->_clone( $self->{_cache_structure} ) ) if( $self->{_cache_structure} && !CORE::length( $self->{_reset_structure} // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$self->{"_cache_structure"} and not length($self->{"_reset_structure"} // "")
$self->{"_reset_structure"} // ""
MC/DC0%0/2
$self->{"_cache_structure"} and not length($self->{"_reset_structure"} // "")
$self->{"_cache_structure"}
$self->{"_reset_structure"}
Truth table0%0/3
A and not(B)
A= $self->{"_cache_structure"}B= $self->{"_reset_structure"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $struct = $self->{structure}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $fields = $self->{fields}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | my $dbo = $self->database_object || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | return( $self->error( "No database handle could be found." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $types_dict = $dbo->datatype_dict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | $self->_load_class( 'DB::Object::Fields::Field' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my $q = $self->_reset_query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | my $table = $self->{table} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | return( $self->error( "No table provided to get its structure." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || (return $self->error('No table provided to get its structure.'))
MC/DC0%0/1
$self->{'table'} || (return $self->error('No table provided to get its structure.'))
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | my $sth1 = $dbo->prepare_cached( "SELECT * FROM information_schema.tables WHERE table_name = ?" ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbo->prepare_cached('SELECT * FROM information_schema.tables WHERE table_name = ?') || (return $self->error(qq[An error occured while preparing the sql query to get the details of table "$table": ], $dbo->errstr))
MC/DC0%0/1
$dbo->prepare_cached('SELECT * FROM information_schema.tables WHERE table_name = ?') || (return $self->error(qq[An error occured while preparing the sql query to get the details of table "$table": ], $dbo->errstr))
$dbo->prepare_cached('SELECT * FROM information_schema.tables WHERE table_name = ?')
Truth table0%0/2
A
A= $dbo->prepare_cached('SELECT * FROM information_schema.tables WHERE table_name = ?')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | return( $self->error( "An error occured while preparing the sql query to get the details of table \"$table\": ", $dbo->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $sth1->execute( $table ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | return( $self->error( "An error occured while executing the sql query to get the details of table \"$table\": ", $sth1->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my $def = $sth1->fetchrow_hashref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $sth1->finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if( scalar( keys( %$def ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # Ensure all fields are in lower case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | foreach my $k ( keys( %$def ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # For example: AUTO_INCREMENT -> auto_increment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $def->{ lc( $k ) } = CORE::delete( $def->{ $k } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $self->{type} = lc( $def->{table_type} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | $self->{type} = 'table' if( $self->{type} eq 'base table' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | warn( "No information found for table ${table}\n" ) if( $self->_is_warnings_enabled( 'DB::Object' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # <https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $query = <<EOT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | SELECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | a.column_name AS "field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ,a.ordinal_position AS "field_num" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ,a.column_default AS "default" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | ,a.* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | FROM information_schema.columns a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | WHERE table_name = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | ORDER BY a.ordinal_position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | my $sth = $dbo->prepare_cached( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbo->prepare_cached($query) || (return $self->error("Error while preparing query to get table '${table}' columns specification: ", $dbo->errstr))
MC/DC0%0/1
$dbo->prepare_cached($query) || (return $self->error("Error while preparing query to get table '${table}' columns specification: ", $dbo->errstr))
$dbo->prepare_cached($query)
Truth table0%0/2
A
A= $dbo->prepare_cached($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | return( $self->error( "Error while preparing query to get table '$table' columns specification: ", $dbo->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | $sth->execute( $table ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | return( $self->error( "Error while executing query to get table '$table' columns specification: ", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my @primary = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $ref = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | while( $ref = $sth->fetchrow_hashref() ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # Ensure all fields are in lower case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | foreach my $k ( keys( %$ref ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # For example: ORDINAL_POSITION -> ordinal_position | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $ref->{ lc( $k ) } = CORE::delete( $ref->{ $k } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | my $def = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | name => $ref->{field}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | ( CORE::length( $ref->{column_comment} // '' ) ? ( comment => $ref->{column_comment} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | default => $ref->{column_default}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # Damn MySQL not using boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | is_nullable => ( $ref->{is_nullable} eq 'YES' ? 1 : 0 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | is_primary => ( ( $ref->{column_key} // '' ) eq 'PRI' ? 1 : 0 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | is_unique => ( ( $ref->{column_key} // '' ) eq 'UNI' ? 1 : 0 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | pos => $ref->{field_num}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # query_object => $q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | size => $ref->{character_maximum_length}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | type => $ref->{data_type}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # table_object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/6
$ref->{"column_comment"} // ""
$ref->{"column_key"} // ""
$ref->{"column_key"} // ""
MC/DC0%0/1
$ref->{"column_comment"} // ""
$ref->{"column_comment"}
MC/DC0%0/1
$ref->{"column_key"} // ""
$ref->{"column_key"}
MC/DC0%0/1
$ref->{"column_key"} // ""
$ref->{"column_key"}
Truth table0%0/2
A
A= $ref->{"column_comment"}
Truth table0%0/2
A
A= $ref->{"column_key"}
Truth table0%0/2
A
A= $ref->{"column_key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my( $const_def, $dict ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | if( CORE::exists( $types_dict->{ $def->{type} } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $const_def = $types_dict->{ $def->{type} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # Get the constant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | DATA_TYPE_RE: foreach my $type ( keys( %$types_dict ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if( $def->{type} =~ /$types_dict->{ $type }->{re}/i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | $const_def = $types_dict->{ $type }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | last DATA_TYPE_RE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | if( defined( $const_def ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my $const_keys = [keys( %$const_def )]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | my $dict = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | @$dict{ @$const_keys } = @$const_def{ @$const_keys }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $def->{datatype} = $dict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $def->{query_object} = $q; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $def->{table_object} = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # The information schema field 'column_type' provides already what is needed, such as 'varchar(255)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my @define = ( $ref->{column_type} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | push( @define, "NOT NULL" ) if( !$def->{is_nullable} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # <https://stackoverflow.com/questions/68639745/how-to-get-a-default-column-value-from-mysql-5-7-information-schema-columns-with> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if( defined( $def->{default} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if( ( $ref->{data_type} eq 'datetime' || $ref->{data_type} eq 'timestamp' ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$ref->{"data_type"} eq "datetime" || $ref->{"data_type"} eq "timestamp" and $def->{"default"} eq "CURRENT_TIMESTAMP"
$ref->{"data_type"} eq "datetime" or $ref->{"data_type"} eq "timestamp"
MC/DC0%0/3
$ref->{"data_type"} eq "datetime" || $ref->{"data_type"} eq "timestamp" and $def->{"default"} eq "CURRENT_TIMESTAMP"
$ref->{"data_type"} eq "datetime"
$ref->{"data_type"} eq "timestamp"
$def->{"default"} eq "CURRENT_TIMESTAMP"
Truth table0%0/5
A or B and C
A= $ref->{"data_type"} eq "datetime"B= $ref->{"data_type"} eq "timestamp"C= $def->{"default"} eq "CURRENT_TIMESTAMP"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | $def->{default} eq 'CURRENT_TIMESTAMP' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $value = 'CURRENT_TIMESTAMP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | ▶ | elsif( !length( $def->{default} // '' ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$def->{"default"} // ""
MC/DC0%0/1
$def->{"default"} // ""
$def->{"default"}
Truth table0%0/2
A
A= $def->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $value = "''"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | $value = $dbo->quote( $def->{default}, ( CORE::length( $def->{datatype}->{constant} // '' ) ? $def->{datatype}->{constant} : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$def->{"datatype"}{"constant"} // ""
MC/DC0%0/1
$def->{"datatype"}{"constant"} // ""
$def->{"datatype"}{"constant"}
Truth table0%0/2
A
A= $def->{"datatype"}{"constant"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | push( @define, "DEFAULT ${value}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | push( @define, 'AUTO_INCREMENT' ) if( lc( $ref->{extra} // '' ) eq 'auto_increment' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ref->{"extra"} // ""
MC/DC0%0/1
$ref->{"extra"} // ""
$ref->{"extra"}
Truth table0%0/2
A
A= $ref->{"extra"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | if( defined( $ref->{extra} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ref->{"extra"} and $ref->{"extra"} =~ /^DEFAULT_GENERATED[[:blank:]]+(ON[[:blank:]]+UPDATE[[:blank:]]+.*)$/i
MC/DC0%0/2
defined $ref->{"extra"} and $ref->{"extra"} =~ /^DEFAULT_GENERATED[[:blank:]]+(ON[[:blank:]]+UPDATE[[:blank:]]+.*)$/i
defined $ref->{"extra"}
$ref->{"extra"} =~ /^DEFAULT_GENERATED[[:blank:]]+(ON[[:blank:]]+UPDATE[[:blank:]]+.*)$/i
Truth table0%0/3
A and B
A= defined $ref->{"extra"}B= $ref->{"extra"} =~ /^DEFAULT_GENERATED[[:blank:]]+(ON[[:blank:]]+UPDATE[[:blank:]]+.*)$/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | $ref->{extra} =~ /^DEFAULT_GENERATED[[:blank:]]+(ON[[:blank:]]+UPDATE[[:blank:]]+.*)$/i ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | push( @define, $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | push( @primary, $def->{name} ) if( $ref->{column_key} eq 'PRI' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $struct->{ $def->{name} } = CORE::join( ' ', @define ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | my $field = DB::Object::Fields::Field->new( %$def, debug => $self->debug ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'DB::Object::Fields::Field'->new(%$def, 'debug', $self->debug) || (return $self->pass_error('DB::Object::Fields::Field'->error))
MC/DC0%0/1
'DB::Object::Fields::Field'->new(%$def, 'debug', $self->debug) || (return $self->pass_error('DB::Object::Fields::Field'->error))
'DB::Object::Fields::Field'->new(%$def, 'debug', $self->debug)
Truth table0%0/2
A
A= 'DB::Object::Fields::Field'->new(%$def, 'debug', $self->debug)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | return( $self->pass_error( DB::Object::Fields::Field->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | $fields->{ $def->{name} } = $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | if( @primary ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $self->{primary} = \@primary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | $self->{fields} = $fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $self->{_cache_structure} = $struct; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return( $self->_clone( $struct ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | sub table_info { return( shift->database_object->table_info( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | sub unlock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | return( $self->CORE::unlock( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | my $query = 'UNLOCK TABLES'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | my $sth = $self->prepare( $query ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->prepare($query) || (return $self->error("Error while preparing query to unlock tables:\n$query", $self->errstr))
MC/DC0%0/1
$self->prepare($query) || (return $self->error("Error while preparing query to unlock tables:\n$query", $self->errstr))
$self->prepare($query)
Truth table0%0/2
A
A= $self->prepare($query)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | return( $self->error( "Error while preparing query to unlock tables:\n$query", $self->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if( !defined( wantarray() ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | $sth->execute() || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | return( $self->error( "Error while executing query to unlock tables:\n$query", $sth->errstr() ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | return( $sth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | DESTROY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # Do nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | # DB::Object::Tables are never destroyed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # They are just gateway to tables, and they are cached by DB::Object::table() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # print( STDERR "DESTROY'ing table $self ($self->{ 'table' })\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||