... | ... |
@@ -1020,11 +1020,12 @@ sub update { |
1020 | 1020 |
croak qq{"$name" is wrong option } . _subname |
1021 | 1021 |
unless $UPDATE_ARGS{$name}; |
1022 | 1022 |
} |
1023 |
- |
|
1023 |
+ |
|
1024 | 1024 |
# Update clause |
1025 | 1025 |
my $update_clause = $self->update_param($param); |
1026 | 1026 |
|
1027 | 1027 |
# Where |
1028 |
+ $where = $self->_create_param_from_id($id, $primary_key) if $id; |
|
1028 | 1029 |
my $where_clause = ''; |
1029 | 1030 |
if (ref $where) { |
1030 | 1031 |
$where = $self->_where_to_obj($where); |
... | ... |
@@ -2376,5 +2376,58 @@ is($row->{key1}, 1); |
2376 | 2376 |
is($row->{key2}, 2); |
2377 | 2377 |
is($row->{key3}, 3); |
2378 | 2378 |
|
2379 |
+test 'update and id option'; |
|
2380 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2381 |
+$dbi->execute($CREATE_TABLE->{1}); |
|
2382 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2383 |
+$dbi->update( |
|
2384 |
+ table => 'table1', |
|
2385 |
+ primary_key => ['key1', 'key2'], |
|
2386 |
+ id => [1, 2], |
|
2387 |
+ param => {key3 => 4} |
|
2388 |
+); |
|
2389 |
+is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2390 |
+is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2391 |
+is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2392 |
+ |
|
2393 |
+$dbi->delete_all(table => 'table1'); |
|
2394 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2395 |
+$dbi->update( |
|
2396 |
+ table => 'table1', |
|
2397 |
+ primary_key => 'key1', |
|
2398 |
+ id => 1, |
|
2399 |
+ param => {key3 => 4} |
|
2400 |
+); |
|
2401 |
+is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2402 |
+is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2403 |
+is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2404 |
+ |
|
2405 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2406 |
+$dbi->execute($CREATE_TABLE->{1}); |
|
2407 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2408 |
+$dbi->update( |
|
2409 |
+ {key3 => 4}, |
|
2410 |
+ table => 'table1', |
|
2411 |
+ primary_key => ['key1', 'key2'], |
|
2412 |
+ id => [1, 2] |
|
2413 |
+); |
|
2414 |
+is($dbi->select(table => 'table1')->one->{key1}, 1); |
|
2415 |
+is($dbi->select(table => 'table1')->one->{key2}, 2); |
|
2416 |
+is($dbi->select(table => 'table1')->one->{key3}, 4); |
|
2417 |
+ |
|
2418 |
+ |
|
2419 |
+test 'model update_at'; |
|
2420 |
+$dbi = MyDBI6->connect($NEW_ARGS->{0}); |
|
2421 |
+$dbi->execute($CREATE_TABLE->{1}); |
|
2422 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3}); |
|
2423 |
+$dbi->model('table1')->update( |
|
2424 |
+ id => [1, 2], |
|
2425 |
+ param => {key3 => 4} |
|
2426 |
+); |
|
2427 |
+$result = $dbi->model('table1')->select; |
|
2428 |
+$row = $result->one; |
|
2429 |
+is($row->{key1}, 1); |
|
2430 |
+is($row->{key2}, 2); |
|
2431 |
+is($row->{key3}, 4); |
|
2379 | 2432 |
|
2380 | 2433 |
=cut |