... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1682 |
|
2 |
+ - fixed merge_param bug |
|
1 | 3 |
0.1681 |
2 | 4 |
- added EXPERIMENTAL assign_tag() method |
3 | 5 |
0.1680 |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
|
3 |
-our $VERSION = '0.1681'; |
|
3 |
+our $VERSION = '0.1682'; |
|
4 | 4 |
|
5 | 5 |
use 5.008001; |
6 | 6 |
use strict; |
... | ... |
@@ -730,21 +730,24 @@ sub merge_param { |
730 | 730 |
my ($self, @params) = @_; |
731 | 731 |
|
732 | 732 |
# Merge parameters |
733 |
- my $param = {}; |
|
734 |
- foreach my $p (@params) { |
|
735 |
- foreach my $column (keys %$p) { |
|
736 |
- if (exists $param->{$column}) { |
|
737 |
- $param->{$column} = [$param->{$column}] |
|
738 |
- unless ref $param->{$column} eq 'ARRAY'; |
|
739 |
- push @{$param->{$column}}, $p->{$column}; |
|
733 |
+ my $merge = {}; |
|
734 |
+ foreach my $param (@params) { |
|
735 |
+ foreach my $column (keys %$param) { |
|
736 |
+ my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0; |
|
737 |
+ |
|
738 |
+ if (exists $merge->{$column}) { |
|
739 |
+ $merge->{$column} = [$merge->{$column}] |
|
740 |
+ unless ref $merge->{$column} eq 'ARRAY'; |
|
741 |
+ push @{$merge->{$column}}, |
|
742 |
+ ref $param->{$column} ? @{$param->{$column}} : $param->{$column}; |
|
740 | 743 |
} |
741 | 744 |
else { |
742 |
- $param->{$column} = $p->{$column}; |
|
745 |
+ $merge->{$column} = $param->{$column}; |
|
743 | 746 |
} |
744 | 747 |
} |
745 | 748 |
} |
746 | 749 |
|
747 |
- return $param; |
|
750 |
+ return $merge; |
|
748 | 751 |
} |
749 | 752 |
|
750 | 753 |
sub method { |
... | ... |
@@ -2132,6 +2132,14 @@ test 'merge_param'; |
2132 | 2132 |
is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3}); |
2133 | 2133 |
} |
2134 | 2134 |
|
2135 |
+{ |
|
2136 |
+ my $dbi = DBIx::Custom->new; |
|
2137 |
+ my $param1 = {key1 => [1, 2], key2 => 1, key3 => [1, 2]}; |
|
2138 |
+ my $param2 = {key1 => [3, 4], key2 => [2, 3], key3 => 3}; |
|
2139 |
+ my $param = $dbi->merge_param($param1, $param2); |
|
2140 |
+ is_deeply($param, {key1 => [1, 2, 3, 4], key2 => [1, 2, 3], key3 => [1, 2, 3]}); |
|
2141 |
+} |
|
2142 |
+ |
|
2135 | 2143 |
test 'select() param option'; |
2136 | 2144 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
2137 | 2145 |
$dbi->execute($CREATE_TABLE->{0}); |