...
|
...
|
@@ -19,6 +19,11 @@ BEGIN {
|
19
|
19
|
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
|
20
|
20
|
sub test { print "# $_[0]\n" }
|
21
|
21
|
|
|
22
|
+{
|
|
23
|
+ package DBIx::Custom;
|
|
24
|
+ has dsn => sub { 'dbi:SQLite:dbname=:memory:' }
|
|
25
|
+}
|
|
26
|
+
|
22
|
27
|
# Constant
|
23
|
28
|
my %memory = (dsn => 'dbi:SQLite:dbname=:memory:');
|
24
|
29
|
my $create_table1 = 'create table table1 (key1 char(255), key2 char(255));';
|
...
|
...
|
@@ -482,7 +487,7 @@ $result = $dbi->select(table => 'table1');
|
482
|
487
|
ok(! $result->fetch_first, "rollback");
|
483
|
488
|
|
484
|
489
|
test 'cache';
|
485
|
|
-$dbi = DBIx::Custom->connect(%memory);
|
|
490
|
+eval { $dbi->execute('drop table table1') };
|
486
|
491
|
$dbi->cache(1);
|
487
|
492
|
$dbi->execute($create_table1);
|
488
|
493
|
$source = 'select * from table1 where key1 = :key1 and key2 = :key2;';
|
...
|
...
|
@@ -490,7 +495,7 @@ $dbi->execute($source, {}, query => 1);
|
490
|
495
|
is_deeply($dbi->{_cached}->{$source},
|
491
|
496
|
{sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
|
492
|
497
|
|
493
|
|
-$dbi = DBIx::Custom->connect(%memory);
|
|
498
|
+eval { $dbi->execute('drop table table1') };
|
494
|
499
|
$dbi->execute($create_table1);
|
495
|
500
|
$dbi->{_cached} = {};
|
496
|
501
|
$dbi->cache(0);
|
...
|
...
|
@@ -498,7 +503,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
498
|
503
|
is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
|
499
|
504
|
|
500
|
505
|
test 'execute';
|
501
|
|
-$dbi = DBIx::Custom->connect(%memory);
|
|
506
|
+eval { $dbi->execute('drop table table1') };
|
502
|
507
|
$dbi->execute($create_table1);
|
503
|
508
|
{
|
504
|
509
|
local $Carp::Verbose = 0;
|
...
|
...
|
@@ -570,7 +575,6 @@ $dbi->dbh->{AutoCommit} = 1;
|
570
|
575
|
|
571
|
576
|
|
572
|
577
|
test 'method';
|
573
|
|
-$dbi = DBIx::Custom->connect(%memory);
|
574
|
578
|
$dbi->method(
|
575
|
579
|
one => sub { 1 }
|
576
|
580
|
);
|
...
|
...
|
@@ -592,7 +596,8 @@ eval {$dbi->XXXXXX};
|
592
|
596
|
ok($@, "not exists");
|
593
|
597
|
|
594
|
598
|
test 'out filter';
|
595
|
|
-$dbi = DBIx::Custom->connect(%memory);
|
|
599
|
+$dbi = DBIx::Custom->connect;
|
|
600
|
+eval { $dbi->execute('drop table table1') };
|
596
|
601
|
$dbi->execute($create_table1);
|
597
|
602
|
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
598
|
603
|
$dbi->register_filter(three_times => sub { $_[0] * 3});
|
...
|
...
|
@@ -608,6 +613,7 @@ $row = $result->one;
|
608
|
613
|
is_deeply($row, {key1 => 6, key2 => 12}, "insert");
|
609
|
614
|
|
610
|
615
|
$dbi = DBIx::Custom->connect(%memory);
|
|
616
|
+eval { $dbi->execute('drop table table1') };
|
611
|
617
|
$dbi->execute($create_table1);
|
612
|
618
|
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
613
|
619
|
$dbi->register_filter(three_times => sub { $_[0] * 3});
|
...
|
...
|
@@ -623,6 +629,7 @@ $row = $result->one;
|
623
|
629
|
is_deeply($row, {key1 => 1, key2 => 6}, "insert");
|
624
|
630
|
|
625
|
631
|
$dbi = DBIx::Custom->connect(%memory);
|
|
632
|
+eval { $dbi->execute('drop table table1') };
|
626
|
633
|
$dbi->execute($create_table1);
|
627
|
634
|
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
628
|
635
|
$dbi->apply_filter(
|
...
|
...
|
@@ -1432,7 +1439,7 @@ like($@, qr/not registered/);
|
1432
|
1439
|
$dbi->method({one => sub { 1 }});
|
1433
|
1440
|
is($dbi->one, 1);
|
1434
|
1441
|
|
1435
|
|
-eval{DBIx::Custom->connect()};
|
|
1442
|
+eval{DBIx::Custom->connect(dsn => undef)};
|
1436
|
1443
|
like($@, qr/_connect/);
|
1437
|
1444
|
|
1438
|
1445
|
$dbi = DBIx::Custom->connect(%memory);
|