Showing 2 changed files with 199 additions and 199 deletions
+199
t/common.t
... ...
@@ -2335,6 +2335,205 @@ is($dbi->select(table => 'table1')->one->{key1}, 1);
2335 2335
 is($dbi->select(table => 'table1')->one->{key2}, 2);
2336 2336
 is($dbi->select(table => 'table1')->one->{key3}, 3);
2337 2337
 
2338
+test 'model insert id and primary_key option';
2339
+$dbi = MyDBI6->connect;
2340
+eval { $dbi->execute('drop table table1') };
2341
+$dbi->execute($create_table1_2);
2342
+$dbi->model('table1')->insert(
2343
+    id => [1, 2],
2344
+    param => {key3 => 3}
2345
+);
2346
+$result = $dbi->model('table1')->select;
2347
+$row = $result->one;
2348
+is($row->{key1}, 1);
2349
+is($row->{key2}, 2);
2350
+is($row->{key3}, 3);
2351
+
2352
+$dbi = MyDBI6->connect;
2353
+eval { $dbi->execute('drop table table1') };
2354
+$dbi->execute($create_table1_2);
2355
+$dbi->model('table1')->insert(
2356
+    {key3 => 3},
2357
+    id => [1, 2]
2358
+);
2359
+$result = $dbi->model('table1')->select;
2360
+$row = $result->one;
2361
+is($row->{key1}, 1);
2362
+is($row->{key2}, 2);
2363
+is($row->{key3}, 3);
2364
+
2365
+test 'update and id option';
2366
+$dbi = DBIx::Custom->connect;
2367
+eval { $dbi->execute('drop table table1') };
2368
+$dbi->execute($create_table1_2);
2369
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2370
+$dbi->update(
2371
+    table => 'table1',
2372
+    primary_key => ['key1', 'key2'],
2373
+    id => [1, 2],
2374
+    param => {key3 => 4}
2375
+);
2376
+is($dbi->select(table => 'table1')->one->{key1}, 1);
2377
+is($dbi->select(table => 'table1')->one->{key2}, 2);
2378
+is($dbi->select(table => 'table1')->one->{key3}, 4);
2379
+
2380
+$dbi->delete_all(table => 'table1');
2381
+$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
2382
+$dbi->update(
2383
+    table => 'table1',
2384
+    primary_key => 'key1',
2385
+    id => 0,
2386
+    param => {key3 => 4}
2387
+);
2388
+is($dbi->select(table => 'table1')->one->{key1}, 0);
2389
+is($dbi->select(table => 'table1')->one->{key2}, 2);
2390
+is($dbi->select(table => 'table1')->one->{key3}, 4);
2391
+
2392
+$dbi = DBIx::Custom->connect;
2393
+eval { $dbi->execute('drop table table1') };
2394
+$dbi->execute($create_table1_2);
2395
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2396
+$dbi->update(
2397
+    {key3 => 4},
2398
+    table => 'table1',
2399
+    primary_key => ['key1', 'key2'],
2400
+    id => [1, 2]
2401
+);
2402
+is($dbi->select(table => 'table1')->one->{key1}, 1);
2403
+is($dbi->select(table => 'table1')->one->{key2}, 2);
2404
+is($dbi->select(table => 'table1')->one->{key3}, 4);
2405
+
2406
+
2407
+test 'model update and id option';
2408
+$dbi = MyDBI6->connect;
2409
+eval { $dbi->execute('drop table table1') };
2410
+$dbi->execute($create_table1_2);
2411
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2412
+$dbi->model('table1')->update(
2413
+    id => [1, 2],
2414
+    param => {key3 => 4}
2415
+);
2416
+$result = $dbi->model('table1')->select;
2417
+$row = $result->one;
2418
+is($row->{key1}, 1);
2419
+is($row->{key2}, 2);
2420
+is($row->{key3}, 4);
2421
+
2422
+
2423
+test 'delete and id option';
2424
+$dbi = DBIx::Custom->connect;
2425
+eval { $dbi->execute('drop table table1') };
2426
+$dbi->execute($create_table1_2);
2427
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2428
+$dbi->delete(
2429
+    table => 'table1',
2430
+    primary_key => ['key1', 'key2'],
2431
+    id => [1, 2],
2432
+);
2433
+is_deeply($dbi->select(table => 'table1')->all, []);
2434
+
2435
+$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
2436
+$dbi->delete(
2437
+    table => 'table1',
2438
+    primary_key => 'key1',
2439
+    id => 0,
2440
+);
2441
+is_deeply($dbi->select(table => 'table1')->all, []);
2442
+
2443
+
2444
+test 'model delete and id option';
2445
+$dbi = MyDBI6->connect;
2446
+eval { $dbi->execute('drop table table1') };
2447
+eval { $dbi->execute('drop table table2') };
2448
+eval { $dbi->execute('drop table table3') };
2449
+$dbi->execute($create_table1_2);
2450
+$dbi->execute($create_table2_2);
2451
+$dbi->execute($create_table3);
2452
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2453
+$dbi->model('table1')->delete(id => [1, 2]);
2454
+is_deeply($dbi->select(table => 'table1')->all, []);
2455
+$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
2456
+$dbi->model('table1_1')->delete(id => [1, 2]);
2457
+is_deeply($dbi->select(table => 'table1')->all, []);
2458
+$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
2459
+$dbi->model('table1_3')->delete(id => [1, 2]);
2460
+is_deeply($dbi->select(table => 'table1')->all, []);
2461
+
2462
+
2463
+test 'select and id option';
2464
+$dbi = DBIx::Custom->connect;
2465
+eval { $dbi->execute('drop table table1') };
2466
+$dbi->execute($create_table1_2);
2467
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2468
+$result = $dbi->select(
2469
+    table => 'table1',
2470
+    primary_key => ['key1', 'key2'],
2471
+    id => [1, 2]
2472
+);
2473
+$row = $result->one;
2474
+is($row->{key1}, 1);
2475
+is($row->{key2}, 2);
2476
+is($row->{key3}, 3);
2477
+
2478
+$dbi->delete_all(table => 'table1');
2479
+$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
2480
+$result = $dbi->select(
2481
+    table => 'table1',
2482
+    primary_key => 'key1',
2483
+    id => 0,
2484
+);
2485
+$row = $result->one;
2486
+is($row->{key1}, 0);
2487
+is($row->{key2}, 2);
2488
+is($row->{key3}, 3);
2489
+
2490
+$dbi->delete_all(table => 'table1');
2491
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2492
+$result = $dbi->select(
2493
+    table => 'table1',
2494
+    primary_key => ['key1', 'key2'],
2495
+    id => [1, 2]
2496
+);
2497
+$row = $result->one;
2498
+is($row->{key1}, 1);
2499
+is($row->{key2}, 2);
2500
+is($row->{key3}, 3);
2501
+
2502
+
2503
+test 'model select_at';
2504
+$dbi = MyDBI6->connect;
2505
+eval { $dbi->execute('drop table table1') };
2506
+$dbi->execute($create_table1_2);
2507
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
2508
+$result = $dbi->model('table1')->select(id => [1, 2]);
2509
+$row = $result->one;
2510
+is($row->{key1}, 1);
2511
+is($row->{key2}, 2);
2512
+is($row->{key3}, 3);
2513
+
2514
+test 'column separator is default .';
2515
+$dbi = MyDBI7->connect;
2516
+eval { $dbi->execute('drop table table1') };
2517
+eval { $dbi->execute('drop table table2') };
2518
+$dbi->execute($create_table1);
2519
+$dbi->execute($create_table2);
2520
+$dbi->setup_model;
2521
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2522
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
2523
+$model = $dbi->model('table1');
2524
+$result = $model->select(
2525
+    column => [$model->column('table2')],
2526
+    where => {'table1.key1' => 1}
2527
+);
2528
+is_deeply($result->one,
2529
+          {'table2.key1' => 1, 'table2.key3' => 3});
2530
+
2531
+$result = $model->select(
2532
+    column => [$model->column('table2' => [qw/key1 key3/])],
2533
+    where => {'table1.key1' => 1}
2534
+);
2535
+is_deeply($result->one,
2536
+          {'table2.key1' => 1, 'table2.key3' => 3});
2338 2537
 
