Showing 1 changed files with 32 additions and 40 deletions
+32 -40
t/basic.t
... ...
@@ -1,11 +1,10 @@
1 1
 use Test::More;
2 2
 use strict;
3 3
 use warnings;
4
-
5 4
 use utf8;
6 5
 use Encode qw/encode_utf8 decode_utf8/;
7
-
8
-$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
6
+use FindBin;
7
+use lib "$FindBin::Bin/basic";
9 8
 
10 9
 BEGIN {
11 10
     eval { require DBD::SQLite; 1 }
... ...
@@ -17,10 +16,7 @@ BEGIN {
17 16
     use_ok('DBIx::Custom');
18 17
 }
19 18
 
20
-use FindBin;
21
-use lib "$FindBin::Bin/basic";
22
-
23
-# Function for test name
19
+$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
24 20
 sub test { print "# $_[0]\n" }
25 21
 
26 22
 # Constant varialbes for test
... ...
@@ -32,10 +28,6 @@ my $CREATE_TABLE = {
32 28
     4 => 'create table table3 (key3 int, key4 int);'
33 29
 };
34 30
 
35
-my $SELECT_SOURCES = {
36
-    0 => 'select * from table1;'
37
-};
38
-
39 31
 # Variables
40 32
 my $dbi;
41 33
 my $sth;
... ...
@@ -111,7 +103,7 @@ $dbi->execute('drop table table1');
111 103
 $dbi->execute($CREATE_TABLE->{0});
112 104
 $insert_SOURCE = "insert into table1 {insert_param key1 key2}";
113 105
 $dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2});
114
-$result = $dbi->execute($SELECT_SOURCES->{0});
106
+$result = $dbi->execute('select * from table1;');
115 107
 $rows = $result->all;
116 108
 is_deeply($rows, [{key1 => 1, key2 => 2}]);
117 109
 
... ...
@@ -125,7 +117,7 @@ $insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
125 117
 $insert_query = $dbi->execute($insert_SOURCE, {}, query => 1);
126 118
 $insert_query->filter({key1 => 'twice'});
127 119
 $dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
128
-$result = $dbi->execute($SELECT_SOURCES->{0});
120
+$result = $dbi->execute('select * from table1;');
129 121
 $rows = $result->filter({key2 => 'three_times'})->all;
130 122
 is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
131 123
 $dbi->execute('drop table table1');
... ...
@@ -183,7 +175,7 @@ $dbi->execute("delete from table1");
183 175
 $insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
184 176
 $dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
185 177
 
186
-$result = $dbi->execute($SELECT_SOURCES->{0});
178
+$result = $dbi->execute('select * from table1;');
187 179
 $rows = $result->all;
188 180
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
189 181
 
