DEPRECATED select() param option, this is renamed to...
...where_param
... | ... |
@@ -1,5 +1,6 @@ |
1 | 1 |
0.1680 |
2 |
- - select, update, and delete where option can receive string where clause |
|
2 |
+ - DEPRECATED select() param option, this is renamed to where_param |
|
3 |
+ - added select(), update(), and delete() where_param option |
|
3 | 4 |
0.1679 |
4 | 5 |
- added EXPERIMENTAL select() wrap option to support Oracle ROWNUM |
5 | 6 |
0.1678 |
... | ... |
@@ -265,7 +265,7 @@ sub dbh { |
265 | 265 |
} |
266 | 266 |
|
267 | 267 |
our %DELETE_ARGS |
268 |
- = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all param/; |
|
268 |
+ = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/; |
|
269 | 269 |
|
270 | 270 |
sub delete { |
271 | 271 |
my ($self, %args) = @_; |
... | ... |
@@ -284,14 +284,15 @@ sub delete { |
284 | 284 |
my $append = delete $args{append}; |
285 | 285 |
my $allow_delete_all = delete $args{allow_delete_all}; |
286 | 286 |
my $query_return = delete $args{query}; |
287 |
- my $param = delete $args{param} || {}; |
|
287 |
+ my $where_param = delete $args{where_param} || {}; |
|
288 | 288 |
|
289 | 289 |
# Where |
290 | 290 |
my $where_clause = ''; |
291 | 291 |
if (ref $where) { |
292 | 292 |
$where = $self->_where_to_obj($where); |
293 |
- $param = keys %$param ? $self->merge_param($param, $where->param) |
|
294 |
- : $where->param; |
|
293 |
+ $where_param = keys %$where_param |
|
294 |
+ ? $self->merge_param($where_param, $where->param) |
|
295 |
+ : $where->param; |
|
295 | 296 |
|
296 | 297 |
# String where |
297 | 298 |
$where_clause = $where->to_string; |
... | ... |
@@ -314,7 +315,7 @@ sub delete { |
314 | 315 |
# Execute query |
315 | 316 |
return $self->execute( |
316 | 317 |
$query, |
317 |
- param => $param, |
|
318 |
+ param => $where_param, |
|
318 | 319 |
table => $table, |
319 | 320 |
%args |
320 | 321 |
); |
... | ... |
@@ -809,7 +810,7 @@ sub register_tag { shift->query_builder->register_tag(@_) } |
809 | 810 |
|
810 | 811 |
our %SELECT_ARGS |
811 | 812 |
= map { $_ => 1 } @COMMON_ARGS, |
812 |
- qw/column where append relation join param wrap/; |
|
813 |
+ qw/column where append relation join param where_param wrap/; |
|
813 | 814 |
|
814 | 815 |
sub select { |
815 | 816 |
my ($self, %args) = @_; |
... | ... |
@@ -826,7 +827,10 @@ sub select { |
826 | 827 |
croak qq{"join" must be array reference } . _subname |
827 | 828 |
unless ref $join eq 'ARRAY'; |
828 | 829 |
my $relation = delete $args{relation}; |
829 |
- my $param = delete $args{param} || {}; |
|
830 |
+ my $param = delete $args{param} || {}; # DEPRECATED! |
|
831 |
+ warn "DEPRECATED select() param option. this is renamed to where_param" |
|
832 |
+ if keys %$param; |
|
833 |
+ my $where_param = delete $args{where_param} || $param || {}; |
|
830 | 834 |
my $query_return = $args{query}; |
831 | 835 |
my $wrap = delete $args{wrap}; |
832 | 836 |
|
... | ... |
@@ -873,14 +877,16 @@ sub select { |
873 | 877 |
unless $tables->[-1]; |
874 | 878 |
|
875 | 879 |
# Add tables in parameter |
876 |
- unshift @$tables, @{$self->_search_tables(join(' ', keys %$param) || '')}; |
|
880 |
+ unshift @$tables, |
|
881 |
+ @{$self->_search_tables(join(' ', keys %$where_param) || '')}; |
|
877 | 882 |
|
878 | 883 |
# Where |
879 | 884 |
my $where_clause = ''; |
880 | 885 |
if (ref $where) { |
881 | 886 |
$where = $self->_where_to_obj($where); |
882 |
- $param = keys %$param ? $self->merge_param($param, $where->param) |
|
883 |
- : $where->param; |
|
887 |
+ $where_param = keys %$where_param |
|
888 |
+ ? $self->merge_param($where_param, $where->param) |
|
889 |
+ : $where->param; |
|
884 | 890 |
|
885 | 891 |
# String where |
886 | 892 |
$where_clause = $where->to_string; |
... | ... |
@@ -920,7 +926,7 @@ sub select { |
920 | 926 |
# Execute query |
921 | 927 |
my $result = $self->execute( |
922 | 928 |
$query, |
923 |
- param => $param, |
|
929 |
+ param => $where_param, |
|
924 | 930 |
table => $tables, |
925 | 931 |
%args |
926 | 932 |
); |
... | ... |
@@ -972,7 +978,7 @@ sub setup_model { |
972 | 978 |
} |
973 | 979 |
|
974 | 980 |
our %UPDATE_ARGS |
975 |
- = map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all/; |
|
981 |
+ = map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all where_param/; |
|
976 | 982 |
|
977 | 983 |
sub update { |
978 | 984 |
my ($self, %args) = @_; |
... | ... |
@@ -983,6 +989,7 @@ sub update { |
983 | 989 |
unless $table; |
984 | 990 |
my $param = delete $args{param} || {}; |
985 | 991 |
my $where = delete $args{where} || {}; |
992 |
+ my $where_param = delete $args{where_param} || {}; |
|
986 | 993 |
my $append = delete $args{append} || ''; |
987 | 994 |
my $allow_update_all = delete $args{allow_update_all}; |
988 | 995 |
|
... | ... |
@@ -1011,8 +1018,9 @@ sub update { |
1011 | 1018 |
my $where_clause = ''; |
1012 | 1019 |
if (ref $where) { |
1013 | 1020 |
$where = $self->_where_to_obj($where); |
1014 |
- $param = keys %$param ? $self->merge_param($param, $where->param) |
|
1015 |
- : $where->param; |
|
1021 |
+ $where_param = keys %$where_param |
|
1022 |
+ ? $self->merge_param($where_param, $where->param) |
|
1023 |
+ : $where->param; |
|
1016 | 1024 |
|
1017 | 1025 |
# String where |
1018 | 1026 |
$where_clause = $where->to_string; |
... | ... |
@@ -1021,6 +1029,9 @@ sub update { |
1021 | 1029 |
croak qq{"where" must be specified } . _subname |
1022 | 1030 |
if "$where_clause" eq '' && !$allow_update_all; |
1023 | 1031 |
|
1032 |
+ # Merge param |
|
1033 |
+ $param = $self->merge_param($param, $where_param) if keys %$where_param; |
|
1034 |
+ |
|
1024 | 1035 |
# Update statement |
1025 | 1036 |
my @sql; |
1026 | 1037 |
push @sql, "update $q$table$q $update_clause $where_clause"; |
... | ... |
@@ -2584,14 +2595,12 @@ or array refrence. |
2584 | 2595 |
); |
2585 | 2596 |
$dbi->update(where => $where); |
2586 | 2597 |
|
2587 |
- # Array refrendce (where clause and parameter) |
|
2588 |
- $dbi->update(where => |
|
2589 |
- [ |
|
2590 |
- ['and', '{= author}', '{like title}'], |
|
2591 |
- {author => 'Ken', title => '%Perl%'} |
|
2592 |
- ] |
|
2598 |
+ # String |
|
2599 |
+ $dbi->update( |
|
2600 |
+ where => ['{= id}', {id => 2}] |
|
2601 |
+ param => {title => 'Perl', id => 2} |
|
2593 | 2602 |
); |
2594 |
- |
|
2603 |
+ |
|
2595 | 2604 |
=item C<append> |
2596 | 2605 |
|
2597 | 2606 |
Append statement to last of SQL. This is string. |
... | ... |
@@ -2159,7 +2159,7 @@ $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
2159 | 2159 |
$rows = $dbi->select( |
2160 | 2160 |
table => 'table1', |
2161 | 2161 |
where => '{= key1} and {= key2}', |
2162 |
- param => {key1 => 1, key2 => 2} |
|
2162 |
+ where_param => {key1 => 1, key2 => 2} |
|
2163 | 2163 |
)->fetch_hash_all; |
2164 | 2164 |
is_deeply($rows, [{key1 => 1, key2 => 2}]); |
2165 | 2165 |
|
... | ... |
@@ -2171,7 +2171,7 @@ $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
2171 | 2171 |
$dbi->delete( |
2172 | 2172 |
table => 'table1', |
2173 | 2173 |
where => '{= key1} and {= key2}', |
2174 |
- param => {key1 => 1, key2 => 2} |
|
2174 |
+ where_param => {key1 => 1, key2 => 2} |
|
2175 | 2175 |
); |
2176 | 2176 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
2177 | 2177 |
is_deeply($rows, [{key1 => 2, key2 => 3}]); |
... | ... |
@@ -2183,8 +2183,9 @@ $dbi->execute($CREATE_TABLE->{0}); |
2183 | 2183 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
2184 | 2184 |
$dbi->update( |
2185 | 2185 |
table => 'table1', |
2186 |
- param => {key1 => [5, 1], key2 => 2}, |
|
2187 |
- where => '{= key1} and {= key2}' |
|
2186 |
+ param => {key1 => 5}, |
|
2187 |
+ where => '{= key1} and {= key2}', |
|
2188 |
+ where_param => {key1 => 1, key2 => 2} |
|
2188 | 2189 |
); |
2189 | 2190 |
$rows = $dbi->select(table => 'table1')->fetch_hash_all; |
2190 | 2191 |
is_deeply($rows, [{key1 => 5, key2 => 2}]); |