| 1 | package DBIO::Firebird::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Shared Firebird-specific helper functions for DBIO | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 21 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 21 | our @EXPORT_OK = qw(mask_error_details); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # What stands in for a value in an error text. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 21 | my $MASK = '***'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # ("A" = 1, "B" = 'x') without the outer parentheses: the column names, kept, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # with the values replaced -- or undef when the text is not one reading. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 19 | ▶ | sub _mask_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_key: called CC=13 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 19 | my ($inner, $binds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 19 | ▶ | for my $bound (@{ $binds // [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$binds // []
MC/DC100%1/1
$binds // []
$binds
Truth table100%2/2
A
A= $binds
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | return undef if defined $bound && !ref $bound && $bound =~ /, "|\)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $bound and not ref $bound and $bound =~ /, "|\)/
defined $bound and not ref $bound
MC/DC33%1/3
defined $bound and not ref $bound and $bound =~ /, "|\)/
defined $bound
not ref $bound
$bound =~ /, "|\)/
Truth table50%2/4
A and not(B) and C
A= defined $boundB= not ref $boundC= $bound =~ /, "|\)/
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # The server does not escape a quote in a value, so a value holding | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # `" = ` would be read as one column more. The number of `" = ` must be the | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # number of columns found. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 18 | my $equals = () = $inner =~ /" = /g; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 18 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 18 | my $rest = $inner; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 18 | ▶ | while (length $rest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | $rest =~ s/\A"((?:[^"]|"")+)" = // | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 25 | push @names, $1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | # The value reaches to the next `, "NAME" = ` or to the end (lazy). | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | ▶ | $rest =~ s/\A.*?(?=, "(?:[^"]|"")+" = |\z)//s | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | ▶ | $rest =~ s/\A, // or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 18 | ▶ | return undef unless @names && @names == $equals && !length $rest; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@names and @names == $equals and not length $rest
@names and @names == $equals
MC/DC33%1/3
@names and @names == $equals and not length $rest
@names
@names == $equals
not length $rest
Truth table50%2/4
A and B and not(C)
A= @namesB= @names == $equalsC= not length $rest
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 17 | return join ', ', map { qq{"$_" = $MASK} } @names; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 58 | ▶ | sub mask_error_details { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask_error_details: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 58 | my ($text, $binds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 58 | ▶ | return $text unless defined $text && !ref $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and not ref $text
MC/DC50%1/2
defined $text and not ref $text
defined $text
not ref $text
Truth table66%2/3
A and not(B)
A= defined $textB= not ref $text
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # -Problematic key value is ("ID" = 1, "EMAIL" = 'x') | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 57 | $text =~ s{(Problematic key value is )(.*)\z}{ | |||||||||||||||||||||||||||||||||||||||||
| 54 | 24 | my ($head, $tail) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 24 | my $masked; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 24 | ▶ | if ($tail =~ /\A\((.*)\)\s*\z/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 19 | my $keys = _mask_key($1, $binds); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 19 | ▶ | $masked = "($keys)" if defined $keys; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 24 | ▶ | $head . (defined $masked ? $masked : $MASK) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | }se; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # -conversion error from string "geheimdate" | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 57 | $text =~ s/(conversion error from string )".*"/$1"$MASK"/s; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # validation error for column "T"."C", value "x" | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 57 | $text =~ s/(validation error for column [^\n]*?, value )"(.*)"/ | |||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | $2 eq '*** null ***' ? qq{$1"$2"} : qq{$1"$MASK"}/se; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 57 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||||||||||||||||