... | ... |
@@ -16,6 +16,8 @@ sub test { print "# $_[0]\n" } |
16 | 16 |
|
17 | 17 |
# Constant |
18 | 18 |
my $create_table1 = $dbi->create_table1; |
19 |
+my $create_table1_2 = $dbi->create_table1_2; |
|
20 |
+ |
|
19 | 21 |
|
20 | 22 |
# Variable |
21 | 23 |
# Variables |
... | ... |
@@ -127,7 +129,7 @@ is_deeply($rows, [{key1 => 2, key2 => 4}], "filter"); |
127 | 129 |
|
128 | 130 |
test 'DBIx::Custom::SQLTemplate basic tag'; |
129 | 131 |
$dbi->execute('drop table table1'); |
130 |
-$dbi->execute($dbi->create_table1_2); |
|
132 |
+$dbi->execute($create_table1_2); |
|
131 | 133 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
132 | 134 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
133 | 135 |
|
... | ... |
@@ -151,7 +153,7 @@ is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "bas |
151 | 153 |
|
152 | 154 |
test 'DIB::Custom::SQLTemplate in tag'; |
153 | 155 |
$dbi->execute('drop table table1'); |
154 |
-$dbi->execute($dbi->create_table1_2); |
|
156 |
+$dbi->execute($create_table1_2); |
|
155 | 157 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
156 | 158 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
157 | 159 |
|
... | ... |
@@ -184,4 +186,56 @@ $rows = $result->all; |
184 | 186 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
185 | 187 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic"); |
186 | 188 |
|
189 |
+test 'Named placeholder'; |
|
190 |
+$dbi->execute('drop table table1'); |
|
191 |
+$dbi->execute($create_table1_2); |
|
192 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
193 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
194 |
+ |
|
195 |
+$source = "select * from table1 where key1 = :key1 and key2 = :key2"; |
|
196 |
+$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
197 |
+$rows = $result->all; |
|
198 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
199 |
+ |
|
200 |
+$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2"; |
|
201 |
+$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
202 |
+$rows = $result->all; |
|
203 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
204 |
+ |
|
205 |
+$source = "select * from table1 where key1 = :key1 or key1 = :key1"; |
|
206 |
+$result = $dbi->execute($source, param => {key1 => [1, 2]}); |
|
207 |
+$rows = $result->all; |
|
208 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
209 |
+ |
|
210 |
+$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2"; |
|
211 |
+$result = $dbi->execute( |
|
212 |
+ $source, |
|
213 |
+ param => {'table1.key1' => 1, 'table1.key2' => 1}, |
|
214 |
+ filter => {'table1.key2' => sub { $_[0] * 2 }} |
|
215 |
+); |
|
216 |
+$rows = $result->all; |
|
217 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
218 |
+ |
|
219 |
+$dbi->execute('drop table table1'); |
|
220 |
+$dbi->execute($create_table1); |
|
221 |
+$dbi->insert(table => 'table1', param => {key1 => '2011-10-14 12:19:18', key2 => 2}); |
|
222 |
+$source = "select * from table1 where key1 = '2011-10-14 12:19:18' and key2 = :key2"; |
|
223 |
+$result = $dbi->execute( |
|
224 |
+ $source, |
|
225 |
+ param => {'key2' => 2}, |
|
226 |
+); |
|
227 |
+ |
|
228 |
+$rows = $result->all; |
|
229 |
+is_deeply($rows, [{key1 => '2011-10-14 12:19:18', key2 => 2}]); |
|
230 |
+ |
|
231 |
+$dbi->delete_all(table => 'table1'); |
|
232 |
+$dbi->insert(table => 'table1', param => {key1 => 'a:b c:d', key2 => 2}); |
|
233 |
+$source = "select * from table1 where key1 = 'a\\:b c\\:d' and key2 = :key2"; |
|
234 |
+$result = $dbi->execute( |
|
235 |
+ $source, |
|
236 |
+ param => {'key2' => 2}, |
|
237 |
+); |
|
238 |
+$rows = $result->all; |
|
239 |
+is_deeply($rows, [{key1 => 'a:b c:d', key2 => 2}]); |
|
240 |
+ |
|
187 | 241 |
1; |
... | ... |
@@ -57,60 +57,6 @@ my $join; |
57 | 57 |
# Prepare table |
58 | 58 |
$dbi = DBIx::Custom->connect(%memory); |
59 | 59 |
|
60 |
-test 'Named placeholder'; |
|
61 |
-#$dbi->execute('drop table table1'); |
|
62 |
-$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));'); |
|
63 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
64 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
65 |
- |
|
66 |
-$source = "select * from table1 where key1 = :key1 and key2 = :key2"; |
|
67 |
-$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
68 |
-$rows = $result->all; |
|
69 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
70 |
- |
|
71 |
-$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2"; |
|
72 |
-$result = $dbi->execute($source, param => {key1 => 1, key2 => 2}); |
|
73 |
-$rows = $result->all; |
|
74 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
75 |
- |
|
76 |
-$source = "select * from table1 where key1 = :key1 or key1 = :key1"; |
|
77 |
-$result = $dbi->execute($source, param => {key1 => [1, 2]}); |
|
78 |
-$rows = $result->all; |
|
79 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
80 |
- |
|
81 |
-$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2"; |
|
82 |
-$result = $dbi->execute( |
|
83 |
- $source, |
|
84 |
- param => {'table1.key1' => 1, 'table1.key2' => 1}, |
|
85 |
- filter => {'table1.key2' => sub { $_[0] * 2 }} |
|
86 |
-); |
|
87 |
-$rows = $result->all; |
|
88 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]); |
|
89 |
- |
|
90 |
-$dbi->execute('drop table table1'); |
|
91 |
-$dbi->execute($create_table_default); |
|
92 |
-$dbi->insert(table => 'table1', param => {key1 => '2011-10-14 12:19:18', key2 => 2}); |
|
93 |
-$source = "select * from table1 where key1 = '2011-10-14 12:19:18' and key2 = :key2"; |
|
94 |
-$result = $dbi->execute( |
|
95 |
- $source, |
|
96 |
- param => {'key2' => 2}, |
|
97 |
-); |
|
98 |
- |
|
99 |
-$rows = $result->all; |
|
100 |
-is_deeply($rows, [{key1 => '2011-10-14 12:19:18', key2 => 2}]); |
|
101 |
- |
|
102 |
-$dbi = DBIx::Custom->connect(%memory); |
|
103 |
-$dbi->execute($create_table_default); |
|
104 |
-$dbi->insert(table => 'table1', param => {key1 => 'a:b c:d', key2 => 2}); |
|
105 |
-$source = "select * from table1 where key1 = 'a\\:b c\\:d' and key2 = :key2"; |
|
106 |
-$result = $dbi->execute( |
|
107 |
- $source, |
|
108 |
- param => {'key2' => 2}, |
|
109 |
-); |
|
110 |
-$rows = $result->all; |
|
111 |
-is_deeply($rows, [{key1 => 'a:b c:d', key2 => 2}]); |
|
112 |
- |
|
113 |
- |
|
114 | 60 |
test 'Error case'; |
115 | 61 |
eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')}; |
116 | 62 |
ok($@, "connect error"); |