Showing 1 changed files with 19 additions and 55 deletions
+19 -55
t/02-sqlite.t
... ...
@@ -203,7 +203,7 @@ $result       = $dbi->execute($select_query);
203 203
 $rows = $result->fetch_all_hash;
204 204
 is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
205 205
 
206
-test 'DBI::Custom::SQL::Template';
206
+test 'DBI::Custom::SQL::Template basic tag';
207 207
 $dbi->reconnect;
208 208
 $dbi->do($CREATE_TABLE->{1});
209 209
 $sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
... ...
@@ -223,19 +223,20 @@ $rows = $result->fetch_all_hash;
223 223
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
224 224
 
225 225
 
226
+test 'DBI::Custom::SQL::Template insert tag';
226 227
 $dbi->do("delete from table1");
227 228
 $insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
228 229
 $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
229 230
 
230 231
 $result = $dbi->execute($SELECT_TMPL->{0});
231 232
 $rows = $result->fetch_all_hash;
232
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag");
233
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
233 234
 
234 235
 $dbi->do("delete from table1");
235 236
 $dbi->execute($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
236 237
 $result = $dbi->execute($SELECT_TMPL->{0});
237 238
 $rows = $result->fetch_all_hash;
238
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag #insert");
239
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert");
239 240
 
240 241
 
241 242
 $dbi->do("delete from table1");
... ...
@@ -244,17 +245,17 @@ $dbi->execute($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 =>
244 245
 
245 246
 $result = $dbi->execute($SELECT_TMPL->{0});
246 247
 $rows = $result->fetch_all_hash;
247
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag with table name");
248
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name");
249
+
248 250
 
249 251
 $dbi->do("delete from table1");
250 252
 $dbi->execute($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
251 253
 $result = $dbi->execute($SELECT_TMPL->{0});
252 254
 $rows = $result->fetch_all_hash;
253
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag #insert with table name");
254
-
255
-
255
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name");
256 256
 
257 257
 
258
+test 'DBI::Custom::SQL::Template update tag';
258 259
 $dbi->do("delete from table1");
259 260
 $insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
260 261
 $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
... ...
@@ -266,68 +267,31 @@ $dbi->execute($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 =>
266 267
 $result = $dbi->execute($SELECT_TMPL->{0});
267 268
 $rows = $result->fetch_all_hash;
268 269
 is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
269
-                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag");
270
-
271
-__END__
270
+                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
272 271
 
273
-$dbi->do("delete from table1");
274
-$dbi->execute($update_tmpl, {'#update' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
272
+$dbi->execute($update_tmpl, {'#update' => {key1 => 2, key2 => 2, key3 => 2, key4 => 2}, key5 => 5});
275 273
 $result = $dbi->execute($SELECT_TMPL->{0});
276 274
 $rows = $result->fetch_all_hash;
277
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag #update");
278
-
279
-
280
-$dbi->do("delete from table1");
281
-$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
282
-$dbi->execute($update_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
275
+is_deeply($rows, [{key1 => 2, key2 => 2, key3 => 2, key4 => 2, key5 => 5},
276
+                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : #update");
283 277
 
278
+$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
279
+$dbi->execute($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}});
284 280
 $result = $dbi->execute($SELECT_TMPL->{0});
285 281
 $rows = $result->fetch_all_hash;
286
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag with table name");
282
+is_deeply($rows, [{key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5},
283
+                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name");
287 284
 
288
-$dbi->do("delete from table1");
289
-$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
285
+$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 4, key2 => 4, key3 => 4, key4 => 4}}, table1 => {key5 => 5}});
290 286
 $result = $dbi->execute($SELECT_TMPL->{0});
291 287
 $rows = $result->fetch_all_hash;
292
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag #update with table name");
293
-
288
+is_deeply($rows, [{key1 => 4, key2 => 4, key3 => 4, key4 => 4, key5 => 5},
289
+                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag #update with table name");
294 290
 
295 291
 
296 292
 __END__
297 293
 
298
-# Insert values
299
-$dbi = DBI::Custom->new;
300
-$tmpl   = "insert into table {insert}";
301
-$params = {insert => {key1 => 'a', key2 => 'b'}};
302 294
 
303
-$dbi->filters(filter => sub {
304
-    my ($key, $value) = @_;
305
-    if ($key eq 'key1' && $value eq 'a') {
306
-        return uc $value;
307
-    }
308
-    return $value;
309
-});
310
-    
311
-($sql, @bind_values) = $dbi->_create_sql($tmpl, $params, $dbi->filters->{filter});
312
-is($sql, "insert into table (key1, key2) values (?, ?);");
313
-is_deeply(\@bind, ['A', 'b'], 'sql template bind' );
314
-
315
-# Update set
316
-$dbi = DBI::Custom->new;
317
-$tmpl   = "update table {update}";
318
-$params = {update => {key1 => 'a', key2 => 'b'}};
319
-
320
-$dbi->filters(filter => sub {
321
-    my ($key, $value) = @_;
322
-    if ($key eq 'key1' && $value eq 'a') {
323
-        return uc $value;
324
-    }
325
-    return $value;
326
-});
327
-    
328
-($sql, @bind_values) = $dbi->_create_sql($tmpl, $params, $dbi->filters->{filter});
329
-is($sql, "update table set key1 = ?, key2 = ?;");
330
-is_deeply(\@bind, ['A', 'b'], 'sql template bind' );
331 295
 
332 296
 $dbi->disconnnect;
333 297