- insert method can receive multipule parameters...
..., this is very fast, this is...
| ... | ... |
@@ -505,38 +505,44 @@ sub execute {
|
| 505 | 505 |
if (!$query->{duplicate} && $type_rule_off && !keys %$filter && !$self->{default_out_filter}
|
| 506 | 506 |
&& !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
|
| 507 | 507 |
{
|
| 508 |
- eval { $affected = $sth->execute(map { $params->[0]->{$_} } @{$query->{columns}}) };
|
|
| 509 |
- } |
|
| 510 |
- else {
|
|
| 511 |
- # Create bind values |
|
| 512 |
- my ($bind, $bind_types) = $self->_create_bind_values($params->[0], $query->{columns},
|
|
| 513 |
- $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
|
|
| 514 |
- |
|
| 515 |
- # Execute |
|
| 516 | 508 |
eval {
|
| 517 |
- if ($opt{bind_type} || $opt{type}) {
|
|
| 518 |
- $sth->bind_param($_ + 1, $bind->[$_], |
|
| 519 |
- $bind_types->[$_] ? $bind_types->[$_] : ()) |
|
| 520 |
- for (0 .. @$bind - 1); |
|
| 521 |
- $affected = $sth->execute; |
|
| 522 |
- } |
|
| 523 |
- else {
|
|
| 524 |
- $affected = $sth->execute(@$bind); |
|
| 509 |
+ for my $param (@$params) {
|
|
| 510 |
+ $affected = $sth->execute(map { $param->{$_} } @{$query->{columns}});
|
|
| 525 | 511 |
} |
| 512 |
+ }; |
|
| 513 |
+ } |
|
| 514 |
+ else {
|
|
| 515 |
+ for my $param (@$params) {
|
|
| 516 |
+ # Create bind values |
|
| 517 |
+ my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
|
|
| 518 |
+ $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
|
|
| 519 |
+ |
|
| 520 |
+ # Execute |
|
| 521 |
+ eval {
|
|
| 522 |
+ if ($opt{bind_type} || $opt{type}) {
|
|
| 523 |
+ $sth->bind_param($_ + 1, $bind->[$_], |
|
| 524 |
+ $bind_types->[$_] ? $bind_types->[$_] : ()) |
|
| 525 |
+ for (0 .. @$bind - 1); |
|
| 526 |
+ $affected = $sth->execute; |
|
| 527 |
+ } |
|
| 528 |
+ else {
|
|
| 529 |
+ $affected = $sth->execute(@$bind); |
|
| 530 |
+ } |
|
| 526 | 531 |
|
| 527 |
- # DEBUG message |
|
| 528 |
- if ($ENV{DBIX_CUSTOM_DEBUG}) {
|
|
| 529 |
- warn "SQL:\n" . $query->{sql} . "\n";
|
|
| 530 |
- my @output; |
|
| 531 |
- for my $value (@$bind) {
|
|
| 532 |
- $value = 'undef' unless defined $value; |
|
| 533 |
- $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
|
|
| 534 |
- if utf8::is_utf8($value); |
|
| 535 |
- push @output, $value; |
|
| 532 |
+ # DEBUG message |
|
| 533 |
+ if ($ENV{DBIX_CUSTOM_DEBUG}) {
|
|
| 534 |
+ warn "SQL:\n" . $query->{sql} . "\n";
|
|
| 535 |
+ my @output; |
|
| 536 |
+ for my $value (@$bind) {
|
|
| 537 |
+ $value = 'undef' unless defined $value; |
|
| 538 |
+ $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
|
|
| 539 |
+ if utf8::is_utf8($value); |
|
| 540 |
+ push @output, $value; |
|
| 541 |
+ } |
|
| 542 |
+ warn "Bind values: " . join(', ', @output) . "\n\n";
|
|
| 536 | 543 |
} |
| 537 |
- warn "Bind values: " . join(', ', @output) . "\n\n";
|
|
| 538 |
- } |
|
| 539 |
- }; |
|
| 544 |
+ }; |
|
| 545 |
+ } |
|
| 540 | 546 |
} |
| 541 | 547 |
|
| 542 | 548 |
$self->_croak($@, qq{. Following SQL is executed.\n}
|
| ... | ... |
@@ -636,6 +636,37 @@ like($row->{$key2}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
| 636 | 636 |
like($row->{$key3}, qr/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
| 637 | 637 |
is($row->{$key2}, $row->{$key3});
|
| 638 | 638 |
|
| 639 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 640 |
+$dbi->execute($create_table1); |
|
| 641 |
+$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] , table => $table1);
|
|
| 642 |
+$result = $dbi->execute("select * from $table1");
|
|
| 643 |
+$rows = $result->all; |
|
| 644 |
+is_deeply($rows, [{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}], "basic");
|
|
| 645 |
+ |
|
| 646 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 647 |
+$dbi->execute($create_table1_2); |
|
| 648 |
+$dbi->insert([{$key1 => 1}, {$key1 => 3}] ,
|
|
| 649 |
+ table => $table1, |
|
| 650 |
+ updated_at => $key2, |
|
| 651 |
+ created_at => $key3 |
|
| 652 |
+); |
|
| 653 |
+$result = $dbi->execute("select * from $table1");
|
|
| 654 |
+$rows = $result->all; |
|
| 655 |
+is($rows->[0]->{$key1}, 1);
|
|
| 656 |
+is($rows->[1]->{$key1}, 3);
|
|
| 657 |
+like($rows->[0]->{$key2}, qr/\d{2}:/);
|
|
| 658 |
+like($rows->[1]->{$key2}, qr/\d{2}:/);
|
|
| 659 |
+like($rows->[0]->{$key3}, qr/\d{2}:/);
|
|
| 660 |
+like($rows->[1]->{$key3}, qr/\d{2}:/);
|
|
| 661 |
+ |
|
| 662 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 663 |
+$dbi->execute($create_table1); |
|
| 664 |
+$dbi->insert([{$key1 => 1, $key2 => 2}, {$key1 => 3, $key2 => 4}] ,
|
|
| 665 |
+ table => $table1, filter => {$key1 => sub { $_[0] * 2 }});
|
|
| 666 |
+$result = $dbi->execute("select * from $table1");
|
|
| 667 |
+$rows = $result->all; |
|
| 668 |
+is_deeply($rows, [{$key1 => 2, $key2 => 2}, {$key1 => 6, $key2 => 4}], "basic");
|
|
| 669 |
+ |
|
| 639 | 670 |
test 'update_or_insert'; |
| 640 | 671 |
eval { $dbi->execute("drop table $table1") };
|
| 641 | 672 |
$dbi->execute($create_table1); |