2339 2538
 
2340 2539
 
-199
t/sqlite.t
... ...
@@ -198,205 +198,6 @@ $dbi = DBIx::Custom->connect;
198 198
 
199 199
 
200 200
 
201
-test 'model insert id and primary_key option';
202
-$dbi = MyDBI6->connect;
203
-eval { $dbi->execute('drop table table1') };
204
-$dbi->execute($create_table1_2);
205
-$dbi->model('table1')->insert(
206
-    id => [1, 2],
207
-    param => {key3 => 3}
208
-);
209
-$result = $dbi->model('table1')->select;
210
-$row = $result->one;
211
-is($row->{key1}, 1);
212
-is($row->{key2}, 2);
213
-is($row->{key3}, 3);
214
-
215
-$dbi = MyDBI6->connect;
216
-eval { $dbi->execute('drop table table1') };
217
-$dbi->execute($create_table1_2);
218
-$dbi->model('table1')->insert(
219
-    {key3 => 3},
220
-    id => [1, 2]
221
-);
222
-$result = $dbi->model('table1')->select;
223
-$row = $result->one;
224
-is($row->{key1}, 1);
225
-is($row->{key2}, 2);
226
-is($row->{key3}, 3);
227
-
228
-test 'update and id option';
229
-$dbi = DBIx::Custom->connect;
230
-eval { $dbi->execute('drop table table1') };
231
-$dbi->execute($create_table1_2);
232
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
233
-$dbi->update(
234
-    table => 'table1',
235
-    primary_key => ['key1', 'key2'],
236
-    id => [1, 2],
237
-    param => {key3 => 4}
238
-);
239
-is($dbi->select(table => 'table1')->one->{key1}, 1);
240
-is($dbi->select(table => 'table1')->one->{key2}, 2);
241
-is($dbi->select(table => 'table1')->one->{key3}, 4);
242
-
243
-$dbi->delete_all(table => 'table1');
244
-$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
245
-$dbi->update(
246
-    table => 'table1',
247
-    primary_key => 'key1',
248
-    id => 0,
249
-    param => {key3 => 4}
250
-);
251
-is($dbi->select(table => 'table1')->one->{key1}, 0);
252
-is($dbi->select(table => 'table1')->one->{key2}, 2);
253
-is($dbi->select(table => 'table1')->one->{key3}, 4);
254
-
255
-$dbi = DBIx::Custom->connect;
256
-eval { $dbi->execute('drop table table1') };
257
-$dbi->execute($create_table1_2);
258
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
259
-$dbi->update(
260
-    {key3 => 4},
261
-    table => 'table1',
262
-    primary_key => ['key1', 'key2'],
263
-    id => [1, 2]
264
-);
265
-is($dbi->select(table => 'table1')->one->{key1}, 1);
266
-is($dbi->select(table => 'table1')->one->{key2}, 2);
267
-is($dbi->select(table => 'table1')->one->{key3}, 4);
268
-
269
-
270
-test 'model update and id option';
271
-$dbi = MyDBI6->connect;
272
-eval { $dbi->execute('drop table table1') };
273
-$dbi->execute($create_table1_2);
274
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
275
-$dbi->model('table1')->update(
276
-    id => [1, 2],
277
-    param => {key3 => 4}
278
-);
279
-$result = $dbi->model('table1')->select;
280
-$row = $result->one;
281
-is($row->{key1}, 1);
282
-is($row->{key2}, 2);
283
-is($row->{key3}, 4);
284
-
285
-
286
-test 'delete and id option';
287
-$dbi = DBIx::Custom->connect;
288
-eval { $dbi->execute('drop table table1') };
289
-$dbi->execute($create_table1_2);
290
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
291
-$dbi->delete(
292
-    table => 'table1',
293
-    primary_key => ['key1', 'key2'],
294
-    id => [1, 2],
295
-);
296
-is_deeply($dbi->select(table => 'table1')->all, []);
297
-
298
-$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
299
-$dbi->delete(
300
-    table => 'table1',
301
-    primary_key => 'key1',
302
-    id => 0,
303
-);
304
-is_deeply($dbi->select(table => 'table1')->all, []);
305
-
306
-
307
-test 'model delete and id option';
308
-$dbi = MyDBI6->connect;
309
-eval { $dbi->execute('drop table table1') };
310
-eval { $dbi->execute('drop table table2') };
311
-eval { $dbi->execute('drop table table3') };
312
-$dbi->execute($create_table1_2);
313
-$dbi->execute($create_table2_2);
314
-$dbi->execute($create_table3);
315
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
316
-$dbi->model('table1')->delete(id => [1, 2]);
317
-is_deeply($dbi->select(table => 'table1')->all, []);
318
-$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
319
-$dbi->model('table1_1')->delete(id => [1, 2]);
320
-is_deeply($dbi->select(table => 'table1')->all, []);
321
-$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
322
-$dbi->model('table1_3')->delete(id => [1, 2]);
323
-is_deeply($dbi->select(table => 'table1')->all, []);
324
-
325
-
326
-test 'select and id option';
327
-$dbi = DBIx::Custom->connect;
328
-eval { $dbi->execute('drop table table1') };
329
-$dbi->execute($create_table1_2);
330
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
331
-$result = $dbi->select(
332
-    table => 'table1',
333
-    primary_key => ['key1', 'key2'],
334
-    id => [1, 2]
335
-);
336
-$row = $result->one;
337
-is($row->{key1}, 1);
338
-is($row->{key2}, 2);
339
-is($row->{key3}, 3);
340
-
341
-$dbi->delete_all(table => 'table1');
342
-$dbi->insert(table => 'table1', param => {key1 => 0, key2 => 2, key3 => 3});
343
-$result = $dbi->select(
344
-    table => 'table1',
345
-    primary_key => 'key1',
346
-    id => 0,
347
-);
348
-$row = $result->one;
349
-is($row->{key1}, 0);
350
-is($row->{key2}, 2);
351
-is($row->{key3}, 3);
352
-
353
-$dbi->delete_all(table => 'table1');
354
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
355
-$result = $dbi->select(
356
-    table => 'table1',
357
-    primary_key => ['key1', 'key2'],
358
-    id => [1, 2]
359
-);
360
-$row = $result->one;
361
-is($row->{key1}, 1);
362
-is($row->{key2}, 2);
363
-is($row->{key3}, 3);
364
-
365
-
366
-test 'model select_at';
367
-$dbi = MyDBI6->connect;
368
-eval { $dbi->execute('drop table table1') };
369
-$dbi->execute($create_table1_2);
370
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
371
-$result = $dbi->model('table1')->select(id => [1, 2]);
372
-$row = $result->one;
373
-is($row->{key1}, 1);
374
-is($row->{key2}, 2);
375
-is($row->{key3}, 3);
376
-
377
-test 'column separator is default .';
378
-$dbi = MyDBI7->connect;
379
-eval { $dbi->execute('drop table table1') };
380
-eval { $dbi->execute('drop table table2') };
381
-$dbi->execute($create_table1);
382
-$dbi->execute($create_table2);
383
-$dbi->setup_model;
384
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
385
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
386
-$model = $dbi->model('table1');
387
-$result = $model->select(
388
-    column => [$model->column('table2')],
389
-    where => {'table1.key1' => 1}
390
-);
391
-is_deeply($result->one,
392
-          {'table2.key1' => 1, 'table2.key3' => 3});
393
-
394
-$result = $model->select(
395
-    column => [$model->column('table2' => [qw/key1 key3/])],
396
-    where => {'table1.key1' => 1}
397
-);
398
-is_deeply($result->one,
399
-          {'table2.key1' => 1, 'table2.key3' => 3});
400 201
 
401 202
 
402 203