Showing 3 changed files with 40 additions and 27 deletions
+1
Changes
... ...
@@ -1,4 +1,5 @@
1 1
 0.1733
2
+    - delete method where_param option is DEPRECATED!
2 3
     - update method where_param option is DEPRECATED!
3 4
     - update method param option is DEPRECATED!
4 5
     - insert method param option is DEPRECATED!
+38 -25
lib/DBIx/Custom.pm
... ...
@@ -229,42 +229,54 @@ sub dbh {
229 229
     }
230 230
 }
231 231
 
232
-sub delete {
233
-    my ($self, %opt) = @_;
234
-
235
-    # Arguments
236
-    my $where            = $opt{where} || {};
237
-    my $where_param      = $opt{where_param} || {};
238
-    
239
-    # Where
240
-    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
241
-      if defined $opt{id};
232
+sub _where_clause_and_param {
233
+    my ($self, $where, $param) = @_;
234
+ 
235
+    $where ||= {};
236
+    $param ||= {};
237
+    my $w = {};
242 238
     my $where_clause = '';
243 239
     if (ref $where eq 'ARRAY' && !ref $where->[0]) {
244
-        $where_clause = "where " . $where->[0];
245
-        $where_param = $where->[1];
240
+        $w->{clause} = "where " . $where->[0];
241
+        $w->{param} = $where->[1];
246 242
     }
247 243
     elsif (ref $where) {
248 244
         $where = $self->_where_to_obj($where);
249
-        $where_param = keys %$where_param
250
-                     ? $self->merge_param($where_param, $where->param)
251
-                     : $where->param;
252
-        
253
-        # String where
254
-        $where_clause = $where->to_string;
245
+        $w->{param} = keys %$param
246
+                    ? $self->merge_param($param, $where->param)
247
+                    : $where->param;
248
+        $w->{clause} = $where->to_string;
255 249
     }
256
-    elsif ($where) { $where_clause = "where $where" }
257
-    croak qq{"where" must be specified } . _subname
258
-      if $where_clause eq '' && !$opt{allow_delete_all};
250
+    elsif ($where) {
251
+        $w->{clause} = "where $where";
252
+        $w->{param} = $param;
253
+    }
254
+    
255
+    return $w;
256
+}
257
+
258
+sub delete {
259
+    my ($self, %opt) = @_;
260
+    warn "delete method where_param option is DEPRECATED!"
261
+      if $opt{where_param};
262
+    
263
+    # Don't allow delete all row
264
+    croak qq{delete method where or id option must be specified } . _subname
265
+      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
266
+    
267
+    # Where
268
+    my $where = defined $opt{id}
269
+           ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
270
+           : $opt{where};
271
+    my $w = $self->_where_clause_and_param($where, $opt{where_param});
259 272
 
260 273
     # Delete statement
261
-    my $sql;
262
-    $sql .= "delete ";
274
+    my $sql = "delete ";
263 275
     $sql .= "$opt{prefix} " if defined $opt{prefix};
264
-    $sql .= "from " . $self->_q($opt{table}) . " $where_clause ";
276
+    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
265 277
     
266 278
     # Execute query
267
-    return $self->execute($sql, $where_param, %opt);
279
+    return $self->execute($sql, $w->{param}, %opt);
268 280
 }
269 281
 
270 282
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
... ...
@@ -3427,6 +3439,7 @@ L<DBIx::Custom>
3427 3439
     update_param_tag # will be removed at 2017/1/1
3428 3440
     
3429 3441
     # Options
3442
+    delete method where_param option # will be removed 2017/1/1
3430 3443
     update method where_param option # will be removed 2017/1/1
3431 3444
     insert method param option # will be removed at 2017/1/1
3432 3445
     insert method id option # will be removed at 2017/1/1
+1 -2
t/common.t
... ...
@@ -836,8 +836,7 @@ test 'delete error';
836 836
 eval { $dbi->execute("drop table $table1") };
837 837
 $dbi->execute($create_table1);
838 838
 eval{$dbi->delete(table => $table1)};
839
-like($@, qr/"where" must be specified/,
840
-         "where key-value pairs not specified");
839
+like($@, qr/where/, "where key-value pairs not specified");
841 840
 
842 841
 eval{$dbi->delete(table => $table1, where => {';' => 1})};
843 842
 like($@, qr/safety/);