...
|
...
|
@@ -104,7 +104,7 @@ is_deeply($rows, [[1, 2], [3, 4]], "fetch_all");
|
104
|
104
|
|
105
|
105
|
$result = $dbi->execute($query);
|
106
|
106
|
$rows = $result->fetch_hash_all;
|
107
|
|
-is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "fetch_hash_all");
|
|
107
|
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "all");
|
108
|
108
|
|
109
|
109
|
test 'Insert query return value';
|
110
|
110
|
$dbi->execute($DROP_TABLE->{0});
|
...
|
...
|
@@ -121,7 +121,7 @@ $dbi->execute($CREATE_TABLE->{0});
|
121
|
121
|
$insert_SOURCE = "insert into table1 {insert_param key1 key2}";
|
122
|
122
|
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2});
|
123
|
123
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
124
|
|
-$rows = $result->fetch_hash_all;
|
|
124
|
+$rows = $result->all;
|
125
|
125
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
126
|
126
|
|
127
|
127
|
test 'Filter basic';
|
...
|
...
|
@@ -135,7 +135,7 @@ $insert_query = $dbi->create_query($insert_SOURCE);
|
135
|
135
|
$insert_query->filter({key1 => 'twice'});
|
136
|
136
|
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
|
137
|
137
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
138
|
|
-$rows = $result->filter({key2 => 'three_times'})->fetch_hash_all;
|
|
138
|
+$rows = $result->filter({key2 => 'three_times'})->all;
|
139
|
139
|
is_deeply($rows, [{key1 => 2, key2 => 6}], "filter fetch_filter");
|
140
|
140
|
$dbi->execute($DROP_TABLE->{0});
|
141
|
141
|
|
...
|
...
|
@@ -148,7 +148,7 @@ $select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.k
|
148
|
148
|
$select_query = $dbi->create_query($select_SOURCE);
|
149
|
149
|
$select_query->filter({'table1.key1' => 'twice'});
|
150
|
150
|
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
|
151
|
|
-$rows = $result->fetch_hash_all;
|
|
151
|
+$rows = $result->all;
|
152
|
152
|
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
|
153
|
153
|
|
154
|
154
|
test 'DBIx::Custom::SQLTemplate basic tag';
|
...
|
...
|
@@ -160,19 +160,19 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
|
160
|
160
|
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
161
|
161
|
$query = $dbi->create_query($source);
|
162
|
162
|
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
163
|
|
-$rows = $result->fetch_hash_all;
|
|
163
|
+$rows = $result->all;
|
164
|
164
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
165
|
165
|
|
166
|
166
|
$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
167
|
167
|
$query = $dbi->create_query($source);
|
168
|
168
|
$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
169
|
|
-$rows = $result->fetch_hash_all;
|
|
169
|
+$rows = $result->all;
|
170
|
170
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
171
|
171
|
|
172
|
172
|
$source = "select * from table1 where {<= key1} and {like key2};";
|
173
|
173
|
$query = $dbi->create_query($source);
|
174
|
174
|
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
|
175
|
|
-$rows = $result->fetch_hash_all;
|
|
175
|
+$rows = $result->all;
|
176
|
176
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
|
177
|
177
|
|
178
|
178
|
test 'DIB::Custom::SQLTemplate in tag';
|
...
|
...
|
@@ -184,7 +184,7 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
|
184
|
184
|
$source = "select * from table1 where {in key1 2};";
|
185
|
185
|
$query = $dbi->create_query($source);
|
186
|
186
|
$result = $dbi->execute($query, param => {key1 => [9, 1]});
|
187
|
|
-$rows = $result->fetch_hash_all;
|
|
187
|
+$rows = $result->all;
|
188
|
188
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
189
|
189
|
|
190
|
190
|
test 'DBIx::Custom::SQLTemplate insert tag';
|
...
|
...
|
@@ -193,7 +193,7 @@ $insert_SOURCE = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
|
193
|
193
|
$dbi->execute($insert_SOURCE, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
194
|
194
|
|
195
|
195
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
196
|
|
-$rows = $result->fetch_hash_all;
|
|
196
|
+$rows = $result->all;
|
197
|
197
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
198
|
198
|
|
199
|
199
|
test 'DBIx::Custom::SQLTemplate update tag';
|
...
|
...
|
@@ -206,7 +206,7 @@ $update_SOURCE = 'update table1 {update_param key1 key2 key3 key4} where {= key5
|
206
|
206
|
$dbi->execute($update_SOURCE, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
|
207
|
207
|
|
208
|
208
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
209
|
|
-$rows = $result->fetch_hash_all;
|
|
209
|
+$rows = $result->all;
|
210
|
210
|
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
|
211
|
211
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
|
212
|
212
|
|
...
|
...
|
@@ -219,17 +219,17 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
|
219
|
219
|
|
220
|
220
|
$source = "select * from table1 where key1 = :key1 and key2 = :key2";
|
221
|
221
|
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
|
222
|
|
-$rows = $result->fetch_hash_all;
|
|
222
|
+$rows = $result->all;
|
223
|
223
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
|
224
|
224
|
|
225
|
225
|
$source = "select * from table1 where key1 = \n:key1\n and key2 = :key2";
|
226
|
226
|
$result = $dbi->execute($source, param => {key1 => 1, key2 => 2});
|
227
|
|
-$rows = $result->fetch_hash_all;
|
|
227
|
+$rows = $result->all;
|
228
|
228
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
|
229
|
229
|
|
230
|
230
|
$source = "select * from table1 where key1 = :key1 or key1 = :key1";
|
231
|
231
|
$result = $dbi->execute($source, param => {key1 => [1, 2]});
|
232
|
|
-$rows = $result->fetch_hash_all;
|
|
232
|
+$rows = $result->all;
|
233
|
233
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
|
234
|
234
|
|
235
|
235
|
$source = "select * from table1 where key1 = :table1.key1 and key2 = :table1.key2";
|
...
|
...
|
@@ -238,7 +238,7 @@ $result = $dbi->execute(
|
238
|
238
|
param => {'table1.key1' => 1, 'table1.key2' => 1},
|
239
|
239
|
filter => {'table1.key2' => sub { $_[0] * 2 }}
|
240
|
240
|
);
|
241
|
|
-$rows = $result->fetch_hash_all;
|
|
241
|
+$rows = $result->all;
|
242
|
242
|
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}]);
|
243
|
243
|
|
244
|
244
|
test 'Error case';
|
...
|
...
|
@@ -255,7 +255,7 @@ $dbi->execute($CREATE_TABLE->{0});
|
255
|
255
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
256
|
256
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
257
|
257
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
258
|
|
-$rows = $result->fetch_hash_all;
|
|
258
|
+$rows = $result->all;
|
259
|
259
|
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
260
|
260
|
|
261
|
261
|
$dbi->execute('delete from table1');
|
...
|
...
|
@@ -266,14 +266,14 @@ $dbi->register_filter(
|
266
|
266
|
$dbi->default_bind_filter('twice');
|
267
|
267
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
|
268
|
268
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
269
|
|
-$rows = $result->fetch_hash_all;
|
|
269
|
+$rows = $result->all;
|
270
|
270
|
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
|
271
|
271
|
$dbi->default_bind_filter(undef);
|
272
|
272
|
|
273
|
273
|
$dbi->execute($DROP_TABLE->{0});
|
274
|
274
|
$dbi->execute($CREATE_TABLE->{0});
|
275
|
275
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => ' ');
|
276
|
|
-$rows = $dbi->select(table => 'table1')->fetch_hash_all;
|
|
276
|
+$rows = $dbi->select(table => 'table1')->all;
|
277
|
277
|
is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
|
278
|
278
|
|
279
|
279
|
eval{$dbi->insert(table => 'table1', noexist => 1)};
|
...
|
...
|
@@ -288,7 +288,7 @@ $dbi->execute('create table "table" ("select")');
|
288
|
288
|
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
289
|
289
|
$dbi->insert(table => 'table', param => {select => 1});
|
290
|
290
|
$result = $dbi->execute('select * from "table"');
|
291
|
|
-$rows = $result->fetch_hash_all;
|
|
291
|
+$rows = $result->all;
|
292
|
292
|
is_deeply($rows, [{select => 2}], "reserved word");
|
293
|
293
|
|
294
|
294
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -296,7 +296,7 @@ $dbi->execute($CREATE_TABLE->{0});
|
296
|
296
|
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
|
297
|
297
|
$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
|
298
|
298
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
299
|
|
-$rows = $result->fetch_hash_all;
|
|
299
|
+$rows = $result->all;
|
300
|
300
|
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
301
|
301
|
|
302
|
302
|
test 'update';
|
...
|
...
|
@@ -306,7 +306,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4
|
306
|
306
|
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
307
|
307
|
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
|
308
|
308
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
309
|
|
-$rows = $result->fetch_hash_all;
|
|
309
|
+$rows = $result->all;
|
310
|
310
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
311
|
311
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
312
|
312
|
"basic");
|
...
|
...
|
@@ -316,14 +316,14 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4
|
316
|
316
|
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
317
|
317
|
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
|
318
|
318
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
319
|
|
-$rows = $result->fetch_hash_all;
|
|
319
|
+$rows = $result->all;
|
320
|
320
|
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
321
|
321
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
322
|
322
|
"update key same as search key");
|
323
|
323
|
|
324
|
324
|
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
|
325
|
325
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
326
|
|
-$rows = $result->fetch_hash_all;
|
|
326
|
+$rows = $result->all;
|
327
|
327
|
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
328
|
328
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
329
|
329
|
"update key same as search key : param is array ref");
|
...
|
...
|
@@ -335,7 +335,7 @@ $dbi->register_filter(twice => sub { $_[0] * 2 });
|
335
|
335
|
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
|
336
|
336
|
filter => {key2 => sub { $_[0] * 2 }});
|
337
|
337
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
338
|
|
-$rows = $result->fetch_hash_all;
|
|
338
|
+$rows = $result->all;
|
339
|
339
|
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
|
340
|
340
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
341
|
341
|
"filter");
|
...
|
...
|
@@ -356,7 +356,7 @@ $where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
|
356
|
356
|
$where->param({key1 => 1, key2 => 2});
|
357
|
357
|
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
|
358
|
358
|
$result = $dbi->select(table => 'table1');
|
359
|
|
-is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
|
|
359
|
+is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
|
360
|
360
|
|
361
|
361
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
362
|
362
|
$dbi->execute($CREATE_TABLE->{0});
|
...
|
...
|
@@ -370,7 +370,7 @@ $dbi->update(
|
370
|
370
|
]
|
371
|
371
|
);
|
372
|
372
|
$result = $dbi->select(table => 'table1');
|
373
|
|
-is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
|
|
373
|
+is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
|
374
|
374
|
|
375
|
375
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
376
|
376
|
$dbi->execute($CREATE_TABLE->{0});
|
...
|
...
|
@@ -380,7 +380,7 @@ $where->clause(['and', '{= key2}']);
|
380
|
380
|
$where->param({key2 => 2});
|
381
|
381
|
$dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
|
382
|
382
|
$result = $dbi->select(table => 'table1');
|
383
|
|
-is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 2}], 'update() where');
|
|
383
|
+is_deeply($result->all, [{key1 => 3, key2 => 2}], 'update() where');
|
384
|
384
|
|
385
|
385
|
eval{$dbi->update(table => 'table1', param => {';' => 1})};
|
386
|
386
|
like($@, qr/safety/);
|
...
|
...
|
@@ -396,7 +396,7 @@ $dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
|
396
|
396
|
$dbi->insert(table => 'table', param => {select => 1});
|
397
|
397
|
$dbi->update(table => 'table', where => {select => 1}, param => {update => 2});
|
398
|
398
|
$result = $dbi->execute('select * from "table"');
|
399
|
|
-$rows = $result->fetch_hash_all;
|
|
399
|
+$rows = $result->all;
|
400
|
400
|
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
|
401
|
401
|
|
402
|
402
|
eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
|
...
|
...
|
@@ -410,7 +410,7 @@ $dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
|
410
|
410
|
$dbi->insert(table => 'table', param => {select => 1});
|
411
|
411
|
$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
|
412
|
412
|
$result = $dbi->execute('select * from "table"');
|
413
|
|
-$rows = $result->fetch_hash_all;
|
|
413
|
+$rows = $result->all;
|
414
|
414
|
is_deeply($rows, [{select => 2, update => 6}], "reserved word");
|
415
|
415
|
|
416
|
416
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -419,7 +419,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4
|
419
|
419
|
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
420
|
420
|
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
|
421
|
421
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
422
|
|
-$rows = $result->fetch_hash_all;
|
|
422
|
+$rows = $result->all;
|
423
|
423
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
424
|
424
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
425
|
425
|
"basic");
|
...
|
...
|
@@ -432,7 +432,7 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
|
432
|
432
|
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
433
|
433
|
$dbi->update_all(table => 'table1', param => {key2 => 10}, filter => {key2 => 'twice'});
|
434
|
434
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
435
|
|
-$rows = $result->fetch_hash_all;
|
|
435
|
+$rows = $result->all;
|
436
|
436
|
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
|
437
|
437
|
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
|
438
|
438
|
"filter");
|
...
|
...
|
@@ -445,7 +445,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
445
|
445
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
446
|
446
|
$dbi->delete(table => 'table1', where => {key1 => 1});
|
447
|
447
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
448
|
|
-$rows = $result->fetch_hash_all;
|
|
448
|
+$rows = $result->all;
|
449
|
449
|
is_deeply($rows, [{key1 => 3, key2 => 4}], "basic");
|
450
|
450
|
|
451
|
451
|
$dbi->execute("delete from table1;");
|
...
|
...
|
@@ -454,7 +454,7 @@ $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
454
|
454
|
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
455
|
455
|
$dbi->delete(table => 'table1', where => {key2 => 1}, filter => {key2 => 'twice'});
|
456
|
456
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
457
|
|
-$rows = $result->fetch_hash_all;
|
|
457
|
+$rows = $result->all;
|
458
|
458
|
is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
|
459
|
459
|
|
460
|
460
|
$dbi->delete(table => 'table1', where => {key1 => 1}, append => ' ');
|
...
|
...
|
@@ -463,7 +463,7 @@ $dbi->delete_all(table => 'table1');
|
463
|
463
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
464
|
464
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
465
|
465
|
$dbi->delete(table => 'table1', where => {key1 => 1, key2 => 2});
|
466
|
|
-$rows = $dbi->select(table => 'table1')->fetch_hash_all;
|
|
466
|
+$rows = $dbi->select(table => 'table1')->all;
|
467
|
467
|
is_deeply($rows, [{key1 => 3, key2 => 4}], "delete multi key");
|
468
|
468
|
|
469
|
469
|
eval{$dbi->delete(table => 'table1', noexist => 1)};
|
...
|
...
|
@@ -478,7 +478,7 @@ $where->clause(['and', '{= key1}', '{= key2}']);
|
478
|
478
|
$where->param({ke1 => 1, key2 => 2});
|
479
|
479
|
$dbi->delete(table => 'table1', where => $where);
|
480
|
480
|
$result = $dbi->select(table => 'table1');
|
481
|
|
-is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
|
|
481
|
+is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
|
482
|
482
|
|
483
|
483
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
484
|
484
|
$dbi->execute($CREATE_TABLE->{0});
|
...
|
...
|
@@ -492,7 +492,7 @@ $dbi->delete(
|
492
|
492
|
]
|
493
|
493
|
);
|
494
|
494
|
$result = $dbi->select(table => 'table1');
|
495
|
|
-is_deeply($result->fetch_hash_all, [{key1 => 3, key2 => 4}], 'delete() where');
|
|
495
|
+is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
|
496
|
496
|
|
497
|
497
|
test 'delete error';
|
498
|
498
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -511,7 +511,7 @@ $dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
511
|
511
|
$dbi->insert(table => 'table', param => {select => 1});
|
512
|
512
|
$dbi->delete(table => 'table', where => {select => 1});
|
513
|
513
|
$result = $dbi->execute('select * from "table"');
|
514
|
|
-$rows = $result->fetch_hash_all;
|
|
514
|
+$rows = $result->all;
|
515
|
515
|
is_deeply($rows, [], "reserved word");
|
516
|
516
|
|
517
|
517
|
test 'delete_all';
|
...
|
...
|
@@ -521,7 +521,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
521
|
521
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
522
|
522
|
$dbi->delete_all(table => 'table1');
|
523
|
523
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
524
|
|
-$rows = $result->fetch_hash_all;
|
|
524
|
+$rows = $result->all;
|
525
|
525
|
is_deeply($rows, [], "basic");
|
526
|
526
|
|
527
|
527
|
|
...
|
...
|
@@ -530,25 +530,25 @@ $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
530
|
530
|
$dbi->execute($CREATE_TABLE->{0});
|
531
|
531
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
532
|
532
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
533
|
|
-$rows = $dbi->select(table => 'table1')->fetch_hash_all;
|
|
533
|
+$rows = $dbi->select(table => 'table1')->all;
|
534
|
534
|
is_deeply($rows, [{key1 => 1, key2 => 2},
|
535
|
535
|
{key1 => 3, key2 => 4}], "table");
|
536
|
536
|
|
537
|
|
-$rows = $dbi->select(table => 'table1', column => ['key1'])->fetch_hash_all;
|
|
537
|
+$rows = $dbi->select(table => 'table1', column => ['key1'])->all;
|
538
|
538
|
is_deeply($rows, [{key1 => 1}, {key1 => 3}], "table and columns and where key");
|
539
|
539
|
|
540
|
|
-$rows = $dbi->select(table => 'table1', where => {key1 => 1})->fetch_hash_all;
|
|
540
|
+$rows = $dbi->select(table => 'table1', where => {key1 => 1})->all;
|
541
|
541
|
is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key");
|
542
|
542
|
|
543
|
|
-$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->fetch_hash_all;
|
|
543
|
+$rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->all;
|
544
|
544
|
is_deeply($rows, [{key1 => 3}], "table and columns and where key");
|
545
|
545
|
|
546
|
|
-$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->fetch_hash_all;
|
|
546
|
+$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all;
|
547
|
547
|
is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
|
548
|
548
|
|
549
|
549
|
$dbi->register_filter(decrement => sub { $_[0] - 1 });
|
550
|
550
|
$rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
|
551
|
|
- ->fetch_hash_all;
|
|
551
|
+ ->all;
|
552
|
552
|
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
|
553
|
553
|
|
554
|
554
|
$dbi->execute($CREATE_TABLE->{2});
|
...
|
...
|
@@ -558,14 +558,14 @@ $rows = $dbi->select(
|
558
|
558
|
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
|
559
|
559
|
where => {'table1.key2' => 2},
|
560
|
560
|
relation => {'table1.key1' => 'table2.key1'}
|
561
|
|
-)->fetch_hash_all;
|
|
561
|
+)->all;
|
562
|
562
|
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : exists where");
|
563
|
563
|
|
564
|
564
|
$rows = $dbi->select(
|
565
|
565
|
table => [qw/table1 table2/],
|
566
|
566
|
column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'],
|
567
|
567
|
relation => {'table1.key1' => 'table2.key1'}
|
568
|
|
-)->fetch_hash_all;
|
|
568
|
+)->all;
|
569
|
569
|
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "relation : no exists where");
|
570
|
570
|
|
571
|
571
|
eval{$dbi->select(table => 'table1', noexist => 1)};
|
...
|
...
|
@@ -577,7 +577,7 @@ $dbi->execute('create table "table" ("select", "update")');
|
577
|
577
|
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
578
|
578
|
$dbi->insert(table => 'table', param => {select => 1, update => 2});
|
579
|
579
|
$result = $dbi->select(table => 'table', where => {select => 1});
|
580
|
|
-$rows = $result->fetch_hash_all;
|
|
580
|
+$rows = $result->all;
|
581
|
581
|
is_deeply($rows, [{select => 2, update => 2}], "reserved word");
|
582
|
582
|
|
583
|
583
|
test 'fetch filter';
|
...
|
...
|
@@ -689,7 +689,7 @@ eval {
|
689
|
689
|
$dbi->rollback if $@;
|
690
|
690
|
|
691
|
691
|
$result = $dbi->select(table => 'table1');
|
692
|
|
-$rows = $result->fetch_hash_all;
|
|
692
|
+$rows = $result->all;
|
693
|
693
|
is_deeply($rows, [], "rollback");
|
694
|
694
|
|
695
|
695
|
$dbi->begin_work;
|
...
|
...
|
@@ -702,7 +702,7 @@ eval {
|
702
|
702
|
$dbi->commit unless $@;
|
703
|
703
|
|
704
|
704
|
$result = $dbi->select(table => 'table1');
|
705
|
|
-$rows = $result->fetch_hash_all;
|
|
705
|
+$rows = $result->all;
|
706
|
706
|
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "commit");
|
707
|
707
|
|
708
|
708
|
$dbi->dbh->{AutoCommit} = 0;
|
...
|
...
|
@@ -785,7 +785,7 @@ $dbi->apply_filter(
|
785
|
785
|
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1=> undef});
|
786
|
786
|
$dbi->delete(table => 'table1', where => {key1 => 1});
|
787
|
787
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
788
|
|
-$rows = $result->fetch_hash_all;
|
|
788
|
+$rows = $result->all;
|
789
|
789
|
is_deeply($rows, [], "delete");
|
790
|
790
|
|
791
|
791
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -797,7 +797,7 @@ $dbi->apply_filter(
|
797
|
797
|
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
|
798
|
798
|
$result = $dbi->select(table => 'table1', where => {key1 => 1});
|
799
|
799
|
$result->filter({'key2' => 'twice'});
|
800
|
|
-$rows = $result->fetch_hash_all;
|
|
800
|
+$rows = $result->all;
|
801
|
801
|
is_deeply($rows, [{key1 => 4, key2 => 4}], "select");
|
802
|
802
|
|
803
|
803
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -810,7 +810,7 @@ $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1
|
810
|
810
|
$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
|
811
|
811
|
param => {key1 => 1, key2 => 2},
|
812
|
812
|
table => ['table1']);
|
813
|
|
-$rows = $result->fetch_hash_all;
|
|
813
|
+$rows = $result->all;
|
814
|
814
|
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute");
|
815
|
815
|
|
816
|
816
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -822,7 +822,7 @@ $dbi->apply_filter(
|
822
|
822
|
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
|
823
|
823
|
$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
|
824
|
824
|
param => {key1 => 1, key2 => 2});
|
825
|
|
-$rows = $result->fetch_hash_all;
|
|
825
|
+$rows = $result->all;
|
826
|
826
|
is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
|
827
|
827
|
|
828
|
828
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -844,7 +844,7 @@ $result = $dbi->select(
|
844
|
844
|
where => {'table1.key2' => 1, 'table2.key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
|
845
|
845
|
|
846
|
846
|
$result->filter({'key2' => 'twice'});
|
847
|
|
-$rows = $result->fetch_hash_all;
|
|
847
|
+$rows = $result->all;
|
848
|
848
|
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join");
|
849
|
849
|
|
850
|
850
|
$result = $dbi->select(
|
...
|
...
|
@@ -853,7 +853,7 @@ $result = $dbi->select(
|
853
|
853
|
where => {'key2' => 1, 'key3' => 2}, relation => {'table1.key1' => 'table2.key1'});
|
854
|
854
|
|
855
|
855
|
$result->filter({'key2' => 'twice'});
|
856
|
|
-$rows = $result->fetch_hash_all;
|
|
856
|
+$rows = $result->all;
|
857
|
857
|
is_deeply($rows, [{key2 => 4, key3 => 18}], "select : join : omit");
|
858
|
858
|
|
859
|
859
|
test 'each_column';
|
...
|
...
|
@@ -902,19 +902,19 @@ $rows = $dbi->select(
|
902
|
902
|
table => 'table1',
|
903
|
903
|
where => {key1 => 1},
|
904
|
904
|
append => "order by key2 {limit 1 0}"
|
905
|
|
-)->fetch_hash_all;
|
|
905
|
+)->all;
|
906
|
906
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
907
|
907
|
$rows = $dbi->select(
|
908
|
908
|
table => 'table1',
|
909
|
909
|
where => {key1 => 1},
|
910
|
910
|
append => "order by key2 {limit 2 1}"
|
911
|
|
-)->fetch_hash_all;
|
|
911
|
+)->all;
|
912
|
912
|
is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
|
913
|
913
|
$rows = $dbi->select(
|
914
|
914
|
table => 'table1',
|
915
|
915
|
where => {key1 => 1},
|
916
|
916
|
append => "order by key2 {limit 1}"
|
917
|
|
-)->fetch_hash_all;
|
|
917
|
+)->all;
|
918
|
918
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
919
|
919
|
|
920
|
920
|
test 'connect super';
|
...
|
...
|
@@ -1069,7 +1069,7 @@ $result = $dbi->select(
|
1069
|
1069
|
table => 'table1',
|
1070
|
1070
|
where => $where
|
1071
|
1071
|
);
|
1072
|
|
-$row = $result->fetch_hash_all;
|
|
1072
|
+$row = $result->all;
|
1073
|
1073
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1074
|
1074
|
|
1075
|
1075
|
$result = $dbi->select(
|
...
|
...
|
@@ -1079,7 +1079,7 @@ $result = $dbi->select(
|
1079
|
1079
|
{key1 => 1}
|
1080
|
1080
|
]
|
1081
|
1081
|
);
|
1082
|
|
-$row = $result->fetch_hash_all;
|
|
1082
|
+$row = $result->all;
|
1083
|
1083
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1084
|
1084
|
|
1085
|
1085
|
$where = $dbi->where
|
...
|
...
|
@@ -1089,7 +1089,7 @@ $result = $dbi->select(
|
1089
|
1089
|
table => 'table1',
|
1090
|
1090
|
where => $where
|
1091
|
1091
|
);
|
1092
|
|
-$row = $result->fetch_hash_all;
|
|
1092
|
+$row = $result->all;
|
1093
|
1093
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1094
|
1094
|
|
1095
|
1095
|
$where = $dbi->where
|
...
|
...
|
@@ -1099,7 +1099,7 @@ $result = $dbi->select(
|
1099
|
1099
|
table => 'table1',
|
1100
|
1100
|
where => $where,
|
1101
|
1101
|
);
|
1102
|
|
-$row = $result->fetch_hash_all;
|
|
1102
|
+$row = $result->all;
|
1103
|
1103
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
|
1104
|
1104
|
|
1105
|
1105
|
$where = $dbi->where
|
...
|
...
|
@@ -1109,7 +1109,7 @@ $result = $dbi->select(
|
1109
|
1109
|
table => 'table1',
|
1110
|
1110
|
where => $where,
|
1111
|
1111
|
);
|
1112
|
|
-$row = $result->fetch_hash_all;
|
|
1112
|
+$row = $result->all;
|
1113
|
1113
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1114
|
1114
|
|
1115
|
1115
|
$where = $dbi->where;
|
...
|
...
|
@@ -1117,7 +1117,7 @@ $result = $dbi->select(
|
1117
|
1117
|
table => 'table1',
|
1118
|
1118
|
where => $where
|
1119
|
1119
|
);
|
1120
|
|
-$row = $result->fetch_hash_all;
|
|
1120
|
+$row = $result->all;
|
1121
|
1121
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
|
1122
|
1122
|
|
1123
|
1123
|
eval {
|
...
|
...
|
@@ -1140,7 +1140,7 @@ $result = $dbi->select(
|
1140
|
1140
|
table => 'table1',
|
1141
|
1141
|
where => $where,
|
1142
|
1142
|
);
|
1143
|
|
-$row = $result->fetch_hash_all;
|
|
1143
|
+$row = $result->all;
|
1144
|
1144
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
|
1145
|
1145
|
|
1146
|
1146
|
$where = $dbi->where
|
...
|
...
|
@@ -1150,7 +1150,7 @@ $result = $dbi->select(
|
1150
|
1150
|
table => 'table1',
|
1151
|
1151
|
where => $where,
|
1152
|
1152
|
);
|
1153
|
|
-$row = $result->fetch_hash_all;
|
|
1153
|
+$row = $result->all;
|
1154
|
1154
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1155
|
1155
|
|
1156
|
1156
|
$where = $dbi->where
|
...
|
...
|
@@ -1160,7 +1160,7 @@ $result = $dbi->select(
|
1160
|
1160
|
table => 'table1',
|
1161
|
1161
|
where => $where,
|
1162
|
1162
|
);
|
1163
|
|
-$row = $result->fetch_hash_all;
|
|
1163
|
+$row = $result->all;
|
1164
|
1164
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1165
|
1165
|
|
1166
|
1166
|
$where = $dbi->where
|
...
|
...
|
@@ -1170,7 +1170,7 @@ $result = $dbi->select(
|
1170
|
1170
|
table => 'table1',
|
1171
|
1171
|
where => $where,
|
1172
|
1172
|
);
|
1173
|
|
-$row = $result->fetch_hash_all;
|
|
1173
|
+$row = $result->all;
|
1174
|
1174
|
is_deeply($row, [{key1 => 1, key2 => 2}]);
|
1175
|
1175
|
|
1176
|
1176
|
$where = $dbi->where
|
...
|
...
|
@@ -1192,7 +1192,7 @@ $result = $dbi->select(
|
1192
|
1192
|
table => 'table1',
|
1193
|
1193
|
where => $where,
|
1194
|
1194
|
);
|
1195
|
|
-$row = $result->fetch_hash_all;
|
|
1195
|
+$row = $result->all;
|
1196
|
1196
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1197
|
1197
|
|
1198
|
1198
|
$where = $dbi->where
|
...
|
...
|
@@ -1202,7 +1202,7 @@ $result = $dbi->select(
|
1202
|
1202
|
table => 'table1',
|
1203
|
1203
|
where => $where,
|
1204
|
1204
|
);
|
1205
|
|
-$row = $result->fetch_hash_all;
|
|
1205
|
+$row = $result->all;
|
1206
|
1206
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1207
|
1207
|
|
1208
|
1208
|
$where = $dbi->where
|
...
|
...
|
@@ -1212,7 +1212,7 @@ $result = $dbi->select(
|
1212
|
1212
|
table => 'table1',
|
1213
|
1213
|
where => $where,
|
1214
|
1214
|
);
|
1215
|
|
-$row = $result->fetch_hash_all;
|
|
1215
|
+$row = $result->all;
|
1216
|
1216
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1217
|
1217
|
|
1218
|
1218
|
$where = $dbi->where
|
...
|
...
|
@@ -1222,7 +1222,7 @@ $result = $dbi->select(
|
1222
|
1222
|
table => 'table1',
|
1223
|
1223
|
where => $where,
|
1224
|
1224
|
);
|
1225
|
|
-$row = $result->fetch_hash_all;
|
|
1225
|
+$row = $result->all;
|
1226
|
1226
|
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
|
1227
|
1227
|
|
1228
|
1228
|
$where = $dbi->where
|
...
|
...
|
@@ -1232,7 +1232,7 @@ $result = $dbi->select(
|
1232
|
1232
|
table => 'table1',
|
1233
|
1233
|
where => $where,
|
1234
|
1234
|
);
|
1235
|
|
-$row = $result->fetch_hash_all;
|
|
1235
|
+$row = $result->all;
|
1236
|
1236
|
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
|
1237
|
1237
|
|
1238
|
1238
|
$where = $dbi->where
|
...
|
...
|
@@ -1242,7 +1242,7 @@ $result = $dbi->select(
|
1242
|
1242
|
table => 'table1',
|
1243
|
1243
|
where => $where,
|
1244
|
1244
|
);
|
1245
|
|
-$row = $result->fetch_hash_all;
|
|
1245
|
+$row = $result->all;
|
1246
|
1246
|
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
|
1247
|
1247
|
|
1248
|
1248
|
$where = $dbi->where
|
...
|
...
|
@@ -1252,7 +1252,7 @@ $result = $dbi->select(
|
1252
|
1252
|
table => 'table1',
|
1253
|
1253
|
where => $where,
|
1254
|
1254
|
);
|
1255
|
|
-$row = $result->fetch_hash_all;
|
|
1255
|
+$row = $result->all;
|
1256
|
1256
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1257
|
1257
|
|
1258
|
1258
|
$where = $dbi->where
|
...
|
...
|
@@ -1262,7 +1262,7 @@ $result = $dbi->select(
|
1262
|
1262
|
table => 'table1',
|
1263
|
1263
|
where => $where,
|
1264
|
1264
|
);
|
1265
|
|
-$row = $result->fetch_hash_all;
|
|
1265
|
+$row = $result->all;
|
1266
|
1266
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1267
|
1267
|
|
1268
|
1268
|
$where = $dbi->where
|
...
|
...
|
@@ -1272,7 +1272,7 @@ $result = $dbi->select(
|
1272
|
1272
|
table => 'table1',
|
1273
|
1273
|
where => $where,
|
1274
|
1274
|
);
|
1275
|
|
-$row = $result->fetch_hash_all;
|
|
1275
|
+$row = $result->all;
|
1276
|
1276
|
is_deeply($row, [{key1 => 3, key2 => 4}], 'not_exists');
|
1277
|
1277
|
|
1278
|
1278
|
$where = $dbi->where
|
...
|
...
|
@@ -1282,7 +1282,7 @@ $result = $dbi->select(
|
1282
|
1282
|
table => 'table1',
|
1283
|
1283
|
where => $where,
|
1284
|
1284
|
);
|
1285
|
|
-$row = $result->fetch_hash_all;
|
|
1285
|
+$row = $result->all;
|
1286
|
1286
|
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
|
1287
|
1287
|
|
1288
|
1288
|
$where = $dbi->where
|
...
|
...
|
@@ -1292,7 +1292,7 @@ $result = $dbi->select(
|
1292
|
1292
|
table => 'table1',
|
1293
|
1293
|
where => $where,
|
1294
|
1294
|
);
|
1295
|
|
-$row = $result->fetch_hash_all;
|
|
1295
|
+$row = $result->all;
|
1296
|
1296
|
is_deeply($row, [{key1 => 1, key2 => 2},{key1 => 3, key2 => 4}], 'not_exists');
|
1297
|
1297
|
|
1298
|
1298
|
$where = $dbi->where
|
...
|
...
|
@@ -1302,7 +1302,7 @@ $result = $dbi->select(
|
1302
|
1302
|
table => 'table1',
|
1303
|
1303
|
where => $where,
|
1304
|
1304
|
);
|
1305
|
|
-$row = $result->fetch_hash_all;
|
|
1305
|
+$row = $result->all;
|
1306
|
1306
|
is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
|
1307
|
1307
|
|
1308
|
1308
|
$where = $dbi->where
|
...
|
...
|
@@ -1311,7 +1311,7 @@ $result = $dbi->select(
|
1311
|
1311
|
table => 'table1',
|
1312
|
1312
|
where => $where,
|
1313
|
1313
|
);
|
1314
|
|
-$row = $result->fetch_hash_all;
|
|
1314
|
+$row = $result->all;
|
1315
|
1315
|
is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
|
1316
|
1316
|
|
1317
|
1317
|
eval {$dbi->where(ppp => 1) };
|
...
|
...
|
@@ -1364,7 +1364,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
1364
|
1364
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
1365
|
1365
|
$dbi->apply_filter('table1', 'key2',
|
1366
|
1366
|
{in => sub { $_[0] * 3 }, out => sub { $_[0] * 2 }});
|
1367
|
|
-$rows = $dbi->select(table => 'table1', where => {key2 => 1})->fetch_hash_all;
|
|
1367
|
+$rows = $dbi->select(table => 'table1', where => {key2 => 1})->all;
|
1368
|
1368
|
is_deeply($rows, [{key1 => 1, key2 => 6}]);
|
1369
|
1369
|
|
1370
|
1370
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -1372,7 +1372,7 @@ $dbi->execute($CREATE_TABLE->{0});
|
1372
|
1372
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
1373
|
1373
|
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
1374
|
1374
|
$dbi->apply_filter('table1', 'key2', {});
|
1375
|
|
-$rows = $dbi->select(table => 'table1', where => {key2 => 2})->fetch_hash_all;
|
|
1375
|
+$rows = $dbi->select(table => 'table1', where => {key2 => 2})->all;
|
1376
|
1376
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
1377
|
1377
|
|
1378
|
1378
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -1475,11 +1475,11 @@ $dbi = MyDBI1->connect($NEW_ARGS->{0});
|
1475
|
1475
|
$dbi->execute("create table book (title, author)");
|
1476
|
1476
|
$model = $dbi->model('book');
|
1477
|
1477
|
$model->insert({title => 'a', author => 'b'});
|
1478
|
|
-is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
|
|
1478
|
+is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
|
1479
|
1479
|
$dbi->execute("create table company (name)");
|
1480
|
1480
|
$model = $dbi->model('company');
|
1481
|
1481
|
$model->insert({name => 'a'});
|
1482
|
|
-is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
|
|
1482
|
+is_deeply($model->list->all, [{name => 'a'}], 'basic');
|
1483
|
1483
|
is($dbi->models->{'book'}, $dbi->model('book'));
|
1484
|
1484
|
is($dbi->models->{'company'}, $dbi->model('company'));
|
1485
|
1485
|
|
...
|
...
|
@@ -1543,11 +1543,11 @@ $dbi = MyDBI4->connect($NEW_ARGS->{0});
|
1543
|
1543
|
$dbi->execute("create table book (title, author)");
|
1544
|
1544
|
$model = $dbi->model('book');
|
1545
|
1545
|
$model->insert({title => 'a', author => 'b'});
|
1546
|
|
-is_deeply($model->list->fetch_hash_all, [{title => 'a', author => 'b'}], 'basic');
|
|
1546
|
+is_deeply($model->list->all, [{title => 'a', author => 'b'}], 'basic');
|
1547
|
1547
|
$dbi->execute("create table company (name)");
|
1548
|
1548
|
$model = $dbi->model('company');
|
1549
|
1549
|
$model->insert({name => 'a'});
|
1550
|
|
-is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic');
|
|
1550
|
+is_deeply($model->list->all, [{name => 'a'}], 'basic');
|
1551
|
1551
|
|
1552
|
1552
|
{
|
1553
|
1553
|
package MyDBI5;
|
...
|
...
|
@@ -1568,10 +1568,10 @@ $dbi->execute("create table company (name)");
|
1568
|
1568
|
$dbi->execute("create table table1 (key1)");
|
1569
|
1569
|
$model = $dbi->model('company');
|
1570
|
1570
|
$model->insert({name => 'a'});
|
1571
|
|
-is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
|
|
1571
|
+is_deeply($model->list->all, [{name => 'a'}], 'include all model');
|
1572
|
1572
|
$dbi->insert(table => 'table1', param => {key1 => 1});
|
1573
|
1573
|
$model = $dbi->model('book');
|
1574
|
|
-is_deeply($model->list->fetch_hash_all, [{key1 => 1}], 'include all model');
|
|
1574
|
+is_deeply($model->list->all, [{key1 => 1}], 'include all model');
|
1575
|
1575
|
|
1576
|
1576
|
test 'primary_key';
|
1577
|
1577
|
use MyDBI1;
|
...
|
...
|
@@ -1606,7 +1606,7 @@ $dbi->delete_at(
|
1606
|
1606
|
primary_key => ['key1', 'key2'],
|
1607
|
1607
|
where => [1, 2],
|
1608
|
1608
|
);
|
1609
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
1609
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
1610
|
1610
|
|
1611
|
1611
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
1612
|
1612
|
$dbi->delete_at(
|
...
|
...
|
@@ -1614,7 +1614,7 @@ $dbi->delete_at(
|
1614
|
1614
|
primary_key => 'key1',
|
1615
|
1615
|
where => 1,
|
1616
|
1616
|
);
|
1617
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
1617
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
1618
|
1618
|
|
1619
|
1619
|
test 'insert_at';
|
1620
|
1620
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -1804,13 +1804,13 @@ $dbi->execute("create table table2 (key1, key2, key3)");
|
1804
|
1804
|
$dbi->execute("create table table3 (key1, key2, key3)");
|
1805
|
1805
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
1806
|
1806
|
$dbi->model('table1')->delete_at(where => [1, 2]);
|
1807
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
1807
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
1808
|
1808
|
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
|
1809
|
1809
|
$dbi->model('table1_1')->delete_at(where => [1, 2]);
|
1810
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
1810
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
1811
|
1811
|
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
|
1812
|
1812
|
$dbi->model('table1_3')->delete_at(where => [1, 2]);
|
1813
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
1813
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
1814
|
1814
|
|
1815
|
1815
|
test 'model insert_at';
|
1816
|
1816
|
$dbi = MyDBI6->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -1893,7 +1893,7 @@ where key1 = 1
|
1893
|
1893
|
EOS
|
1894
|
1894
|
$dbi->execute($sql, param => $param);
|
1895
|
1895
|
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
|
1896
|
|
-$rows = $result->fetch_hash_all;
|
|
1896
|
+$rows = $result->all;
|
1897
|
1897
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
1898
|
1898
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
1899
|
1899
|
"basic");
|
...
|
...
|
@@ -1912,7 +1912,7 @@ where key1 = 1
|
1912
|
1912
|
EOS
|
1913
|
1913
|
$dbi->execute($sql, param => $param);
|
1914
|
1914
|
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
|
1915
|
|
-$rows = $result->fetch_hash_all;
|
|
1915
|
+$rows = $result->all;
|
1916
|
1916
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
1917
|
1917
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
1918
|
1918
|
"basic");
|
...
|
...
|
@@ -1930,7 +1930,7 @@ where key1 = 1
|
1930
|
1930
|
EOS
|
1931
|
1931
|
$dbi->execute($sql, param => $param);
|
1932
|
1932
|
$result = $dbi->execute($SELECT_SOURCES->{0}, table => 'table1');
|
1933
|
|
-$rows = $result->fetch_hash_all;
|
|
1933
|
+$rows = $result->all;
|
1934
|
1934
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
1935
|
1935
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
1936
|
1936
|
"update param no_set");
|
...
|
...
|
@@ -1954,7 +1954,7 @@ where key1 = 1
|
1954
|
1954
|
EOS
|
1955
|
1955
|
$dbi->execute($sql, param => $param, table => 'table1');
|
1956
|
1956
|
$result = $dbi->execute($SELECT_SOURCES->{0});
|
1957
|
|
-$rows = $result->fetch_hash_all;
|
|
1957
|
+$rows = $result->all;
|
1958
|
1958
|
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
1959
|
1959
|
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
1960
|
1960
|
"basic");
|
...
|
...
|
@@ -2002,14 +2002,14 @@ $rows = $dbi->select(
|
2002
|
2002
|
column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3',
|
2003
|
2003
|
where => {'table1.key2' => 2},
|
2004
|
2004
|
join => ['left outer join table2 on table1.key1 = table2.key1']
|
2005
|
|
-)->fetch_hash_all;
|
|
2005
|
+)->all;
|
2006
|
2006
|
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}]);
|
2007
|
2007
|
|
2008
|
2008
|
$rows = $dbi->select(
|
2009
|
2009
|
table => 'table1',
|
2010
|
2010
|
where => {'key1' => 1},
|
2011
|
2011
|
join => ['left outer join table2 on table1.key1 = table2.key1']
|
2012
|
|
-)->fetch_hash_all;
|
|
2012
|
+)->all;
|
2013
|
2013
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
2014
|
2014
|
|
2015
|
2015
|
eval {
|
...
|
...
|
@@ -2027,7 +2027,7 @@ $rows = $dbi->select(
|
2027
|
2027
|
where => {'key1' => 1},
|
2028
|
2028
|
join => ['left outer join table2 on table1.key1 = table2.key1',
|
2029
|
2029
|
'left outer join table3 on table2.key3 = table3.key3']
|
2030
|
|
-)->fetch_hash_all;
|
|
2030
|
+)->all;
|
2031
|
2031
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
2032
|
2032
|
|
2033
|
2033
|
$rows = $dbi->select(
|
...
|
...
|
@@ -2036,7 +2036,7 @@ $rows = $dbi->select(
|
2036
|
2036
|
where => {'table1.key1' => 1},
|
2037
|
2037
|
join => ['left outer join table2 on table1.key1 = table2.key1',
|
2038
|
2038
|
'left outer join table3 on table2.key3 = table3.key3']
|
2039
|
|
-)->fetch_hash_all;
|
|
2039
|
+)->all;
|
2040
|
2040
|
is_deeply($rows, [{table3__key4 => 4}]);
|
2041
|
2041
|
|
2042
|
2042
|
$rows = $dbi->select(
|
...
|
...
|
@@ -2045,7 +2045,7 @@ $rows = $dbi->select(
|
2045
|
2045
|
where => {'table3.key4' => 4},
|
2046
|
2046
|
join => ['left outer join table2 on table1.key1 = table2.key1',
|
2047
|
2047
|
'left outer join table3 on table2.key3 = table3.key3']
|
2048
|
|
-)->fetch_hash_all;
|
|
2048
|
+)->all;
|
2049
|
2049
|
is_deeply($rows, [{table1__key1 => 1}]);
|
2050
|
2050
|
|
2051
|
2051
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
...
|
...
|
@@ -2059,7 +2059,7 @@ $rows = $dbi->select(
|
2059
|
2059
|
column => '"table1"."key1" as "table1_key1", "table2"."key1" as "table2_key1", "key2", "key3"',
|
2060
|
2060
|
where => {'table1.key2' => 2},
|
2061
|
2061
|
join => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'],
|
2062
|
|
-)->fetch_hash_all;
|
|
2062
|
+)->all;
|
2063
|
2063
|
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
|
2064
|
2064
|
'reserved_word_quote');
|
2065
|
2065
|
|
...
|
...
|
@@ -2094,7 +2094,7 @@ $rows = $dbi->select(
|
2094
|
2094
|
table => 'table1',
|
2095
|
2095
|
column => 'latest_table1.key1 as latest_table1__key1',
|
2096
|
2096
|
join => $join
|
2097
|
|
-)->fetch_hash_all;
|
|
2097
|
+)->all;
|
2098
|
2098
|
is_deeply($rows, [{latest_table1__key1 => 1}]);
|
2099
|
2099
|
|
2100
|
2100
|
test 'mycolumn';
|
...
|
...
|
@@ -2288,7 +2288,7 @@ $rows = $dbi->select(
|
2288
|
2288
|
join => ['inner join (select * from table2 where {= table2.key3})' .
|
2289
|
2289
|
' as table2 on table1.key1 = table2.key1'],
|
2290
|
2290
|
param => {'table2.key3' => 5}
|
2291
|
|
-)->fetch_hash_all;
|
|
2291
|
+)->all;
|
2292
|
2292
|
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
|
2293
|
2293
|
|
2294
|
2294
|
|
...
|
...
|
@@ -2301,7 +2301,7 @@ $rows = $dbi->select(
|
2301
|
2301
|
table => 'table1',
|
2302
|
2302
|
column => 'key1',
|
2303
|
2303
|
wrap => ['select * from (', ') as t where key1 = 1']
|
2304
|
|
-)->fetch_hash_all;
|
|
2304
|
+)->all;
|
2305
|
2305
|
is_deeply($rows, [{key1 => 1}]);
|
2306
|
2306
|
|
2307
|
2307
|
eval {
|
...
|
...
|
@@ -2322,7 +2322,7 @@ $rows = $dbi->select(
|
2322
|
2322
|
table => 'table1',
|
2323
|
2323
|
where => '{= key1} and {= key2}',
|
2324
|
2324
|
where_param => {key1 => 1, key2 => 2}
|
2325
|
|
-)->fetch_hash_all;
|
|
2325
|
+)->all;
|
2326
|
2326
|
is_deeply($rows, [{key1 => 1, key2 => 2}]);
|
2327
|
2327
|
|
2328
|
2328
|
test 'delete() string where';
|
...
|
...
|
@@ -2335,7 +2335,7 @@ $dbi->delete(
|
2335
|
2335
|
where => '{= key1} and {= key2}',
|
2336
|
2336
|
where_param => {key1 => 1, key2 => 2}
|
2337
|
2337
|
);
|
2338
|
|
-$rows = $dbi->select(table => 'table1')->fetch_hash_all;
|
|
2338
|
+$rows = $dbi->select(table => 'table1')->all;
|
2339
|
2339
|
is_deeply($rows, [{key1 => 2, key2 => 3}]);
|
2340
|
2340
|
|
2341
|
2341
|
|
...
|
...
|
@@ -2349,7 +2349,7 @@ $dbi->update(
|
2349
|
2349
|
where => '{= key1} and {= key2}',
|
2350
|
2350
|
where_param => {key1 => 1, key2 => 2}
|
2351
|
2351
|
);
|
2352
|
|
-$rows = $dbi->select(table => 'table1')->fetch_hash_all;
|
|
2352
|
+$rows = $dbi->select(table => 'table1')->all;
|
2353
|
2353
|
is_deeply($rows, [{key1 => 5, key2 => 2}]);
|
2354
|
2354
|
|
2355
|
2355
|
|
...
|
...
|
@@ -2481,7 +2481,7 @@ $dbi->delete(
|
2481
|
2481
|
primary_key => ['key1', 'key2'],
|
2482
|
2482
|
id => [1, 2],
|
2483
|
2483
|
);
|
2484
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
2484
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
2485
|
2485
|
|
2486
|
2486
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
2487
|
2487
|
$dbi->delete(
|
...
|
...
|
@@ -2489,7 +2489,7 @@ $dbi->delete(
|
2489
|
2489
|
primary_key => 'key1',
|
2490
|
2490
|
id => 1,
|
2491
|
2491
|
);
|
2492
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
2492
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
2493
|
2493
|
|
2494
|
2494
|
|
2495
|
2495
|
test 'model delete and id option';
|
...
|
...
|
@@ -2499,13 +2499,13 @@ $dbi->execute("create table table2 (key1, key2, key3)");
|
2499
|
2499
|
$dbi->execute("create table table3 (key1, key2, key3)");
|
2500
|
2500
|
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
2501
|
2501
|
$dbi->model('table1')->delete(id => [1, 2]);
|
2502
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
2502
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
2503
|
2503
|
$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
|
2504
|
2504
|
$dbi->model('table1_1')->delete(id => [1, 2]);
|
2505
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
2505
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
2506
|
2506
|
$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
|
2507
|
2507
|
$dbi->model('table1_3')->delete(id => [1, 2]);
|
2508
|
|
-is_deeply($dbi->select(table => 'table1')->fetch_hash_all, []);
|
|
2508
|
+is_deeply($dbi->select(table => 'table1')->all, []);
|
2509
|
2509
|
|
2510
|
2510
|
|
2511
|
2511
|
test 'select and id option';
|
...
|
...
|
@@ -2809,4 +2809,12 @@ test 'available_date_type';
|
2809
|
2809
|
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
2810
|
2810
|
ok($dbi->can('available_data_type'));
|
2811
|
2811
|
|
|
2812
|
+
|
|
2813
|
+test 'select prefix option';
|
|
2814
|
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
|
2815
|
+$dbi->execute($CREATE_TABLE->{0});
|
|
2816
|
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
2817
|
+$rows = $dbi->select(prefix => 'key1,', column => 'key2', table => 'table1')->all;
|
|
2818
|
+is_deeply($rows, [{key1 => 1, key2 => 2}], "table");
|
|
2819
|
+
|
2812
|
2820
|
=cut
|