Showing 1 changed files with 27 additions and 23 deletions
+27 -23
t/sqlite.t
... ...
@@ -23,6 +23,8 @@ sub test { print "# $_[0]\n" }
23 23
 my %memory = (dsn => 'dbi:SQLite:dbname=:memory:');
24 24
 my $create_table1 = 'create table table1 (key1 char(255), key2 char(255));';
25 25
 my $create_table1_2 = 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));';
26
+my $q = '"';
27
+my $p = '"';
26 28
 
27 29
 # Variables
28 30
 my $builder;
... ...
@@ -58,9 +60,10 @@ my $join;
58 60
 # Prepare table
59 61
 $dbi = DBIx::Custom->connect(%memory);
60 62
 
63
+=pod
61 64
 
62 65
 test 'insert';
63
-$dbi = DBIx::Custom->connect(%memory);
66
+eval { $dbi->execute('drop table table1') };
64 67
 $dbi->execute($create_table1);
65 68
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
66 69
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -92,7 +95,6 @@ like($@, qr/noexist/, "invalid");
92 95
 eval{$dbi->insert(table => 'table', param => {';' => 1})};
93 96
 like($@, qr/safety/);
94 97
 
95
-$dbi = DBIx::Custom->connect(%memory);
96 98
 $dbi->quote('"');
97 99
 $dbi->execute('create table "table" ("select")');
98 100
 $dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
... ...
@@ -101,7 +103,7 @@ $result = $dbi->execute('select * from "table"');
101 103
 $rows   = $result->all;
102 104
 is_deeply($rows, [{select => 2}], "reserved word");
103 105
 
104
-$dbi = DBIx::Custom->connect(%memory);
106
+eval { $dbi->execute('drop table table1') };
105 107
 $dbi->execute($create_table1);
106 108
 $dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
107 109
 $dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
... ...
@@ -109,7 +111,7 @@ $result = $dbi->execute('select * from table1;');
109 111
 $rows   = $result->all;
110 112
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
111 113
 
112
-$dbi = DBIx::Custom->connect(%memory);
114
+eval { $dbi->execute('drop table table1') };
113 115
 $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
114 116
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
115 117
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
... ...
@@ -117,7 +119,7 @@ $result = $dbi->execute('select * from table1;');
117 119
 $rows   = $result->all;
118 120
 is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
119 121
 
120
-$dbi = DBIx::Custom->connect(%memory);
122
+eval { $dbi->execute('drop table table1') };
121 123
 $dbi->execute($create_table1);
122 124
 $dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
123 125
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -125,8 +127,10 @@ $result = $dbi->execute('select * from table1;');
125 127
 $rows   = $result->all;
126 128
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
127 129
 
130
+=cut
131
+
128 132
 test 'update';
129
-$dbi = DBIx::Custom->connect(%memory);
133
+eval { $dbi->execute('drop table table1') };
130 134
 $dbi->execute($create_table1_2);
131 135
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
132 136
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
... ...
@@ -174,7 +178,7 @@ like($@, qr/noexist/, "invalid");
174 178
 eval{$dbi->update(table => 'table1')};
175 179
 like($@, qr/where/, "not contain where");
176 180
 
177
-$dbi = DBIx::Custom->connect(%memory);
181
+eval { $dbi->execute('drop table table1') };
178 182
 $dbi->execute($create_table1);
179 183
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
180 184
 $where = $dbi->where;
... ...
@@ -184,7 +188,7 @@ $dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
184 188
 $result = $dbi->select(table => 'table1');
185 189
 is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
186 190
 
187
-$dbi = DBIx::Custom->connect(%memory);
191
+eval { $dbi->execute('drop table table1') };
188 192
 $dbi->execute($create_table1);
189 193
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
190 194
 $dbi->update(
... ...
@@ -198,7 +202,7 @@ $dbi->update(
198 202
 $result = $dbi->select(table => 'table1');
199 203
 is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
200 204
 
201
-$dbi = DBIx::Custom->connect(%memory);
205
+eval { $dbi->execute('drop table table1') };
202 206
 $dbi->execute($create_table1);
203 207
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
204 208
 $where = $dbi->where;
... ...
@@ -214,7 +218,7 @@ like($@, qr/safety/);
214 218
 eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1})};
215 219
 like($@, qr/safety/);
216 220
 
217
-$dbi = DBIx::Custom->connect(%memory);
221
+eval { $dbi->execute('drop table table1') };
218 222
 $dbi->quote('"');
219 223
 $dbi->execute('create table "table" ("select", "update")');
220 224
 $dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
... ...
@@ -228,7 +232,7 @@ is_deeply($rows, [{select => 2, update => 6}], "reserved word");
228 232
 eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
229 233
 like($@, qr/safety/);
230 234
 
