Showing 2 changed files with 29 additions and 71 deletions
+3 -2
lib/DBIx/Custom.pm
... ...
@@ -295,8 +295,6 @@ sub _build_bind_values {
295 295
     return \@bind_values;
296 296
 }
297 297
 
298
-sub transaction { DBIx::Custom::Transaction->new(dbi => shift) }
299
-
300 298
 sub run_transaction {
301 299
     my ($self, $transaction) = @_;
302 300
     
... ...
@@ -480,6 +478,9 @@ sub update {
480 478
             
481 479
             push @{$params->{$where_key}}, $where_params->{$where_key};
482 480
         }
481
+        else {
482
+            $params->{$where_key} = $where_params->{$where_key};
483
+        }
483 484
     }
484 485
     
485 486
     # Execute query
+26 -69
t/dbix-custom-core-sqlite.t
... ...
@@ -339,7 +339,7 @@ $dbi->resist_filter(three_times => sub { $_[0] * 3});
339 339
 $dbi->insert('table1', {key1 => 1, key2 => 2}, {filter => {key1 => 'three_times'}});
340 340
 $result = $dbi->query($SELECT_TMPLS->{0});
341 341
 $rows   = $result->fetch_hash_all;
342
-is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : edit_query_callback");
342
+is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : filter");
343 343
 
344 344
 $dbi->do($DROP_TABLE->{0});
345 345
 $dbi->do($CREATE_TABLE->{0});
... ...
@@ -377,28 +377,17 @@ is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
377 377
 $dbi->do("delete from table1");
378 378
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
379 379
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
380
-$dbi->update('table1', {key2 => 11}, {where => {key1 => 1}, query_edit_cb => sub {
381
-    my $query = shift;
382
-    $query->filter(sub {
383
-        my ($value, $table, $column, $dbi) = @_;
384
-        if ($column eq 'key2') {
385
-            return $value * 2;
386
-        }
387
-        return $value;
388
-    });
389
-}});
380
+$dbi->resist_filter(twice => sub { $_[0] * 2 });
381
+$dbi->update('table1', {key2 => 11}, {where => {key1 => 1},
382
+              filter => {key2 => 'twice'}});
390 383
 $result = $dbi->query($SELECT_TMPLS->{0});
391 384
 $rows   = $result->fetch_hash_all;
392 385
 is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
393 386
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
394
-                  "$test : query edit callback");
387
+                  "$test : filter");
395 388
 
396
-$dbi->update('table1', {key2 => 11}, {where => {key1 => 1}, append => '   ', query_edit_cb => sub {
397
-    my $query = shift;
398
-    is($query->sql, 'update table1 set key2 = ? where table1.key1 = ?    ;',
399
-       "$test: append statement");
400
-}});
401 389
 
390
+$result = $dbi->update('table1', {key2 => 11}, {where => {key1 => 1}, append => '   '});
402 391
 
403 392
 test 'update error';
404 393
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
... ...
@@ -411,28 +400,18 @@ eval{$dbi->update('table1', {key2 => 1})};
411 400
 like($@, qr/Key-value pairs for where clause must be specified to 'update' third argument/,
412 401
          "$test : where key-value pairs not specified");
413 402
 
414
-eval{$dbi->update('table1', {key2 => 1}, {where => {key2 => 3}, append => '', query_edit_cb => 'aaa'})};
415
-like($@, qr/Query edit callback must be code reference/, 
416
-         "$test : query edit callback not code reference");
417
-
418
-
419 403
 test 'update_all';
420 404
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
421 405
 $dbi->do($CREATE_TABLE->{1});
422 406
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
423 407
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
424
-$dbi->update_all('table1', {key2 => 10}, {query_edit_cb => sub {
425
-    my $query = shift;
426
-    $query->filter(sub {
427
-        my ($value, $table, $column, $dbi) = @_;
428
-        return $value * 2;
429
-    })
430
-}});
408
+$dbi->resist_filter(twice => sub { $_[0] * 2 });
409
+$dbi->update_all('table1', {key2 => 10}, {filter => {key2 => 'twice'}});
431 410
 $result = $dbi->query($SELECT_TMPLS->{0});
432 411
 $rows   = $result->fetch_hash_all;
433 412
 is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
434 413
                   {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
435
-                  "$test : query edit callback");
414
+                  "$test : filter");
436 415
 
437 416
 
438 417
 test 'delete';
... ...
@@ -448,23 +427,13 @@ is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
448 427
 $dbi->do("delete from table1;");
449 428
 $dbi->insert('table1', {key1 => 1, key2 => 2});
450 429
 $dbi->insert('table1', {key1 => 3, key2 => 4});
451
-$dbi->delete('table1', {where => {key2 => 1}, query_edit_cb => sub {
452
-    my $query = shift;
453
-    $query->filter(sub {
454
-        my ($value, $table, $column, $dbi) = @_;
455
-        return $value * 2;
456
-    });
457
-}});
430
+$dbi->resist_filter(twice => sub { $_[0] * 2 });
431
+$dbi->delete('table1', {where => {key2 => 1}, filter => {key2 => 'twice'}});
458 432
 $result = $dbi->query($SELECT_TMPLS->{0});
459 433
 $rows   = $result->fetch_hash_all;
