Showing 1 changed files with 41 additions and 3 deletions
+41 -3
t/02-sqlite.t
... ...
@@ -18,8 +18,6 @@ sub test {
18 18
     $test = shift;
19 19
 }
20 20
 
21
-
22
-
23 21
 # Constant varialbes for test
24 22
 my $CREATE_TABLE = {
25 23
     0 => 'create table table1 (key1 char(255), key2 char(255));',
... ...
@@ -43,6 +41,7 @@ my $NEW_ARGS = {
43 41
 my $dbi;
44 42
 my $sth;
45 43
 my $tmpl;
44
+my @tmpls;
46 45
 my $select_tmpl;
47 46
 my $insert_tmpl;
48 47
 my $update_tmpl;
... ...
@@ -52,6 +51,7 @@ my $result;
52 51
 my @rows;
53 52
 my $rows;
54 53
 my $query;
54
+my @queries;
55 55
 my $select_query;
56 56
 my $insert_query;
57 57
 my $update_query;
... ...
@@ -675,4 +675,42 @@ $rows = $dbi->select([qw/table1 table2/],
675 675
                      ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
676 676
                      {'table1.key2' => 2},
677 677
                      "where table1.key1 = table2.key1")->fetch_all_hash;
678
-is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : join");
678
+is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "$test : join");
679
+
680
+test 'Cache';
681
+$dbi = DBI::Custom->new($NEW_ARGS->{0});
682
+DBI::Custom->query_cache_max(2);
683
+$dbi->do($CREATE_TABLE->{0});
684
+DBI::Custom->delete_class_attr('_query_caches');
685
+DBI::Custom->delete_class_attr('_query_cache_keys');
686
+$tmpls[0] = "insert into table1 {insert key1 key2}";
687
+$queries[0] = $dbi->create_query($tmpls[0]);
688
+is(DBI::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
689
+is(DBI::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
690
+is_deeply(DBI::Custom->_query_cache_keys, [@tmpls], "$test : cache key first");
691
+
692
+$tmpls[1] = "select * from table1";
693
+$queries[1] = $dbi->create_query($tmpls[1]);
694
+is(DBI::Custom->_query_caches->{$tmpls[0]}{sql}, $queries[0]->sql, "$test : sql first");
695
+is(DBI::Custom->_query_caches->{$tmpls[0]}{key_infos}, $queries[0]->key_infos, "$test : key_infos first");
696
+is(DBI::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql second");
697
+is(DBI::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos second");
698
+is_deeply(DBI::Custom->_query_cache_keys, [@tmpls], "$test : cache key second");
699
+
700
+$tmpls[2] = "select key1, key2 from table1";
701
+$queries[2] = $dbi->create_query($tmpls[2]);
702
+ok(!exists DBI::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
703
+is(DBI::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
704
+is(DBI::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
705
+is(DBI::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
706
+is(DBI::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
707
+is_deeply(DBI::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
708
+
709
+$queries[1] = $dbi->create_query($tmpls[1]);
710
+ok(!exists DBI::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key");
711
+is(DBI::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key");
712
+is(DBI::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key");
713
+is(DBI::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key");
714
+is(DBI::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key");
715
+is_deeply(DBI::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third");
716
+