Showing 2 changed files with 23 additions and 20 deletions
+2
Changes
... ...
@@ -1,4 +1,6 @@
1 1
 0.1733
2
+
3
+    - insert method param option is DEPRECATED!
2 4
     - removed argument checking logic because in database performance is more
3 5
       important.
4 6
 0.1732
+21 -20
lib/DBIx/Custom.pm
... ...
@@ -248,7 +248,7 @@ sub delete {
248 248
     my $prefix = $args{prefix};
249 249
     
250 250
     # Where
251
-    $where = $self->_create_param_from_id($id, $primary_key, $table)
251
+    $where = $self->_id_to_param($id, $primary_key, $table)
252 252
       if defined $id;
253 253
     my $where_clause = '';
254 254
     if (ref $where eq 'ARRAY' && !ref $where->[0]) {
... ...
@@ -420,7 +420,7 @@ sub execute {
420 420
     my $main_table = @{$tables}[-1];
421 421
 
422 422
     if (defined $id) {
423
-        my $id_param = $self->_create_param_from_id($id, $primary_key, $main_table);
423
+        my $id_param = $self->_id_to_param($id, $primary_key, $main_table);
424 424
         $param = $self->merge_param($id_param, $param);
425 425
     }
426 426
     
... ...
@@ -600,7 +600,8 @@ sub insert {
600 600
     # Arguments
601 601
     my $param = @_ % 2 ? shift : undef;
602 602
     my %args = @_;
603
-    $param ||= $args{param} || {};
603
+    warn "insert method param option is DEPRECATED" if $args{param};
604
+    $param ||= delete $args{param} || {};
604 605
     
605 606
     # Timestamp
606 607
     if ($args{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
... ...
@@ -610,16 +611,14 @@ sub insert {
610 611
         $value = $value->() if ref $value eq 'CODE';
611 612
         $param->{$_} = $value for @$columns;
612 613
     }
613
-
614
-    # Merge parameter
615
-    if (defined $args{id}) {
616
-        my $id_param = $self->_create_param_from_id($args{id}, $args{primary_key});
617
-        $param = $self->merge_param($id_param, $param);
618
-    }
619
-
614
+    
615
+    # Merge id to parameter
616
+    $param = $self->merge_param(
617
+        $self->_id_to_param($args{id}, $args{primary_key}), $param)
618
+      if defined $args{id};
619
+    
620 620
     # Insert statement
621
-    my $sql;
622
-    $sql .= "insert ";
621
+    my $sql = "insert ";
623 622
     $sql .= "$args{prefix} " if defined $args{prefix};
624 623
     $sql .= "into " . $self->_q($args{table}) . " "
625 624
       . $self->values_clause($param, {wrap => $args{wrap}}) . " ";
... ...
@@ -929,7 +928,7 @@ sub select {
929 928
     
930 929
     # Where
931 930
     my $where_clause = '';
932
-    $where = $self->_create_param_from_id($id, $primary_key, $tables->[-1])
931
+    $where = $self->_id_to_param($id, $primary_key, $tables->[-1])
933 932
       if defined $id;
934 933
     if (ref $where eq 'ARRAY' && !ref $where->[0]) {
935 934
         $where_clause = "where " . $where->[0];
... ...
@@ -1123,7 +1122,7 @@ sub update {
1123 1122
     my $assign_clause = $self->assign_clause($param, {wrap => $wrap});
1124 1123
 
1125 1124
     # Where
1126
-    $where = $self->_create_param_from_id($id, $primary_key, $table)
1125
+    $where = $self->_id_to_param($id, $primary_key, $table)
1127 1126
       if defined $id;
1128 1127
     my $where_clause = '';
1129 1128
     if (ref $where eq 'ARRAY' && !ref $where->[0]) {
... ...
@@ -1322,9 +1321,10 @@ sub _create_bind_values {
1322 1321
     return $bind;
1323 1322
 }
1324 1323
 
1325
-sub _create_param_from_id {
1324
+sub _id_to_param {
1326 1325
     my ($self, $id, $primary_keys, $table) = @_;
1327
-
1326
+    
1327
+    # Check primary key
1328 1328
     croak "primary_key option " .
1329 1329
           "must be specified with id option " . _subname
1330 1330
       unless defined $primary_keys;
... ...
@@ -1744,7 +1744,7 @@ sub select_at {
1744 1744
     my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1745 1745
     
1746 1746
     # Create where parameter
1747
-    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1747
+    my $where_param = $self->_id_to_param($where, $primary_keys);
1748 1748
     
1749 1749
     return $self->select(where => $where_param, %args);
1750 1750
 }
... ...
@@ -1761,7 +1761,7 @@ sub delete_at {
1761 1761
     my $where = delete $args{where};
1762 1762
     
1763 1763
     # Create where parameter
1764
-    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1764
+    my $where_param = $self->_id_to_param($where, $primary_keys);
1765 1765
     
1766 1766
     return $self->delete(where => $where_param, %args);
1767 1767
 }
... ...
@@ -1783,7 +1783,7 @@ sub update_at {
1783 1783
     $param  ||= $p;
1784 1784
     
1785 1785
     # Create where parameter
1786
-    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1786
+    my $where_param = $self->_id_to_param($where, $primary_keys);
1787 1787
     
1788 1788
     return $self->update(where => $where_param, param => $param, %args);
1789 1789
 }
... ...
@@ -1805,7 +1805,7 @@ sub insert_at {
1805 1805
     $param  ||= $p;
1806 1806
     
1807 1807
     # Create where parameter
1808
-    my $where_param = $self->_create_param_from_id($where, $primary_key);
1808
+    my $where_param = $self->_id_to_param($where, $primary_key);
1809 1809
     $param = $self->merge_param($where_param, $param);
1810 1810
     
1811 1811
     return $self->insert(param => $param, %args);
... ...
@@ -3446,6 +3446,7 @@ L<DBIx::Custom>
3446 3446
     update_param_tag # will be removed at 2017/1/1
3447 3447
     
3448 3448
     # Options
3449
+    insert method param option # will be removed at 2017/1/1
3449 3450
     insert method id option # will be removed at 2017/1/1
3450 3451
     select method relation option # will be removed at 2017/1/1
3451 3452
     select method param option # will be removed at 2017/1/1