line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Otogiri::Plugin::BulkInsert; |
2
|
2
|
|
|
2
|
|
30054
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
485
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
408
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
our @EXPORT = qw(bulk_insert); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub bulk_insert { |
10
|
1
|
|
|
1
|
1
|
1459
|
my ($self, $table, $key_list, $row_list) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
3
|
my $keys = join(', ', @$key_list); |
13
|
1
|
|
|
|
|
2
|
my $binds = join(', ', map {'?'} @$key_list); |
|
2
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
9
|
my $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $table, $keys, $binds); |
16
|
1
|
|
|
|
|
4
|
my $sth = $self->dbh->prepare($sql); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
107
|
for my $row (@$row_list) { |
19
|
8
|
|
|
|
|
23
|
my %rowdata = %$row; |
20
|
8
|
|
|
|
|
129
|
$sth->execute(@rowdata{@$key_list}); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
23
|
$sth->finish; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
__END__ |