| 1 | package DBIO::MySQL::Identifier; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MySQL/MariaDB identifier quoting for generated DDL | ||||||||||||||||||||||||||||||||||||||||||
| 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 DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 88 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 88 | our @EXPORT_OK = qw(quote_ident check_table_name split_table_name quote_table quote_table_in); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2089 | ▶ | sub quote_ident { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_ident: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2089 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 2089 | $name =~ s/`/``/g; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 2089 | return "`$name`"; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 403 | ▶ | sub split_table_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_table_name: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 403 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 403 | ▶ | return (undef, $name) unless defined $name && !ref $name && $name =~ /\./; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $name and not ref $name and $name =~ /\./
defined $name and not ref $name
MC/DC33%1/3
defined $name and not ref $name and $name =~ /\./
defined $name
not ref $name
$name =~ /\./
Truth table50%2/4
A and not(B) and C
A= defined $nameB= not ref $nameC= $name =~ /\./
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 28 | my @parts = split /\./, $name, -1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 28 | ▶ | DBIO::Exception->throw("DBIO::MySQL: table '$name' is refused: a table name " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@parts == 2 and length $parts[0] and length $parts[1]
@parts == 2 and length $parts[0]
MC/DC100%3/3
@parts == 2 and length $parts[0] and length $parts[1]
@parts == 2
length $parts[0]
length $parts[1]
Truth table100%4/4
A and B and C
A= @parts == 2B= length $parts[0]C= length $parts[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | . 'is table or database.table, with both halves given and one dot') | ||||||||||||||||||||||||||||||||||||||||||
| 29 | unless @parts == 2 && length $parts[0] && length $parts[1]; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 25 | return @parts; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 169 | ▶ | sub quote_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_table: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 169 | my ($database, $table) = split_table_name($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 169 | ▶ | return defined $database ? quote_ident($database) . '.' . quote_ident($table) : quote_ident($table); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 314 | ▶ | sub quote_table_in { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_table_in: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 314 | my ($database, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 314 | ▶ | return defined $database ? quote_ident($database) . '.' . quote_ident($table) : quote_ident($table); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 192 | ▶ | sub check_table_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_table_name: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 192 | my ($name, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 192 | ▶ | return $name unless defined $name && !ref $name && $name =~ /\./; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $name and not ref $name and $name =~ /\./
defined $name and not ref $name
MC/DC33%1/3
defined $name and not ref $name and $name =~ /\./
defined $name
not ref $name
$name =~ /\./
Truth table50%2/4
A and not(B) and C
A= defined $nameB= not ref $nameC= $name =~ /\./
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 12 | ▶ | $kind //= 'table'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$kind //= "table"
MC/DC100%1/1
$kind //= "table"
$kind
Truth table100%2/2
A
A= $kind
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | ▶ | if ($kind ne 'table') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | DBIO::Exception->throw("DBIO::MySQL: $kind '$name' is refused: a name with a " | |||||||||||||||||||||||||||||||||||||||||
| 52 | . "dot means database.table to MySQL, and creating a $kind in another " | ||||||||||||||||||||||||||||||||||||||||||
| 53 | . "database is not supported. Name the $kind without a dot"); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 11 | split_table_name($name); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 88 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||||||||||||||||