Showing 2 changed files with 99 additions and 77 deletions
+99 -2
t/common.t
... ...
@@ -3,8 +3,6 @@ use strict;
3 3
 use warnings;
4 4
 use DBIx::Custom;
5 5
 
6
-$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
7
-
8 6
 my $dbi;
9 7
 
10 8
 plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
... ...
@@ -13,11 +11,42 @@ plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
13 11
 
14 12
 plan 'no_plan';
15 13
 
14
+$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
15
+sub test { print "# $_[0]\n" }
16
+
16 17
 # Constant
17 18
 my $create_table1 = $dbi->create_table1;
18 19
 
19 20
 # Variable
21
+# Variables
22
+my $builder;
23
+my $datas;
24
+my $sth;
25
+my $source;
26
+my @sources;
27
+my $select_source;
28
+my $insert_source;
29
+my $update_source;
30
+my $param;
31
+my $params;
32
+my $sql;
33
+my $result;
34
+my $row;
35
+my @rows;
36
+my $rows;
37
+my $query;
38
+my @queries;
39
+my $select_query;
40
+my $insert_query;
41
+my $update_query;
42
+my $ret_val;
43
+my $infos;
20 44
 my $model;
45
+my $model2;
46
+my $where;
47
+my $update_param;
48
+my $insert_param;
49
+my $join;
21 50
 
22 51
 # Drop table
23 52
 eval { $dbi->execute('drop table table1') };
... ...
@@ -28,3 +57,71 @@ $model = $dbi->create_model(table => 'table1');
28 57
 $model->insert({key1 => 1, key2 => 2});
29 58
 is_deeply($model->select->all, [{key1 => 1, key2 => 2}]);
30 59
 
60
+test 'DBIx::Custom::Result test';
61
+$dbi->delete_all(table => 'table1');
62
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
63
+$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
64
+$source = "select key1, key2 from table1";
65
+$query = $dbi->create_query($source);
66
+$result = $dbi->execute($query);
67
+
68
+@rows = ();
69
+while (my $row = $result->fetch) {
70
+    push @rows, [@$row];
71
+}
72
+is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
73
+
74
+$result = $dbi->execute($query);
75
+@rows = ();
76
+while (my $row = $result->fetch_hash) {
77
+    push @rows, {%$row};
78
+}
79
+is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash");
80
+
81
+$result = $dbi->execute($query);
82
+$rows = $result->fetch_all;
83
+is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
84
+
85
+$result = $dbi->execute($query);
86
+$rows = $result->fetch_hash_all;
87
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "all");
88
+
89
+test 'Insert query return value';
90
+$source = "insert into table1 {insert_param key1 key2}";
91
+$query = $dbi->execute($source, {}, query => 1);
92
+$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
93
+ok($ret_val);
94
+
95
+test 'Direct query';
96
+$dbi->delete_all(table => 'table1');
97
+$insert_source = "insert into table1 {insert_param key1 key2}";
98
+$dbi->execute($insert_source, param => {key1 => 1, key2 => 2});
99
+$result = $dbi->execute('select * from table1;');
100
+$rows = $result->all;
101
+is_deeply($rows, [{key1 => 1, key2 => 2}]);
102
+
103
+test 'Filter basic';
104
+$dbi->delete_all(table => 'table1');
105
+$dbi->register_filter(twice       => sub { $_[0] * 2}, 
106
+                    three_times => sub { $_[0] * 3});
107
+
108
+$insert_source  = "insert into table1 {insert_param key1 key2};";
109
+$insert_query = $dbi->execute($insert_source, {}, query => 1);
110
+$insert_query->filter({key1 => 'twice'});
111
+$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
112
+$result = $dbi->execute('select * from table1;');
113
+$rows = $result->filter({key2 => 'three_times'})->all;
114
+is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
115
+
116
+test 'Filter in';
117
+$dbi->delete_all(table => 'table1');
118
+$insert_source  = "insert into table1 {insert_param key1 key2};";
119
+$insert_query = $dbi->execute($insert_source, {}, query => 1);
120
+$dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
121
+$select_source = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
122
+$select_query = $dbi->execute($select_source,{}, query => 1);
123
+$select_query->filter({'table1.key1' => 'twice'});
124
+$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
125
+$rows = $result->all;
126
+is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
127
+
-75
t/sqlite.t
... ...
@@ -56,83 +56,8 @@ my $join;
56 56
 
57 57
 # Prepare table
58 58
 $dbi = DBIx::Custom->connect(%memory);
59
-$dbi->execute($create_table_default);
60
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
61
-$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
62
-
63
-test 'DBIx::Custom::Result test';
64
-$source = "select key1, key2 from table1";
65
-$query = $dbi->create_query($source);
66
-$result = $dbi->execute($query);
67
-
68
-@rows = ();
69
-while (my $row = $result->fetch) {
70
-    push @rows, [@$row];
71
-}
72
-is_deeply(\@rows, [[1, 2], [3, 4]], "fetch");
73
-
74
-$result = $dbi->execute($query);
75
-@rows = ();
76
-while (my $row = $result->fetch_hash) {
77
-    push @rows, {%$row};
78
-}
79
-is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash");
80
-
81
-$result = $dbi->execute($query);
82
-$rows = $result->fetch_all;
83
-is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
84
-
85
-$result = $dbi->execute($query);
86
-$rows = $result->fetch_hash_all;
87
-is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "all");
88
-
89
-test 'Insert query return value';
90
-$dbi->execute('drop table table1');
91
-$dbi->execute($create_table_default);
92
-$source = "insert into table1 {insert_param key1 key2}";
93
-$query = $dbi->execute($source, {}, query => 1);
94
-$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
95
-ok($ret_val);
96
-
97
-
98
-test 'Direct query';
99
-$dbi->execute('drop table table1');
100
-$dbi->execute($create_table_default);
101
-$insert_source = "insert into table1 {insert_param key1 key2}";
102
-$dbi->execute($insert_source, param => {key1 => 1, key2 => 2});
103
-$result = $dbi->execute('select * from table1;');
104
-$rows = $result->all;
105
-is_deeply($rows, [{key1 => 1, key2 => 2}]);
106
-
107
-test 'Filter basic';
108
-$dbi->execute('drop table table1');
109
-$dbi->execute($create_table_default);
110
-$dbi->register_filter(twice       => sub { $_[0] * 2}, 
111
-                    three_times => sub { $_[0] * 3});
112
-
113
-$insert_source  = "insert into table1 {insert_param key1 key2};";
114
-$insert_query = $dbi->execute($insert_source, {}, query => 1);
115
-$insert_query->filter({key1 => 'twice'});
116
-$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
117
-$result = $dbi->execute('select * from table1;');
118
-$rows = $result->filter({key2 => 'three_times'})->all;
119
-is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
120
-$dbi->execute('drop table table1');
121
-
122
-test 'Filter in';
123
-$dbi->execute($create_table_default);
124
-$insert_source  = "insert into table1 {insert_param key1 key2};";
125
-$insert_query = $dbi->execute($insert_source, {}, query => 1);
126
-$dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
127
-$select_source = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
128
-$select_query = $dbi->execute($select_source,{}, query => 1);
129
-$select_query->filter({'table1.key1' => 'twice'});
130
-$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
131
-$rows = $result->all;
132
-is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
133 59
 
134 60
 test 'DBIx::Custom::SQLTemplate basic tag';
135
-$dbi->execute('drop table table1');
136 61
 $dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
137 62
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
138 63
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});