line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Composer::Quoter; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
14989
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
232
|
|
4
|
10
|
|
|
10
|
|
42
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
3539
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
88
|
|
|
88
|
0
|
18982
|
my $class = shift; |
8
|
88
|
|
|
|
|
266
|
my (%params) = @_; |
9
|
|
|
|
|
|
|
|
10
|
88
|
|
|
|
|
165
|
my $self = {}; |
11
|
88
|
|
|
|
|
158
|
bless $self, $class; |
12
|
|
|
|
|
|
|
|
13
|
88
|
|
100
|
|
|
449
|
$self->{quote_char} = $params{quote_char} ||= '`'; |
14
|
88
|
|
100
|
|
|
348
|
$self->{name_separator} = $params{name_separator} ||= '.'; |
15
|
88
|
|
50
|
|
|
328
|
$self->{quote_string_char} = $params{quote_string_char} ||= "'"; |
16
|
|
|
|
|
|
|
|
17
|
88
|
100
|
|
|
|
254
|
if (my $driver = $params{driver}) { |
18
|
5
|
100
|
|
|
|
34
|
if ($driver =~ /Pg/i) { |
19
|
2
|
|
|
|
|
6
|
$self->{quote_char} = '"'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
88
|
|
|
|
|
394
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub quote { |
27
|
215
|
|
|
215
|
0
|
357
|
my $self = shift; |
28
|
215
|
|
|
|
|
390
|
my ($column, $prefix) = @_; |
29
|
|
|
|
|
|
|
|
30
|
215
|
|
|
|
|
820
|
my @parts = split /\Q$self->{name_separator}\E/, $column; |
31
|
215
|
|
|
|
|
428
|
foreach my $part (@parts) { |
32
|
224
|
|
|
|
|
488
|
$part = $self->{quote_char} . $part . $self->{quote_char}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
215
|
100
|
100
|
|
|
670
|
if ($prefix && @parts == 1) { |
36
|
82
|
|
|
|
|
200
|
unshift @parts, $self->{quote_char} . $prefix . $self->{quote_char}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
215
|
|
|
|
|
891
|
return join $self->{name_separator}, @parts; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub quote_string { |
43
|
2
|
|
|
2
|
0
|
10
|
my $self = shift; |
44
|
2
|
|
|
|
|
5
|
my ($string) = @_; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
18
|
$string =~ s{$self->{quote_string_char}}{\\$self->{quote_string_char}}g; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
11
|
return $self->{quote_string_char} . $string . $self->{quote_string_char}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub split { |
52
|
2
|
|
|
2
|
0
|
9
|
my $self = shift; |
53
|
2
|
|
|
|
|
5
|
my ($quoted_column) = @_; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
17
|
my ($table, $column) = split /\Q$self->{name_separator}\E/, $quoted_column; |
56
|
2
|
100
|
|
|
|
8
|
($column, $table) = ($table, '') unless $column; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return |
59
|
2
|
|
|
|
|
5
|
map { s/^\Q$self->{quote_char}\E//; s/\Q$self->{quote_char}\E$//; $_ } |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
18
|
|
60
|
|
|
|
|
|
|
($table, $column); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |