Showing 2 changed files with 8 additions and 10 deletions
+8 -8
lib/DBIx/Custom.pm
... ...
@@ -241,19 +241,17 @@ sub delete {
241 241
       if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
242 242
     
243 243
     # Where
244
-    my $where = defined $opt{id}
245
-           ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
246
-           : $opt{where};
247
-    my $w = $self->_where_clause_and_param($where, $opt{where_param});
244
+    my $wcp = $self->_where_clause_and_param($opt{where}, $opt{where_param},
245
+      delete $opt{id}, $opt{primary_key}, $opt{table});
248 246
 
249 247
     # Delete statement
250 248
     my $sql = "delete ";
251 249
     $sql .= "$opt{prefix} " if defined $opt{prefix};
252
-    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
250
+    $sql .= "from " . $self->_q($opt{table}) . " $wcp->{clause} ";
253 251
     
254 252
     # Execute query
255 253
     $opt{statement} = 'delete';
256
-    $self->execute($sql, $w->{param}, %opt);
254
+    $self->execute($sql, $wcp->{param}, %opt);
257 255
 }
258 256
 
259 257
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
... ...
@@ -1578,12 +1576,14 @@ sub _where_to_obj {
1578 1576
 }
1579 1577
 
1580 1578
 sub _where_clause_and_param {
1581
-    my ($self, $where, $param) = @_;
1582
- 
1579
+    my ($self, $where, $param, $id, $primary_key, $table) = @_;
1580
+
1583 1581
     $where ||= {};
1582
+    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1584 1583
     $param ||= {};
1585 1584
     my $w = {};
1586 1585
     my $where_clause = '';
1586
+
1587 1587
     if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1588 1588
         $w->{clause} = "where " . $where->[0];
1589 1589
         $w->{param} = $where->[1];
-2
t/common.t
... ...
@@ -2311,7 +2311,6 @@ $dbi = DBIx::Custom->connect;
2311 2311
 eval { $dbi->execute("drop table $table1") };
2312 2312
 $dbi->execute($create_table1_2);
2313 2313
 $param = {$key3 => 3, $key2 => 4};
2314
-$DB::single = 1;
2315 2314
 $dbi->insert(
2316 2315
     $param,
2317 2316
     primary_key => [$key1, $key2], 
... ...
@@ -2327,7 +2326,6 @@ $dbi = DBIx::Custom->connect;
2327 2326
 eval { $dbi->execute("drop table $table1") };
2328 2327
 $dbi->execute($create_table1_2);
2329 2328
 $param = {$key3 => 3, $key2 => 4};
2330
-$DB::single = 1;
2331 2329
 $query = $dbi->insert(
2332 2330
     $param,
2333 2331
     primary_key => [$key1, $key2],