line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
use strict; |
2
|
1
|
|
|
1
|
|
614
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw/bulk_insert/; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
warn "IMPORTANT: Teng::Plugin::BulkInsert is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my ($self, $table_name, $args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
1
|
|
return unless scalar(@{$args||[]}); |
12
|
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
|
if ($self->dbh->{Driver}->{Name} eq 'mysql') { |
|
0
|
0
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $table = $self->schema->get_table($table_name); |
15
|
0
|
0
|
|
|
|
|
if (! $table) { |
16
|
0
|
|
|
|
|
|
Carp::croak( "Table definition for $table_name does not exist (Did you declare it in our schema?)" ); |
17
|
0
|
0
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ( $table->has_deflators ) { |
20
|
|
|
|
|
|
|
for my $row (@$args) { |
21
|
0
|
0
|
|
|
|
|
for my $col (keys %{$row}) { |
22
|
0
|
|
|
|
|
|
$row->{$col} = $table->call_deflate($col, $row->{$col}); |
23
|
0
|
|
|
|
|
|
} |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ($sql, @binds) = $self->sql_builder->insert_multi( $table_name, $args ); |
28
|
|
|
|
|
|
|
$self->execute($sql, \@binds); |
29
|
0
|
|
|
|
|
|
} else { |
30
|
0
|
|
|
|
|
|
# use transaction for better performance and atomicity. |
31
|
|
|
|
|
|
|
my $txn = $self->txn_scope(); |
32
|
|
|
|
|
|
|
for my $arg (@$args) { |
33
|
0
|
|
|
|
|
|
# do not run trigger for consistency with mysql. |
34
|
0
|
|
|
|
|
|
$self->insert($table_name, $arg); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
$txn->commit; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Teng::Plugin::BulkInsert - (DEPRECATED) Bulk insert helper |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item C<< $teng->bulk_insert($table_name, \@rows_data) >> |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Accepts either an arrayref of hashrefs. |
53
|
|
|
|
|
|
|
each hashref should be a structure suitable |
54
|
|
|
|
|
|
|
for submitting to a Your::Model->insert(...) method. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
insert many record by bulk. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
example: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Your::Model->bulk_insert('user',[ |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
id => 1, |
63
|
|
|
|
|
|
|
name => 'nekokak', |
64
|
|
|
|
|
|
|
}, |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
id => 2, |
67
|
|
|
|
|
|
|
name => 'yappo', |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
id => 3, |
71
|
|
|
|
|
|
|
name => 'walf443', |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
]); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|