460
-is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : query edit callback");
461
-
462
-$dbi->delete('table1', {where => {key1 => 1}, append => '   ', query_edit_cb => sub {
463
-    my $query = shift;
464
-    is($query->sql, 'delete from table1 where table1.key1 = ?    ;',
465
-       "$test: append statement");
466
-}});
434
+is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : filter");
467 435
 
436
+$dbi->delete('table1', {where => {key1 => 1}, append => '   '});
468 437
 
469 438
 $dbi->delete_all('table1');
470 439
 $dbi->insert('table1', {key1 => 1, key2 => 2});
... ...
@@ -481,11 +450,6 @@ eval{$dbi->delete('table1')};
481 450
 like($@, qr/Key-value pairs for where clause must be specified to 'delete' second argument/,
482 451
          "$test : where key-value pairs not specified");
483 452
 
484
-eval{$dbi->delete('table1', {where => {key1 => 1}, append => '', query_edit_cb => 'aaa'})};
485
-like($@, qr/Query edit callback must be code reference/, 
486
-         "$test : query edit callback not code ref");
487
-
488
-
489 453
 test 'delete_all';
490 454
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
491 455
 $dbi->do($CREATE_TABLE->{0});
... ...
@@ -518,17 +482,10 @@ is_deeply($rows, [{key1 => 3}], "$test : table and columns and where key");
518 482
 $rows = $dbi->select('table1', {append => "order by key1 desc limit 1"})->fetch_hash_all;
519 483
 is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : append statement");
520 484
 
521
-$rows = $dbi->select('table1', {where => {key1 => 2}, query_edit_cb =>sub {
522
-    my $query = shift;
523
-    $query->filter(sub {
524
-        my ($value, $table, $column, $dbi) = @_;
525
-        if ($column eq 'key1') {
526
-            return $value - 1;
527
-        }
528
-        return $value;
529
-    });
530
-}})->fetch_hash_all;
531
-is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : query edit call back");
485
+$dbi->resist_filter(decrement => sub { $_[0] - 1 });
486
+$rows = $dbi->select('table1', {where => {key1 => 2}, filter => {key1 => 'decrement'}})
487
+            ->fetch_hash_all;
488
+is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : filter");
532 489
 
533 490
 $dbi->do($CREATE_TABLE->{2});
534 491
 $dbi->insert('table2', {key1 => 1, key3 => 5});
... ...
@@ -550,40 +507,40 @@ delete $DBIx::Custom::CLASS_ATTRS->{_query_cache_keys};
550 507
 $tmpls[0] = "insert into table1 {insert key1 key2}";
551 508
 $queries[0] = $dbi->create_query($tmpls[0]);
552 509
 is(DBIx::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
553
-is(DBIx::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
510
+is(DBIx::Custom->_query_caches->{$tmpls[0]}{columns}, $queries[0]->columns, "$test : columns first");
554 511
 is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls], "$test : cache key first");
555 512
 
556 513
 $tmpls[1] = "select * from table1";
557 514
 $queries[1] = $dbi->create_query($tmpls[1]);
558 515
 is(DBIx::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
559
-is(DBIx::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
516
+is(DBIx::Custom->_query_caches->{$tmpls[0]}{columns}, $queries[0]->columns, "$test : columns first");
560 517
 is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql second");
561
-is(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos second");
518
+is(DBIx::Custom->_query_caches->{$tmpls[1]}{columns}, $queries[1]->columns, "$test : columns second");
562 519
 is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls], "$test : cache key second");
563 520
 
564 521
 $tmpls[2] = "select key1, key2 from table1";
565 522
 $queries[2] = $dbi->create_query($tmpls[2]);
566 523
 ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
567 524
 is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
568
-is(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
525
+is(DBIx::Custom->_query_caches->{$tmpls[1]}{columns}, $queries[1]->columns, "$test : columns cache overflow deleted key");
569 526
 is(DBIx::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
570
-is(DBIx::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
527
+is(DBIx::Custom->_query_caches->{$tmpls[2]}{columns}, $queries[2]->columns, "$test : columns cache overflow deleted key");
571 528
 is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
572 529
 
573 530
 $queries[1] = $dbi->create_query($tmpls[1]);
574 531
 ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
575 532
 is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
576
-is_deeply(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
533
+is_deeply(DBIx::Custom->_query_caches->{$tmpls[1]}{columns}, $queries[1]->columns, "$test : columns cache overflow deleted key");
577 534
 is(DBIx::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
578
-is_deeply(DBIx::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
535
+is_deeply(DBIx::Custom->_query_caches->{$tmpls[2]}{columns}, $queries[2]->columns, "$test : columns cache overflow deleted key");
579 536
 is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
580 537
 
581 538
 $query = $dbi->create_query($tmpls[0]);
582 539
 $query->filter('aaa');
583 540
 $query = $dbi->create_query($tmpls[0]);
584
-ok(!$query->filter, "$test : only cached sql and key_infos");
541
+ok(!$query->filter, "$test : only cached sql and columns");
585 542
 $query->filter('bbb');
586 543
 $query = $dbi->create_query($tmpls[0]);
587
-ok(!$query->filter, "$test : only cached sql and key_infos");
544
+ok(!$query->filter, "$test : only cached sql and columns");
588 545
 
589 546