Showing 1 changed files with 104 additions and 0 deletions
+104
t/basic.t
... ...
@@ -3499,4 +3499,108 @@ $rows = [
3499 3499
     );
3500 3500
 }
3501 3501
 
3502
+test 'result';
3503
+$dbi = DBIx::Custom->connect(%memory);
3504
+$dbi->execute($create_table_default);
3505
+$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
3506
+$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
3507
+
3508
+$result = $dbi->select(table => 'table1');
3509
+@rows = ();
3510
+while (my $row = $result->fetch) {
3511
+    push @rows, [@$row];
3512
+}
3513
+is_deeply(\@rows, [[1, 2], [3, 4]]);
3514
+
3515
+$result = $dbi->select(table => 'table1');
3516
+@rows = ();
3517
+while (my $row = $result->fetch_hash) {
3518
+    push @rows, {%$row};
3519
+}
3520
+is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
3521
+
3522
+$result = $dbi->select(table => 'table1');
3523
+$row = $result->fetch_first;
3524
+is_deeply($row, [1, 2], "row");
3525
+$row = $result->fetch;
3526
+ok(!$row, "finished");
3527
+
3528
+$result = $dbi->select(table => 'table1');
3529
+$row = $result->fetch_hash_first;
3530
+is_deeply($row, {key1 => 1, key2 => 2}, "row");
3531
+$row = $result->fetch_hash;
3532
+ok(!$row, "finished");
3533
+
3534
+$dbi->execute('create table table2 (key1, key2);');
3535
+$result = $dbi->select(table => 'table2');
3536
+$row = $result->fetch_hash_first;
3537
+ok(!$row, "no row fetch");
3538
+
3539
+$dbi = DBIx::Custom->connect(%memory);
3540
+$dbi->execute($create_table_default);
3541
+$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
3542
+$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
3543
+$dbi->insert({key1 => 5, key2 => 6}, table => 'table1');
3544
+$dbi->insert({key1 => 7, key2 => 8}, table => 'table1');
3545
+$dbi->insert({key1 => 9, key2 => 10}, table => 'table1');
3546
+$result = $dbi->select(table => 'table1');
3547
+$rows = $result->fetch_multi(2);
3548
+is_deeply($rows, [[1, 2],
3549
+                  [3, 4]], "fetch_multi first");
3550
+$rows = $result->fetch_multi(2);
3551
+is_deeply($rows, [[5, 6],
3552
+                  [7, 8]], "fetch_multi secound");
3553
+$rows = $result->fetch_multi(2);
3554
+is_deeply($rows, [[9, 10]], "fetch_multi third");
3555
+$rows = $result->fetch_multi(2);
3556
+ok(!$rows);
3557
+
3558
+$result = $dbi->select(table => 'table1');
3559
+eval {$result->fetch_multi};
3560
+like($@, qr/Row count must be specified/, "Not specified row count");
3561
+
3562
+$result = $dbi->select(table => 'table1');
3563
+$rows = $result->fetch_hash_multi(2);
3564
+is_deeply($rows, [{key1 => 1, key2 => 2},
3565
+                  {key1 => 3, key2 => 4}], "fetch_multi first");
3566
+$rows = $result->fetch_hash_multi(2);
3567
+is_deeply($rows, [{key1 => 5, key2 => 6},
3568
+                  {key1 => 7, key2 => 8}], "fetch_multi secound");
3569
+$rows = $result->fetch_hash_multi(2);
3570
+is_deeply($rows, [{key1 => 9, key2 => 10}], "fetch_multi third");
3571
+$rows = $result->fetch_hash_multi(2);
3572
+ok(!$rows);
3573
+
3574
+$result = $dbi->select(table => 'table1');
3575
+eval {$result->fetch_hash_multi};
3576
+like($@, qr/Row count must be specified/, "Not specified row count");
3577
+
3578
+$dbi = DBIx::Custom->connect(%memory);
3579
+$dbi->execute($create_table_default);
3580
+$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
3581
+$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
3582
+
3583
+test 'fetch_all';
3584
+$result = $dbi->select(table => 'table1');
3585
+$rows = $result->fetch_all;
3586
+is_deeply($rows, [[1, 2], [3, 4]]);
3587
+
3588
+test 'fetch_hash_all';
3589
+$result = $dbi->select(table => 'table1');
3590
+$rows = $result->fetch_hash_all;
3591
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
3592
+
3593
+$result = $dbi->select(table => 'table1');
3594
+$result->dbi->filters({three_times => sub { $_[0] * 3}});
3595
+$result->filter({key1 => 'three_times'});
3596
+
3597
+$rows = $result->fetch_all;
3598
+is_deeply($rows, [[3, 2], [9, 4]], "array");
3599
+
3600
+$result = $dbi->select(table => 'table1');
3601
+$result->dbi->filters({three_times => sub { $_[0] * 3}});
3602
+$result->filter({key1 => 'three_times'});
3603
+$rows = $result->fetch_hash_all;
3604
+is_deeply($rows, [{key1 => 3, key2 => 2}, {key1 => 9, key2 => 4}], "hash");
3605
+
3502 3606
 =cut