| ... | ... |
@@ -260,7 +260,7 @@ sub DESTROY {}
|
| 260 | 260 |
sub create_model {
|
| 261 | 261 |
my $self = shift; |
| 262 | 262 |
|
| 263 |
- # Arguments |
|
| 263 |
+ # Options |
|
| 264 | 264 |
my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
|
| 265 | 265 |
$opt->{dbi} = $self;
|
| 266 | 266 |
my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
|
| ... | ... |
@@ -352,7 +352,7 @@ sub execute {
|
| 352 | 352 |
$param = shift if @_ % 2; |
| 353 | 353 |
my %opt = @_; |
| 354 | 354 |
|
| 355 |
- # Arguments |
|
| 355 |
+ # Options |
|
| 356 | 356 |
my $p = $opt{param} || {};
|
| 357 | 357 |
$param ||= $p; |
| 358 | 358 |
my $tables = $opt{table} || [];
|
| ... | ... |
@@ -572,7 +572,7 @@ sub helper {
|
| 572 | 572 |
sub insert {
|
| 573 | 573 |
my $self = shift; |
| 574 | 574 |
|
| 575 |
- # Arguments |
|
| 575 |
+ # Options |
|
| 576 | 576 |
my $param = @_ % 2 ? shift : undef; |
| 577 | 577 |
my %opt = @_; |
| 578 | 578 |
warn "insert method param option is DEPRECATED" if $opt{param};
|
| ... | ... |
@@ -787,7 +787,7 @@ sub register_filter {
|
| 787 | 787 |
sub select {
|
| 788 | 788 |
my ($self, %opt) = @_; |
| 789 | 789 |
|
| 790 |
- # Arguments |
|
| 790 |
+ # Options |
|
| 791 | 791 |
my $table = $opt{table};
|
| 792 | 792 |
my $tables = ref $table eq 'ARRAY' ? $table |
| 793 | 793 |
: defined $table ? [$table] |
| ... | ... |
@@ -1026,15 +1026,13 @@ sub type_rule {
|
| 1026 | 1026 |
sub update {
|
| 1027 | 1027 |
my $self = shift; |
| 1028 | 1028 |
|
| 1029 |
- # Arguments |
|
| 1029 |
+ # Options |
|
| 1030 | 1030 |
my $param = @_ % 2 ? shift : undef; |
| 1031 | 1031 |
my %opt = @_; |
| 1032 | 1032 |
warn "update param option is DEPRECATED!" if $opt{param};
|
| 1033 | 1033 |
warn "update method where_param option is DEPRECATED!" |
| 1034 | 1034 |
if $opt{where_param};
|
| 1035 | 1035 |
$param ||= $opt{param} || {};
|
| 1036 |
- my $where = $opt{where} || {};
|
|
| 1037 |
- my $where_param = $opt{where_param} || {};
|
|
| 1038 | 1036 |
|
| 1039 | 1037 |
# Don't allow update all rows |
| 1040 | 1038 |
croak qq{update method where option must be specified } . _subname
|
| ... | ... |
@@ -1051,33 +1049,22 @@ sub update {
|
| 1051 | 1049 |
|
| 1052 | 1050 |
# Assign clause |
| 1053 | 1051 |
my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
|
| 1052 |
+ |
|
| 1053 |
+ # Convert id to where parameter |
|
| 1054 |
+ my $where = defined $opt{id}
|
|
| 1055 |
+ ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
|
|
| 1056 |
+ : $opt{where};
|
|
| 1054 | 1057 |
|
| 1055 | 1058 |
# Where |
| 1056 |
- $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
|
|
| 1057 |
- if defined $opt{id};
|
|
| 1058 |
- my $where_clause = ''; |
|
| 1059 |
- if (ref $where eq 'ARRAY' && !ref $where->[0]) {
|
|
| 1060 |
- $where_clause = "where " . $where->[0]; |
|
| 1061 |
- $where_param = $where->[1]; |
|
| 1062 |
- } |
|
| 1063 |
- elsif (ref $where) {
|
|
| 1064 |
- $where = $self->_where_to_obj($where); |
|
| 1065 |
- $where_param = keys %$where_param |
|
| 1066 |
- ? $self->merge_param($where_param, $where->param) |
|
| 1067 |
- : $where->param; |
|
| 1068 |
- |
|
| 1069 |
- # String where |
|
| 1070 |
- $where_clause = $where->to_string; |
|
| 1071 |
- } |
|
| 1072 |
- elsif ($where) { $where_clause = "where $where" }
|
|
| 1059 |
+ my $w = $self->_where_clause_and_param($where, $opt{where_param});
|
|
| 1073 | 1060 |
|
| 1074 | 1061 |
# Merge where parameter to parameter |
| 1075 |
- $param = $self->merge_param($param, $where_param) if keys %$where_param; |
|
| 1062 |
+ $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
|
|
| 1076 | 1063 |
|
| 1077 | 1064 |
# Update statement |
| 1078 | 1065 |
my $sql = "update "; |
| 1079 | 1066 |
$sql .= "$opt{prefix} " if defined $opt{prefix};
|
| 1080 |
- $sql .= $self->_q($opt{table}) . " set $assign_clause $where_clause ";
|
|
| 1067 |
+ $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
|
|
| 1081 | 1068 |
|
| 1082 | 1069 |
# Execute query |
| 1083 | 1070 |
return $self->execute($sql, $param, %opt); |
| ... | ... |
@@ -1088,7 +1075,7 @@ sub update_all { shift->update(allow_update_all => 1, @_) };
|
| 1088 | 1075 |
sub update_or_insert {
|
| 1089 | 1076 |
my $self = shift; |
| 1090 | 1077 |
|
| 1091 |
- # Arguments |
|
| 1078 |
+ # Options |
|
| 1092 | 1079 |
my $param = shift; |
| 1093 | 1080 |
my %opt = @_; |
| 1094 | 1081 |
my $id = $opt{id};
|
| ... | ... |
@@ -1722,7 +1709,7 @@ sub select_at {
|
| 1722 | 1709 |
|
| 1723 | 1710 |
warn "select_at is DEPRECATED! use update and id option instead"; |
| 1724 | 1711 |
|
| 1725 |
- # Arguments |
|
| 1712 |
+ # Options |
|
| 1726 | 1713 |
my $primary_keys = delete $opt{primary_key};
|
| 1727 | 1714 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
| 1728 | 1715 |
my $where = delete $opt{where};
|
| ... | ... |
@@ -1745,7 +1732,7 @@ sub delete_at {
|
| 1745 | 1732 |
|
| 1746 | 1733 |
warn "delete_at is DEPRECATED! use update and id option instead"; |
| 1747 | 1734 |
|
| 1748 |
- # Arguments |
|
| 1735 |
+ # Options |
|
| 1749 | 1736 |
my $primary_keys = delete $opt{primary_key};
|
| 1750 | 1737 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
| 1751 | 1738 |
my $where = delete $opt{where};
|
| ... | ... |
@@ -1762,7 +1749,7 @@ sub update_at {
|
| 1762 | 1749 |
|
| 1763 | 1750 |
warn "update_at is DEPRECATED! use update and id option instead"; |
| 1764 | 1751 |
|
| 1765 |
- # Arguments |
|
| 1752 |
+ # Options |
|
| 1766 | 1753 |
my $param; |
| 1767 | 1754 |
$param = shift if @_ % 2; |
| 1768 | 1755 |
my %opt = @_; |
| ... | ... |
@@ -1784,7 +1771,7 @@ sub insert_at {
|
| 1784 | 1771 |
|
| 1785 | 1772 |
warn "insert_at is DEPRECATED! use insert and id option instead"; |
| 1786 | 1773 |
|
| 1787 |
- # Arguments |
|
| 1774 |
+ # Options |
|
| 1788 | 1775 |
my $param; |
| 1789 | 1776 |
$param = shift if @_ % 2; |
| 1790 | 1777 |
my %opt = @_; |