...
|
...
|
@@ -3378,64 +3378,53 @@ is($result->one->{key1}, 'A');
|
3378
|
3378
|
|
3379
|
3379
|
test 'order';
|
3380
|
3380
|
$dbi = DBIx::Custom->connect(%memory);
|
3381
|
|
-{
|
3382
|
|
- $dbi->execute("create table table1 (key1, key2)");
|
3383
|
|
- $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
|
3384
|
|
- $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
|
3385
|
|
- $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
|
3386
|
|
- $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
|
3387
|
|
- my $order = $dbi->order;
|
3388
|
|
- $order->prepend('key1', 'key2 desc');
|
3389
|
|
- $result = $dbi->select(table => 'table1', append => "$order");
|
3390
|
|
- is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
|
3391
|
|
- {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
|
3392
|
|
- $order->prepend('key1 desc');
|
3393
|
|
- $result = $dbi->select(table => 'table1', append => "$order");
|
3394
|
|
- is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
|
3395
|
|
- {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
|
3396
|
|
-
|
3397
|
|
- $order = $dbi->order;
|
3398
|
|
- $order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
|
3399
|
|
- $result = $dbi->select(table => 'table1',
|
3400
|
|
- column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
|
3401
|
|
- append => "$order");
|
3402
|
|
- is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
|
3403
|
|
- {'table1-key1' => 1, 'table1-key2' => 1},
|
3404
|
|
- {'table1-key1' => 2, 'table1-key2' => 4},
|
3405
|
|
- {'table1-key1' => 2, 'table1-key2' => 2}]);
|
3406
|
|
-}
|
|
3381
|
+$dbi->execute("create table table1 (key1, key2)");
|
|
3382
|
+$dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
|
|
3383
|
+$dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
|
|
3384
|
+$dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
|
|
3385
|
+$dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
|
|
3386
|
+my $order = $dbi->order;
|
|
3387
|
+$order->prepend('key1', 'key2 desc');
|
|
3388
|
+$result = $dbi->select(table => 'table1', append => "$order");
|
|
3389
|
+is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
|
|
3390
|
+ {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
|
|
3391
|
+$order->prepend('key1 desc');
|
|
3392
|
+$result = $dbi->select(table => 'table1', append => "$order");
|
|
3393
|
+is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
|
|
3394
|
+ {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
|
|
3395
|
+
|
|
3396
|
+$order = $dbi->order;
|
|
3397
|
+$order->prepend(['table1-key1'], [qw/table1-key2 desc/]);
|
|
3398
|
+$result = $dbi->select(table => 'table1',
|
|
3399
|
+ column => [[key1 => 'table1-key1'], [key2 => 'table1-key2']],
|
|
3400
|
+ append => "$order");
|
|
3401
|
+is_deeply($result->all, [{'table1-key1' => 1, 'table1-key2' => 3},
|
|
3402
|
+ {'table1-key1' => 1, 'table1-key2' => 1},
|
|
3403
|
+ {'table1-key1' => 2, 'table1-key2' => 4},
|
|
3404
|
+ {'table1-key1' => 2, 'table1-key2' => 2}]);
|
3407
|
3405
|
|
3408
|
3406
|
test 'tag_parse';
|
3409
|
3407
|
$dbi = DBIx::Custom->connect(%memory);
|
3410
|
3408
|
$dbi->tag_parse(0);
|
3411
|
|
-{
|
3412
|
|
- $dbi->execute("create table table1 (key1, key2)");
|
3413
|
|
- $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
|
3414
|
|
- eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
|
3415
|
|
- ok($@);
|
3416
|
|
-}
|
|
3409
|
+$dbi->execute("create table table1 (key1, key2)");
|
|
3410
|
+$dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
|
|
3411
|
+eval {$dbi->execute("select * from table1 where {= key1}", {key1 => 1})};
|
|
3412
|
+ok($@);
|
3417
|
3413
|
|
3418
|
3414
|
test 'last_sql';
|
3419
|
|
-{
|
3420
|
|
- my $dbi = DBIx::Custom->connect(%memory);
|
3421
|
|
- $dbi->execute("create table table1 (key1, key2)");
|
3422
|
|
- $dbi->execute('select * from table1');
|
3423
|
|
- is($dbi->last_sql, 'select * from table1;');
|
3424
|
|
-
|
3425
|
|
- eval{$dbi->execute("aaa")};
|
3426
|
|
- is($dbi->last_sql, 'aaa;');
|
3427
|
|
-
|
3428
|
|
-}
|
|
3415
|
+$dbi = DBIx::Custom->connect(%memory);
|
|
3416
|
+$dbi->execute("create table table1 (key1, key2)");
|
|
3417
|
+$dbi->execute('select * from table1');
|
|
3418
|
+is($dbi->last_sql, 'select * from table1;');
|
|
3419
|
+
|
|
3420
|
+eval{$dbi->execute("aaa")};
|
|
3421
|
+is($dbi->last_sql, 'aaa;');
|
3429
|
3422
|
|
3430
|
3423
|
test 'DBIx::Custom header';
|
3431
|
|
-{
|
3432
|
|
- my $dbi = DBIx::Custom->connect(%memory);
|
3433
|
|
- $dbi->execute("create table table1 (key1, key2)");
|
3434
|
|
- my $result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
|
3435
|
|
-
|
3436
|
|
- is_deeply($result->header, [qw/h1 h2/]);
|
3437
|
|
-
|
3438
|
|
-}
|
|
3424
|
+$dbi = DBIx::Custom->connect(%memory);
|
|
3425
|
+$dbi->execute("create table table1 (key1, key2)");
|
|
3426
|
+$result = $dbi->execute('select key1 as h1, key2 as h2 from table1');
|
|
3427
|
+is_deeply($result->header, [qw/h1 h2/]);
|
3439
|
3428
|
|
3440
|
3429
|
test 'Named placeholder :name(operater) syntax';
|
3441
|
3430
|
$dbi->execute('drop table table1');
|