line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::NamedPlaceholder; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
87585
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
2026
|
use Exporter::Lite; |
|
2
|
|
|
|
|
1691
|
|
|
2
|
|
|
|
|
14
|
|
6
|
2
|
|
|
2
|
|
112
|
use Scalar::Util qw(reftype); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
300
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
740
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(bind_named); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub bind_named { |
14
|
23
|
|
|
23
|
1
|
36343
|
my ($sql, $hash) = @_; |
15
|
23
|
100
|
|
|
|
260
|
$sql or croak 'my ($sql, $bind) = bind_named($sql, $hash) requires $sql'; |
16
|
22
|
100
|
|
|
|
406
|
reftype($hash) eq 'HASH' or croak 'must specify HASH as bind values'; |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
599
|
$sql =~ s{((`?)(\S+?)\2\s*(=|<=?|>=?|<>|!=|<=>)\s*)\?}{$1:$3}g; |
19
|
|
|
|
|
|
|
|
20
|
20
|
|
|
|
|
34
|
my $bind = []; |
21
|
|
|
|
|
|
|
|
22
|
20
|
|
|
|
|
93
|
$sql =~ s{:(\w+)}{ |
23
|
36
|
|
|
|
|
75
|
my $type = ref($hash->{$1}); |
24
|
36
|
100
|
|
|
|
69
|
if ($type eq 'ARRAY') { |
25
|
2
|
50
|
|
|
|
3
|
if (@{ $hash->{$1} }) { |
|
2
|
|
|
|
|
7
|
|
26
|
2
|
|
|
|
|
3
|
push @$bind, @{ $hash->{$1} }; |
|
2
|
|
|
|
|
6
|
|
27
|
2
|
|
|
|
|
4
|
join ', ', map { '?' } @{ $hash->{$1} }; |
|
4
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
5
|
|
28
|
|
|
|
|
|
|
} else { |
29
|
0
|
|
|
|
|
0
|
push @$bind, undef; |
30
|
0
|
|
|
|
|
0
|
'?'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} else { |
33
|
34
|
|
|
|
|
67
|
push @$bind, $hash->{$1}; |
34
|
34
|
|
|
|
|
109
|
'?'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
}eg; |
37
|
|
|
|
|
|
|
|
38
|
20
|
100
|
|
|
|
92
|
wantarray ? ($sql, $bind) : [$sql, $bind]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |