| 1 | package DBIO::MySQL::DefaultValue; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MySQL/MariaDB DEFAULT values for generated DDL, written and read | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 88 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 88 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 88 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 88 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 88 | our @EXPORT_OK = qw(default_sql catalog_default catalog_on_update on_update_sql); | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | # The spellings of "now" both servers take as a column default without | ||||||||||||||||||||||||||||||||
| 16 | # parentheses (and as ON UPDATE). | ||||||||||||||||||||||||||||||||
| 17 | 88 | my $NOW = qr/\A(?:current_timestamp|now|localtime|localtimestamp)(?:\(\s*\d*\s*\))?\z/i; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 34 | ▶ | sub default_sql { | ||||||||||||||||||||||||||||||
|
Subroutine
default_sql: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 34 | my ($value, $is_expression) = @_; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 34 | ▶ | return $$value if ref $value eq 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 31 | ▶ | if ($is_expression) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | 11 | ▶ | return $value =~ $NOW ? $value : "($value)"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 20 | (my $lit = $value) =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||
| 29 | 20 | $lit =~ s/'/''/g; | |||||||||||||||||||||||||||||||
| 30 | 20 | $lit =~ s/\0/\\0/g; | |||||||||||||||||||||||||||||||
| 31 | 20 | return "'$lit'"; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 78 | ▶ | sub catalog_default { | ||||||||||||||||||||||||||||||
|
Subroutine
catalog_default: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 36 | 78 | my (%a) = @_; | |||||||||||||||||||||||||||||||
| 37 | 78 | my $raw = $a{raw}; | |||||||||||||||||||||||||||||||
| 38 | 78 | ▶ | return (undef, 0) unless defined $raw; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 46 | ▶ | if ($a{mariadb_expression}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 23 | ▶ | if ($raw =~ /\A'(.*)'\z/s) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 12 | my $lit = $1; | |||||||||||||||||||||||||||||||
| 43 | 12 | my %esc = (n => "\n", r => "\r", t => "\t", 0 => "\0", Z => "\x1a", b => "\b"); | |||||||||||||||||||||||||||||||
| 44 | 12 | $lit =~ s/''/'/g; | |||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | $lit =~ s/\\(.)/exists $esc{$1} ? $esc{$1} : $1/gse; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 12 | return ($lit, 0); | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | 11 | ▶ | return ($raw, 0) if $raw =~ /\A[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\z/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 8 | return ($raw, 1); | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 23 | ▶ | if (($a{extra} // '') =~ /\bDEFAULT_GENERATED\b/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$a{"extra"} // ""
MC/DC0%0/1
$a{"extra"} // ""
$a{"extra"}
Truth table50%1/2
A
A= $a{"extra"}
| |||||||||||||||||||||||||||||||||
| 53 | 8 | (my $expr = $raw) =~ s/\\'/'/g; | |||||||||||||||||||||||||||||||
| 54 | 8 | return ($expr, 1); | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | return ($raw, 1) | ||||||||||||||||||||||||||||||||
| 58 | 15 | ▶ | if $raw =~ $NOW && ($a{data_type} // '') =~ /\A(?:timestamp|datetime)\z/i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$raw =~ /$NOW/ and ($a{"data_type"} // "") =~ /\A(?:timestamp|datetime)\z/i
$a{"data_type"} // ""
MC/DC50%1/2
$raw =~ /$NOW/ and ($a{"data_type"} // "") =~ /\A(?:timestamp|datetime)\z/i
$raw =~ /$NOW/
$a{"data_type"}
Truth table66%2/3
A and B
A= $raw =~ /$NOW/B= $a{"data_type"}
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 14 | return ($raw, 0); | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 78 | ▶ | sub catalog_on_update { | ||||||||||||||||||||||||||||||
|
Subroutine
catalog_on_update: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 65 | 78 | my ($extra) = @_; | |||||||||||||||||||||||||||||||
| 66 | 78 | ▶ | return undef unless defined $extra && $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $extra and $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
MC/DC50%1/2
defined $extra and $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
defined $extra
$extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
Truth table66%2/3
A and B
A= defined $extraB= $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
| |||||||||||||||||||||||||||||||||
| 67 | 6 | (my $expr = uc $1) =~ s/\s+//g; | |||||||||||||||||||||||||||||||
| 68 | 6 | $expr =~ s/\(\)\z//; | |||||||||||||||||||||||||||||||
| 69 | 6 | return $expr; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 192 | ▶ | sub on_update_sql { | ||||||||||||||||||||||||||||||
|
Subroutine
on_update_sql: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 74 | 192 | my ($on_update) = @_; | |||||||||||||||||||||||||||||||
| 75 | 192 | ▶ | return defined $on_update && length $on_update ? " ON UPDATE $on_update" : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_update and length $on_update
MC/DC50%1/2
defined $on_update and length $on_update
defined $on_update
length $on_update
Truth table66%2/3
A and B
A= defined $on_updateB= length $on_update
| |||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 88 | 1; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||||||