line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Otogiri::Plugin::BulkInsert; |
2
|
2
|
|
|
2
|
|
15347
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
397
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
7
|
|
|
|
|
|
|
our @EXPORT = qw(bulk_insert); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub bulk_insert { |
10
|
1
|
|
|
1
|
1
|
1757
|
my ($self, $table, $key_list, $row_list) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
3
|
my $keys = join(', ', @$key_list); |
13
|
1
|
|
|
|
|
3
|
my $binds = join(', ', map {'?'} @$key_list); |
|
2
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
8
|
my $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $table, $keys, $binds); |
16
|
1
|
|
|
|
|
6
|
my $sth = $self->dbh->prepare($sql); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
150
|
my $txn = $self->txn_scope(); |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
155
|
for my $row (@$row_list) { |
21
|
8
|
|
|
|
|
26
|
my %rowdata = %$row; |
22
|
8
|
|
|
|
|
121
|
$sth->execute(@rowdata{@$key_list}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
6
|
$txn->commit(); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
56
|
$sth->finish; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
__END__ |