... ...
@@ -196,7 +188,7 @@ $dbi->execute($insert_SOURCE, param => {key1 => 6, key2 => 7, key3 => 8, key4 =>
196 188
 $update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
197 189
 $dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
198 190
 
199
-$result = $dbi->execute($SELECT_SOURCES->{0});
191
+$result = $dbi->execute('select * from table1;');
200 192
 $rows = $result->all;
201 193
 is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
202 194
                   {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
... ...
@@ -269,7 +261,7 @@ $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
269 261
 $dbi->execute($CREATE_TABLE->{0});
270 262
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
271 263
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
272
-$result = $dbi->execute($SELECT_SOURCES->{0});
264
+$result = $dbi->execute('select * from table1;');
273 265
 $rows   = $result->all;
274 266
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
275 267
 
... ...
@@ -280,7 +272,7 @@ $dbi->register_filter(
280 272
 );
281 273
 $dbi->default_bind_filter('twice');
282 274
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
283
-$result = $dbi->execute($SELECT_SOURCES->{0});
275
+$result = $dbi->execute('select * from table1;');
284 276
 $rows   = $result->all;
285 277
 is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
286 278
 $dbi->default_bind_filter(undef);
... ...
@@ -310,7 +302,7 @@ $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
310 302
 $dbi->execute($CREATE_TABLE->{0});
311 303
 $dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
312 304
 $dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
313
-$result = $dbi->execute($SELECT_SOURCES->{0});
305
+$result = $dbi->execute('select * from table1;');
314 306
 $rows   = $result->all;
315 307
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
316 308
 
... ...
@@ -318,7 +310,7 @@ $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
318 310
 $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
319 311
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
320 312
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
321
-$result = $dbi->execute($SELECT_SOURCES->{0});
313
+$result = $dbi->execute('select * from table1;');
322 314
 $rows   = $result->all;
323 315
 is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
324 316
 
... ...
@@ -326,7 +318,7 @@ $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
326 318
 $dbi->execute($CREATE_TABLE->{0});
327 319
 $dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
328 320
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
329
-$result = $dbi->execute($SELECT_SOURCES->{0});
321
+$result = $dbi->execute('select * from table1;');
330 322
 $rows   = $result->all;
331 323
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
332 324
 
... ...
@@ -336,7 +328,7 @@ $dbi->execute($CREATE_TABLE->{1});
336 328
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
337 329
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
338 330
 $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
339
-$result = $dbi->execute($SELECT_SOURCES->{0});
331
+$result = $dbi->execute('select * from table1;');
340 332
 $rows   = $result->all;
341 333
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
342 334
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -346,14 +338,14 @@ $dbi->execute("delete from table1");
346 338
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
347 339
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
348 340
 $dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
349
-$result = $dbi->execute($SELECT_SOURCES->{0});
341
+$result = $dbi->execute('select * from table1;');
350 342
 $rows   = $result->all;
351 343
 is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
352 344
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
353 345
                   "update key same as search key");
354 346
 
355 347
 $dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
356
-$result = $dbi->execute($SELECT_SOURCES->{0});
348
+$result = $dbi->execute('select * from table1;');
357 349
 $rows   = $result->all;
358 350
 is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
359 351
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -365,7 +357,7 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
365 357
 $dbi->register_filter(twice => sub { $_[0] * 2 });
366 358
 $dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
367 359
               filter => {key2 => sub { $_[0] * 2 }});
368
-$result = $dbi->execute($SELECT_SOURCES->{0});
360
+$result = $dbi->execute('select * from table1;');
369 361
 $rows   = $result->all;
370 362
 is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
371 363
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -449,7 +441,7 @@ $dbi->execute($CREATE_TABLE->{1});
449 441
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
450 442
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
451 443
 $dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
452
-$result = $dbi->execute($SELECT_SOURCES->{0});
444
+$result = $dbi->execute('select * from table1;');
453 445
 $rows   = $result->all;
454 446
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
455 447
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -460,7 +452,7 @@ $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(
460 452
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
461 453
 $dbi->update(table => 'table1', param => {key2 => 4},
462 454
   where => {key1 => 1}, prefix => 'or replace');
463
-$result = $dbi->execute($SELECT_SOURCES->{0});
455
+$result = $dbi->execute('select * from table1;');
464 456
 $rows   = $result->all;
465 457
 is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
466 458
 
... ...
@@ -469,7 +461,7 @@ $dbi->execute($CREATE_TABLE->{1});
469 461
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
470 462
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
471 463
 $dbi->update(table => 'table1', param => {key2 => \"'11'"}, where => {key1 => 1});
472
-$result = $dbi->execute($SELECT_SOURCES->{0});
464
+$result = $dbi->execute('select * from table1;');
473 465
 $rows   = $result->all;
474 466
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
475 467
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -482,7 +474,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4
482 474
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
483 475
 $dbi->register_filter(twice => sub { $_[0] * 2 });
484 476
 $dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
485
-$result = $dbi->execute($SELECT_SOURCES->{0});
477
+$result = $dbi->execute('select * from table1;');
486 478
 $rows   = $result->all;
487 479
 is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
488 480
                   {key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -495,7 +487,7 @@ $dbi->execute($CREATE_TABLE->{0});
495 487
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
496 488
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
497 489
 $dbi->delete(table => 'table1', where => {key1 => 1});
498
-$result = $dbi->execute($SELECT_SOURCES->{0});
490
+$result = $dbi->execute('select * from table1;');
499 491
 $rows   = $result->all;
500 492
 is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
501 493
 
... ...
@@ -504,7 +496,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
504 496
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
505 497
 $dbi->register_filter(twice => sub { $_[0] * 2 });
506 498
 $dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
507
-$result = $dbi->execute($SELECT_SOURCES->{0});
499
+$result = $dbi->execute('select * from table1;');
508 500
 $rows   = $result->all;
509 501
 is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
510 502
 
... ...
@@ -549,7 +541,7 @@ $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
549 541
 $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
550 542
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
551 543
 $dbi->delete(table => 'table1', where => {key1 => 1}, prefix => '    ');
552
-$result = $dbi->execute($SELECT_SOURCES->{0});
544
+$result = $dbi->execute('select * from table1;');
553 545
 $rows   = $result->all;
554 546
 is_deeply($rows, [], "basic");
555 547
 
... ...
@@ -579,7 +571,7 @@ $dbi->execute($CREATE_TABLE->{0});
579 571
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
580 572
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
581 573
 $dbi->delete_all(table => 'table1');
582
-$result = $dbi->execute($SELECT_SOURCES->{0});
574
+$result = $dbi->execute('select * from table1;');
583 575
 $rows   = $result->all;
584 576
 is_deeply($rows, [], "basic");
585 577
 
... ...
@@ -801,7 +793,7 @@ $dbi->apply_filter(
801 793
     'table1', 'key1' => {out => 'twice', in => 'three_times'}, 
802 794
               'key2' => {out => 'three_times', in => 'twice'});
803 795
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
804
-$result = $dbi->execute($SELECT_SOURCES->{0});
796
+$result = $dbi->execute('select * from table1;');
805 797
 $row   = $result->fetch_hash_first;
806 798
 is_deeply($row, {key1 => 2, key2 => 6}, "insert");
807 799
 $result = $dbi->select(table => 'table1');
... ...
@@ -819,7 +811,7 @@ $dbi->apply_filter(
819 811
     'table1', 'key1' => {out => undef}
820 812
 ); 
821 813
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
822
-$result = $dbi->execute($SELECT_SOURCES->{0});
814
+$result = $dbi->execute('select * from table1;');
823 815
 $row   = $result->one;
824 816
 is_deeply($row, {key1 => 1, key2 => 6}, "insert");
825 817
 
... ...
@@ -831,7 +823,7 @@ $dbi->apply_filter(
831 823
 );
832 824
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => undef});
833 825
 $dbi->update(table => 'table1', param => {key1 => 2}, where => {key2 => 2});
834
-$result = $dbi->execute($SELECT_SOURCES->{0});
826
+$result = $dbi->execute('select * from table1;');
835 827
 $row   = $result->one;
836 828
 is_deeply($row, {key1 => 4, key2 => 2}, "update");
837 829
 
... ...
@@ -843,7 +835,7 @@ $dbi->apply_filter(
843 835
 );
844 836
 $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef});