231
-$dbi = DBIx::Custom->connect(%memory);
235
+eval { $dbi->execute("drop table ${q}table$p") };
232 236
 $dbi->reserved_word_quote('"');
233 237
 $dbi->execute('create table "table" ("select", "update")');
234 238
 $dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
... ...
@@ -239,7 +243,7 @@ $result = $dbi->execute('select * from "table"');
239 243
 $rows   = $result->all;
240 244
 is_deeply($rows, [{select => 2, update => 6}], "reserved word");
241 245
 
242
-$dbi = DBIx::Custom->connect(%memory);
246
+eval { $dbi->execute('drop table table1') };
243 247
 $dbi->execute($create_table1_2);
244 248
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
245 249
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
... ...
@@ -250,7 +254,7 @@ is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
250 254
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
251 255
                   "basic");
252 256
 
253
-$dbi = DBIx::Custom->connect(%memory);
257
+eval { $dbi->execute('drop table table1') };
254 258
 $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
255 259
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
256 260
 $dbi->update(table => 'table1', param => {key2 => 4},
... ...
@@ -259,7 +263,7 @@ $result = $dbi->execute('select * from table1;');
259 263
 $rows   = $result->all;
260 264
 is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
261 265
 
262
-$dbi = DBIx::Custom->connect(%memory);
266
+eval { $dbi->execute('drop table table1') };
263 267
 $dbi->execute($create_table1_2);
264 268
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
265 269
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
... ...
@@ -271,7 +275,7 @@ is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
271 275
                   "basic");
272 276
 
273 277
 test 'update_all';
274
-$dbi = DBIx::Custom->connect(%memory);
278
+eval { $dbi->execute('drop table table1') };
275 279
 $dbi->execute($create_table1_2);
276 280
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
277 281
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
... ...
@@ -285,7 +289,7 @@ is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
285 289
 
286 290
 
287 291
 test 'delete';
288
-$dbi = DBIx::Custom->connect(%memory);
292
+eval { $dbi->execute('drop table table1') };
289 293
 $dbi->execute($create_table1);
290 294
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
291 295
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -315,7 +319,7 @@ is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
315 319
 eval{$dbi->delete(table => 'table1', where => {key1 => 1}, noexist => 1)};
316 320
 like($@, qr/noexist/, "invalid");
317 321
 
318
-$dbi = DBIx::Custom->connect(%memory);
322
+eval { $dbi->execute('drop table table1') };
319 323
 $dbi->execute($create_table1);
320 324
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
321 325
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -326,7 +330,7 @@ $dbi->delete(table => 'table1', where => $where);
326 330
 $result = $dbi->select(table => 'table1');
327 331
 is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
328 332
 
329
-$dbi = DBIx::Custom->connect(%memory);
333
+eval { $dbi->execute('drop table table1') };
330 334
 $dbi->execute($create_table1);
331 335
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
332 336
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -340,7 +344,7 @@ $dbi->delete(
340 344
 $result = $dbi->select(table => 'table1');
341 345
 is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
342 346
 
343
-$dbi = DBIx::Custom->connect(%memory);
347
+eval { $dbi->execute('drop table table1') };
344 348
 $dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
345 349
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
346 350
 $dbi->delete(table => 'table1', where => {key1 => 1}, prefix => '    ');
... ...
@@ -349,7 +353,7 @@ $rows   = $result->all;
349 353
 is_deeply($rows, [], "basic");
350 354
 
351 355
 test 'delete error';
352
-$dbi = DBIx::Custom->connect(%memory);
356
+eval { $dbi->execute('drop table table1') };
353 357
 $dbi->execute($create_table1);
354 358
 eval{$dbi->delete(table => 'table1')};
355 359
 like($@, qr/"where" must be specified/,
... ...
@@ -369,7 +373,7 @@ $rows   = $result->all;
369 373
 is_deeply($rows, [], "reserved word");
370 374
 
371 375
 test 'delete_all';
372
-$dbi = DBIx::Custom->connect(%memory);
376
+eval { $dbi->execute('drop table table1') };
373 377
 $dbi->execute($create_table1);
374 378
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
375 379
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -380,7 +384,7 @@ is_deeply($rows, [], "basic");
380 384
 
381 385
 
382 386
 test 'select';
383
-$dbi = DBIx::Custom->connect(%memory);
387
+eval { $dbi->execute('drop table table1') };
384 388
 $dbi->execute($create_table1);
385 389
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
386 390
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
... ...
@@ -435,7 +439,7 @@ $rows   = $result->all;
435 439
 is_deeply($rows, [{select => 2, update => 2}], "reserved word");
436 440
 
437 441
 test 'fetch filter';
438
-$dbi = DBIx::Custom->connect(%memory);
442
+eval { $dbi->execute('drop table table1') };
439 443
 $dbi->register_filter(
440 444
     twice       => sub { $_[0] * 2 },
441 445
     three_times => sub { $_[0] * 3 }