Showing 3 changed files with 27 additions and 1 deletions
+3
Changes
... ...
@@ -1,3 +1,6 @@
1
+0.2101
2
+    - fixed update_or_insert bug that when parameter don't contain any key-value
3
+      this method throw exception.
1 4
 0.2100
2 5
     - micro optimization
3 6
     - DBIx::Custom::Query is DEPRECATED!
+2 -1
lib/DBIx/Custom.pm
... ...
@@ -1,7 +1,7 @@
1 1
 package DBIx::Custom;
2 2
 use Object::Simple -base;
3 3
 
4
-our $VERSION = '0.2100';
4
+our $VERSION = '0.2101';
5 5
 use 5.008001;
6 6
 
7 7
 use Carp 'croak';
... ...
@@ -1169,6 +1169,7 @@ sub update_or_insert {
1169 1169
         return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1170 1170
     }
1171 1171
     elsif (@$rows == 1) {
1172
+        return 0 unless keys %$param;
1172 1173
         return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1173 1174
     }
1174 1175
     else {
+22
t/common.t
... ...
@@ -81,6 +81,7 @@ my $user_column_info;
81 81
 my $values_clause;
82 82
 my $assign_clause;
83 83
 my $reuse;
84
+my $affected;
84 85
 
85 86
 require MyDBI1;
86 87
 {
... ...
@@ -662,6 +663,27 @@ eval {
662 663
 };
663 664
 like($@, qr/one/);
664 665
 
666
+eval { $dbi->execute("drop table $table1") };
667
+$dbi->execute($create_table1);
668
+$dbi->update_or_insert(
669
+    {},
670
+    table => $table1,
671
+    primary_key => $key1,
672
+    id => 1
673
+);
674
+$row = $dbi->select(id => 1, table => $table1, primary_key => $key1)->one;
675
+is($row->{$key1}, 1);
676
+
677
+eval { 
678
+    $affected = $dbi->update_or_insert(
679
+        {},
680
+        table => $table1,
681
+        primary_key => $key1,
682
+        id => 1
683
+    );
684
+};
685
+is($affected, 0);
686
+
665 687
 test 'model update_or_insert';
666 688
 eval { $dbi->execute("drop table $table1") };
667 689
 $dbi->execute($create_table1);