845 837
 $dbi->delete(table => 'table1', where => {key1 => 1});
846
-$result = $dbi->execute($SELECT_SOURCES->{0});
838
+$result = $dbi->execute('select * from table1;');
847 839
 $rows   = $result->all;
848 840
 is_deeply($rows, [], "delete");
849 841
 
... ...
@@ -1997,7 +1989,7 @@ update table1 $update_param
1997 1989
 where key1 = 1
1998 1990
 EOS
1999 1991
 $dbi->execute($sql, param => $param);
2000
-$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
1992
+$result = $dbi->execute('select * from table1;', table => 'table1');
2001 1993
 $rows   = $result->all;
2002 1994
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2003 1995
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -2016,7 +2008,7 @@ update table1 $update_param
2016 2008
 where key1 = 1
2017 2009
 EOS
2018 2010
 $dbi->execute($sql, param => $param);
2019
-$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
2011
+$result = $dbi->execute('select * from table1;', table => 'table1');
2020 2012
 $rows   = $result->all;
2021 2013
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
2022 2014
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -2034,7 +2026,7 @@ update table1 set $update_param
2034 2026
 where key1 = 1
2035 2027
 EOS
2036 2028
 $dbi->execute($sql, param => $param);
2037
-$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
2029
+$result = $dbi->execute('select * from table1;', table => 'table1');
2038 2030
 $rows   = $result->all;
2039 2031
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
2040 2032
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
... ...
@@ -2058,7 +2050,7 @@ update table1 set $update_param
2058 2050
 where key1 = 1
2059 2051
 EOS
2060 2052
 $dbi->execute($sql, param => $param, table => 'table1');
2061
-$result = $dbi->execute($SELECT_SOURCES->{0});
2053
+$result = $dbi->execute('select * from table1;');
2062 2054
 $rows   = $result->all;
2063 2055
 is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2064 2056
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],