| ... | ... |
@@ -15,9 +15,12 @@ use DBIx::Custom; |
| 15 | 15 |
has user => 'dbix_custom'; |
| 16 | 16 |
has password => 'dbix_custom'; |
| 17 | 17 |
|
| 18 |
- sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
|
|
| 18 |
+ sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255)) engine=InnoDB;' }
|
|
| 19 | 19 |
sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '
|
| 20 |
- . 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' } |
|
| 20 |
+ . 'key3 varchar(255), key4 varchar(255), key5 varchar(255)) engine=InnoDB;' } |
|
| 21 |
+ sub create_table2 { 'create table table2 (key1 varchar(255), key3 varchar(255)) engine=InnoDB;' }
|
|
| 22 |
+ sub create_table_reserved {
|
|
| 23 |
+ 'create table `table` (`select` varchar(255), `update` varchar(255)) engine=InnoDB;' } |
|
| 21 | 24 |
} |
| 22 | 25 |
|
| 23 | 26 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -17,6 +17,8 @@ use DBIx::Custom; |
| 17 | 17 |
sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
|
| 18 | 18 |
sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '
|
| 19 | 19 |
. 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' } |
| 20 |
+ sub create_table2 { 'create table table2 (key1 varchar(255), key3 varchar(255));' }
|
|
| 21 |
+ sub create_table_reserved { 'create table "table" ("select" varchar(255), "update" varchar(255))' }
|
|
| 20 | 22 |
} |
| 21 | 23 |
|
| 22 | 24 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -12,6 +12,8 @@ use DBIx::Custom; |
| 12 | 12 |
sub quote { '""' }
|
| 13 | 13 |
sub create_table1 { 'create table table1 (key1, key2);' }
|
| 14 | 14 |
sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
|
| 15 |
+ sub create_table2 { 'create table table2 (key1, key3);' }
|
|
| 16 |
+ sub create_table_reserved { 'create table "table" ("select", "update")' }
|
|
| 15 | 17 |
} |
| 16 | 18 |
|
| 17 | 19 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -11,6 +11,8 @@ use DBIx::Custom; |
| 11 | 11 |
has dsn => 'dbi:SQLite:dbname=:memory:'; |
| 12 | 12 |
sub create_table1 { 'create table table1 (key1, key2);' }
|
| 13 | 13 |
sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
|
| 14 |
+ sub create_table2 { 'create table table2 (key1, key3);' }
|
|
| 15 |
+ sub create_table_reserved { 'create table "table" ("select", "update")' }
|
|
| 14 | 16 |
} |
| 15 | 17 |
|
| 16 | 18 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -18,6 +18,8 @@ sub test { print "# $_[0]\n" }
|
| 18 | 18 |
# Constant |
| 19 | 19 |
my $create_table1 = $dbi->create_table1; |
| 20 | 20 |
my $create_table1_2 = $dbi->create_table1_2; |
| 21 |
+my $create_table2 = $dbi->create_table2; |
|
| 22 |
+my $create_table_reserved = $dbi->create_table_reserved; |
|
| 21 | 23 |
my $q = substr($dbi->quote, 0, 1); |
| 22 | 24 |
my $p = substr($dbi->quote, 1, 1) || $q; |
| 23 | 25 |
|
| ... | ... |
@@ -281,14 +283,13 @@ like($@, qr/noexist/, "invalid"); |
| 281 | 283 |
eval{$dbi->insert(table => 'table', param => {';' => 1})};
|
| 282 | 284 |
like($@, qr/safety/); |
| 283 | 285 |
|
| 284 |
-$dbi->quote('"');
|
|
| 285 | 286 |
eval { $dbi->execute("drop table ${q}table$p") };
|
| 286 |
-$dbi->execute("create table ${q}table$p (${q}select$p)");
|
|
| 287 |
+$dbi->execute($create_table_reserved); |
|
| 287 | 288 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
| 288 | 289 |
$dbi->insert(table => 'table', param => {select => 1});
|
| 289 | 290 |
$result = $dbi->execute("select * from ${q}table$p");
|
| 290 | 291 |
$rows = $result->all; |
| 291 |
-is_deeply($rows, [{select => 2}], "reserved word");
|
|
| 292 |
+is_deeply($rows, [{select => 2, update => undef}], "reserved word");
|
|
| 292 | 293 |
|
| 293 | 294 |
eval { $dbi->execute('drop table table1') };
|
| 294 | 295 |
$dbi->execute($create_table1); |
| ... | ... |
@@ -298,14 +299,6 @@ $result = $dbi->execute('select * from table1;');
|
| 298 | 299 |
$rows = $result->all; |
| 299 | 300 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
| 300 | 301 |
|
| 301 |
-eval { $dbi->execute('drop table table1') };
|
|
| 302 |
-$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 303 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 304 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
|
|
| 305 |
-$result = $dbi->execute('select * from table1;');
|
|
| 306 |
-$rows = $result->all; |
|
| 307 |
-is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 308 |
- |
|
| 309 | 302 |
eval { $dbi->execute('drop table table1') };
|
| 310 | 303 |
$dbi->execute($create_table1); |
| 311 | 304 |
$dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
|
| ... | ... |
@@ -320,7 +313,7 @@ $dbi->execute($create_table1_2); |
| 320 | 313 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 321 | 314 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 322 | 315 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1});
|
| 323 |
-$result = $dbi->execute('select * from table1;');
|
|
| 316 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 324 | 317 |
$rows = $result->all; |
| 325 | 318 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
| 326 | 319 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -330,14 +323,14 @@ $dbi->execute("delete from table1");
|
| 330 | 323 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 331 | 324 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 332 | 325 |
$dbi->update(table => 'table1', param => {key2 => 12}, where => {key2 => 2, key3 => 3});
|
| 333 |
-$result = $dbi->execute('select * from table1;');
|
|
| 326 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 334 | 327 |
$rows = $result->all; |
| 335 | 328 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
| 336 | 329 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| 337 | 330 |
"update key same as search key"); |
| 338 | 331 |
|
| 339 | 332 |
$dbi->update(table => 'table1', param => {key2 => [12]}, where => {key2 => 2, key3 => 3});
|
| 340 |
-$result = $dbi->execute('select * from table1;');
|
|
| 333 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 341 | 334 |
$rows = $result->all; |
| 342 | 335 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
| 343 | 336 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -349,7 +342,7 @@ $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4
|
| 349 | 342 |
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
| 350 | 343 |
$dbi->update(table => 'table1', param => {key2 => 11}, where => {key1 => 1},
|
| 351 | 344 |
filter => {key2 => sub { $_[0] * 2 }});
|
| 352 |
-$result = $dbi->execute('select * from table1;');
|
|
| 345 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 353 | 346 |
$rows = $result->all; |
| 354 | 347 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
|
| 355 | 348 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -404,9 +397,8 @@ eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1}
|
| 404 | 397 |
like($@, qr/safety/); |
| 405 | 398 |
|
| 406 | 399 |
eval { $dbi->execute('drop table table1') };
|
| 407 |
-$dbi->quote('"');
|
|
| 408 | 400 |
eval { $dbi->execute("drop table ${q}table$p") };
|
| 409 |
-$dbi->execute("create table ${q}table$p (${q}select$p, ${q}update$p)");
|
|
| 401 |
+$dbi->execute($create_table_reserved); |
|
| 410 | 402 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
| 411 | 403 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
|
| 412 | 404 |
$dbi->insert(table => 'table', param => {select => 1});
|
| ... | ... |
@@ -419,8 +411,7 @@ eval {$dbi->update_all(table => 'table', param => {';' => 2}) };
|
| 419 | 411 |
like($@, qr/safety/); |
| 420 | 412 |
|
| 421 | 413 |
eval { $dbi->execute("drop table ${q}table$p") };
|
| 422 |
-$dbi->reserved_word_quote('"');
|
|
| 423 |
-$dbi->execute("create table ${q}table$p (${q}select$p, ${q}update$p)");
|
|
| 414 |
+$dbi->execute($create_table_reserved); |
|
| 424 | 415 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
| 425 | 416 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
|
| 426 | 417 |
$dbi->insert(table => 'table', param => {select => 1});
|
| ... | ... |
@@ -434,27 +425,18 @@ $dbi->execute($create_table1_2); |
| 434 | 425 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 435 | 426 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 436 | 427 |
$dbi->update({key2 => 11}, table => 'table1', where => {key1 => 1});
|
| 437 |
-$result = $dbi->execute('select * from table1;');
|
|
| 428 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 438 | 429 |
$rows = $result->all; |
| 439 | 430 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
| 440 | 431 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| 441 | 432 |
"basic"); |
| 442 | 433 |
|
| 443 |
-eval { $dbi->execute('drop table table1') };
|
|
| 444 |
-$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 445 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 446 |
-$dbi->update(table => 'table1', param => {key2 => 4},
|
|
| 447 |
- where => {key1 => 1}, prefix => 'or replace');
|
|
| 448 |
-$result = $dbi->execute('select * from table1;');
|
|
| 449 |
-$rows = $result->all; |
|
| 450 |
-is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 451 |
- |
|
| 452 | 434 |
eval { $dbi->execute('drop table table1') };
|
| 453 | 435 |
$dbi->execute($create_table1_2); |
| 454 | 436 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 455 | 437 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 456 | 438 |
$dbi->update(table => 'table1', param => {key2 => \"'11'"}, where => {key1 => 1});
|
| 457 |
-$result = $dbi->execute('select * from table1;');
|
|
| 439 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 458 | 440 |
$rows = $result->all; |
| 459 | 441 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
| 460 | 442 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -531,7 +513,7 @@ $result = $dbi->select(table => 'table1'); |
| 531 | 513 |
is_deeply($result->all, [{key1 => 3, key2 => 4}], 'delete() where');
|
| 532 | 514 |
|
| 533 | 515 |
eval { $dbi->execute('drop table table1') };
|
| 534 |
-$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 516 |
+$dbi->execute($create_table1); |
|
| 535 | 517 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 536 | 518 |
$dbi->delete(table => 'table1', where => {key1 => 1}, prefix => ' ');
|
| 537 | 519 |
$result = $dbi->execute('select * from table1;');
|
| ... | ... |
@@ -549,9 +531,8 @@ eval{$dbi->delete(table => 'table1', where => {';' => 1})};
|
| 549 | 531 |
like($@, qr/safety/); |
| 550 | 532 |
|
| 551 | 533 |
$dbi = DBIx::Custom->connect; |
| 552 |
-$dbi->quote('"');
|
|
| 553 | 534 |
eval { $dbi->execute("drop table ${q}table$p") };
|
| 554 |
-$dbi->execute("create table ${q}table$p (${q}select$p, ${q}update$p)");
|
|
| 535 |
+$dbi->execute($create_table_reserved); |
|
| 555 | 536 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
| 556 | 537 |
$dbi->insert(table => 'table', param => {select => 1});
|
| 557 | 538 |
$dbi->delete(table => 'table', where => {select => 1});
|
| ... | ... |
@@ -596,7 +577,8 @@ $rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 =>
|
| 596 | 577 |
->all; |
| 597 | 578 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
|
| 598 | 579 |
|
| 599 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 580 |
+eval { $dbi->execute("drop table table2") };
|
|
| 581 |
+$dbi->execute($create_table2); |
|
| 600 | 582 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| 601 | 583 |
$rows = $dbi->select( |
| 602 | 584 |
table => [qw/table1 table2/], |
| ... | ... |
@@ -617,8 +599,8 @@ eval{$dbi->select(table => 'table1', noexist => 1)};
|
| 617 | 599 |
like($@, qr/noexist/, "invalid"); |
| 618 | 600 |
|
| 619 | 601 |
$dbi = DBIx::Custom->connect; |
| 620 |
-$dbi->quote('"');
|
|
| 621 |
-$dbi->execute("create table ${q}table$p (${q}select$p, ${q}update$p)");
|
|
| 602 |
+eval { $dbi->execute("drop table ${q}table$p") };
|
|
| 603 |
+$dbi->execute($create_table_reserved); |
|
| 622 | 604 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
| 623 | 605 |
$dbi->insert(table => 'table', param => {select => 1, update => 2});
|
| 624 | 606 |
$result = $dbi->select(table => 'table', where => {select => 1});
|
| ... | ... |
@@ -27,6 +27,9 @@ sub test { print "# $_[0]\n" }
|
| 27 | 27 |
# Constant |
| 28 | 28 |
my $create_table1 = 'create table table1 (key1 char(255), key2 char(255));'; |
| 29 | 29 |
my $create_table1_2 = 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));'; |
| 30 |
+my $create_table2 = 'create table table2 (key1 char(255), key3 char(255));'; |
|
| 31 |
+my $create_table_reserved = 'create table "table" ("select", "update")';
|
|
| 32 |
+ |
|
| 30 | 33 |
my $q = '"'; |
| 31 | 34 |
my $p = '"'; |
| 32 | 35 |
|
| ... | ... |
@@ -65,6 +68,72 @@ my $binary; |
| 65 | 68 |
# Prepare table |
| 66 | 69 |
$dbi = DBIx::Custom->connect; |
| 67 | 70 |
|
| 71 |
+test 'insert'; |
|
| 72 |
+eval { $dbi->execute('drop table table1') };
|
|
| 73 |
+$dbi->execute($create_table1); |
|
| 74 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 75 |
+$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
|
| 76 |
+$result = $dbi->execute('select * from table1;');
|
|
| 77 |
+$rows = $result->all; |
|
| 78 |
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
|
| 79 |
+ |
|
| 80 |
+$dbi->execute('delete from table1');
|
|
| 81 |
+$dbi->register_filter( |
|
| 82 |
+ twice => sub { $_[0] * 2 },
|
|
| 83 |
+ three_times => sub { $_[0] * 3 }
|
|
| 84 |
+); |
|
| 85 |
+$dbi->default_bind_filter('twice');
|
|
| 86 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, filter => {key1 => 'three_times'});
|
|
| 87 |
+$result = $dbi->execute('select * from table1;');
|
|
| 88 |
+$rows = $result->all; |
|
| 89 |
+is_deeply($rows, [{key1 => 3, key2 => 4}], "filter");
|
|
| 90 |
+$dbi->default_bind_filter(undef); |
|
| 91 |
+ |
|
| 92 |
+$dbi->execute('drop table table1');
|
|
| 93 |
+$dbi->execute($create_table1); |
|
| 94 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, append => ' ');
|
|
| 95 |
+$rows = $dbi->select(table => 'table1')->all; |
|
| 96 |
+is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
|
|
| 97 |
+ |
|
| 98 |
+eval{$dbi->insert(table => 'table1', noexist => 1)};
|
|
| 99 |
+like($@, qr/noexist/, "invalid"); |
|
| 100 |
+ |
|
| 101 |
+eval{$dbi->insert(table => 'table', param => {';' => 1})};
|
|
| 102 |
+like($@, qr/safety/); |
|
| 103 |
+ |
|
| 104 |
+$dbi->quote('"');
|
|
| 105 |
+eval { $dbi->execute("drop table ${q}table$p") };
|
|
| 106 |
+$dbi->execute("create table ${q}table$p (${q}select$p)");
|
|
| 107 |
+$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
|
| 108 |
+$dbi->insert(table => 'table', param => {select => 1});
|
|
| 109 |
+$result = $dbi->execute("select * from ${q}table$p");
|
|
| 110 |
+$rows = $result->all; |
|
| 111 |
+is_deeply($rows, [{select => 2}], "reserved word");
|
|
| 112 |
+ |
|
| 113 |
+eval { $dbi->execute('drop table table1') };
|
|
| 114 |
+$dbi->execute($create_table1); |
|
| 115 |
+$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
|
|
| 116 |
+$dbi->insert({key1 => 3, key2 => 4}, table => 'table1');
|
|
| 117 |
+$result = $dbi->execute('select * from table1;');
|
|
| 118 |
+$rows = $result->all; |
|
| 119 |
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
|
| 120 |
+ |
|
| 121 |
+eval { $dbi->execute('drop table table1') };
|
|
| 122 |
+$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 123 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 124 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
|
|
| 125 |
+$result = $dbi->execute('select * from table1;');
|
|
| 126 |
+$rows = $result->all; |
|
| 127 |
+is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 128 |
+ |
|
| 129 |
+eval { $dbi->execute('drop table table1') };
|
|
| 130 |
+$dbi->execute($create_table1); |
|
| 131 |
+$dbi->insert(table => 'table1', param => {key1 => \"'1'", key2 => 2});
|
|
| 132 |
+$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
|
| 133 |
+$result = $dbi->execute('select * from table1;');
|
|
| 134 |
+$rows = $result->all; |
|
| 135 |
+is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "basic");
|
|
| 136 |
+ |
|
| 68 | 137 |
test 'update'; |
| 69 | 138 |
eval { $dbi->execute('drop table table1') };
|
| 70 | 139 |
$dbi->execute($create_table1_2); |
| ... | ... |
@@ -347,7 +416,7 @@ $rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 =>
|
| 347 | 416 |
->all; |
| 348 | 417 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "filter");
|
| 349 | 418 |
|
| 350 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 419 |
+$dbi->execute($create_table2); |
|
| 351 | 420 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| 352 | 421 |
$rows = $dbi->select( |
| 353 | 422 |
table => [qw/table1 table2/], |
| ... | ... |
@@ -633,7 +702,7 @@ is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
|
| 633 | 702 |
$dbi = DBIx::Custom->connect; |
| 634 | 703 |
eval { $dbi->execute('drop table table1') };
|
| 635 | 704 |
$dbi->execute($create_table1); |
| 636 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 705 |
+$dbi->execute($create_table2); |
|
| 637 | 706 |
$dbi->register_filter(twice => sub { $_[0] * 2 });
|
| 638 | 707 |
$dbi->register_filter(three_times => sub { $_[0] * 3 });
|
| 639 | 708 |
$dbi->apply_filter( |
| ... | ... |
@@ -666,7 +735,7 @@ test 'each_column'; |
| 666 | 735 |
$dbi = DBIx::Custom->connect; |
| 667 | 736 |
eval { $dbi->execute('drop table table1') };
|
| 668 | 737 |
eval { $dbi->execute('drop table table2') };
|
| 669 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 738 |
+$dbi->execute($create_table2); |
|
| 670 | 739 |
$dbi->execute('create table table1 (key1 Date, key2 datetime);');
|
| 671 | 740 |
|
| 672 | 741 |
$infos = []; |
| ... | ... |
@@ -692,7 +761,7 @@ test 'each_table'; |
| 692 | 761 |
$dbi = DBIx::Custom->connect; |
| 693 | 762 |
eval { $dbi->execute('drop table table1') };
|
| 694 | 763 |
eval { $dbi->execute('drop table table2') };
|
| 695 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 764 |
+$dbi->execute($create_table2); |
|
| 696 | 765 |
$dbi->execute('create table table1 (key1 Date, key2 datetime);');
|
| 697 | 766 |
|
| 698 | 767 |
$infos = []; |
| ... | ... |
@@ -1905,7 +1974,7 @@ $dbi = MyDBI7->connect; |
| 1905 | 1974 |
eval { $dbi->execute('drop table table1') };
|
| 1906 | 1975 |
eval { $dbi->execute('drop table table2') };
|
| 1907 | 1976 |
$dbi->execute($create_table1); |
| 1908 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 1977 |
+$dbi->execute($create_table2); |
|
| 1909 | 1978 |
$dbi->separator('__');
|
| 1910 | 1979 |
$dbi->setup_model; |
| 1911 | 1980 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| ... | ... |
@@ -2039,7 +2108,7 @@ eval { $dbi->execute('drop table table1') };
|
| 2039 | 2108 |
$dbi->execute($create_table1); |
| 2040 | 2109 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2041 | 2110 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
| 2042 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2111 |
+$dbi->execute($create_table2); |
|
| 2043 | 2112 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| 2044 | 2113 |
$dbi->execute('create table table3 (key3 int, key4 int);');
|
| 2045 | 2114 |
$dbi->insert(table => 'table3', param => {key3 => 5, key4 => 4});
|
| ... | ... |
@@ -2099,7 +2168,7 @@ $dbi->quote('"');
|
| 2099 | 2168 |
eval { $dbi->execute('drop table table1') };
|
| 2100 | 2169 |
$dbi->execute($create_table1); |
| 2101 | 2170 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2102 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2171 |
+$dbi->execute($create_table2); |
|
| 2103 | 2172 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| 2104 | 2173 |
$rows = $dbi->select( |
| 2105 | 2174 |
table => 'table1', |
| ... | ... |
@@ -2149,7 +2218,7 @@ $dbi = DBIx::Custom->connect; |
| 2149 | 2218 |
eval { $dbi->execute('drop table table1') };
|
| 2150 | 2219 |
eval { $dbi->execute('drop table table2') };
|
| 2151 | 2220 |
$dbi->execute($create_table1); |
| 2152 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2221 |
+$dbi->execute($create_table2); |
|
| 2153 | 2222 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2154 | 2223 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
|
| 2155 | 2224 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| ... | ... |
@@ -2181,7 +2250,7 @@ $dbi = DBIx::Custom->connect; |
| 2181 | 2250 |
eval { $dbi->execute('drop table table1') };
|
| 2182 | 2251 |
eval { $dbi->execute('drop table table2') };
|
| 2183 | 2252 |
$dbi->execute($create_table1); |
| 2184 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2253 |
+$dbi->execute($create_table2); |
|
| 2185 | 2254 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2186 | 2255 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
|
| 2187 | 2256 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5});
|
| ... | ... |
@@ -2202,7 +2271,7 @@ $dbi = MyDBI8->connect; |
| 2202 | 2271 |
eval { $dbi->execute('drop table table1') };
|
| 2203 | 2272 |
eval { $dbi->execute('drop table table2') };
|
| 2204 | 2273 |
$dbi->execute($create_table1); |
| 2205 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2274 |
+$dbi->execute($create_table2); |
|
| 2206 | 2275 |
$dbi->setup_model; |
| 2207 | 2276 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2208 | 2277 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
| ... | ... |
@@ -2276,7 +2345,7 @@ test 'column table option'; |
| 2276 | 2345 |
$dbi = MyDBI9->connect; |
| 2277 | 2346 |
eval { $dbi->execute('drop table table1') };
|
| 2278 | 2347 |
$dbi->execute($create_table1); |
| 2279 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2348 |
+$dbi->execute($create_table2); |
|
| 2280 | 2349 |
$dbi->setup_model; |
| 2281 | 2350 |
$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
|
| 2282 | 2351 |
$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
|
| ... | ... |
@@ -2384,7 +2453,7 @@ $dbi = DBIx::Custom->connect; |
| 2384 | 2453 |
eval { $dbi->execute('drop table table1') };
|
| 2385 | 2454 |
eval { $dbi->execute('drop table table2') };
|
| 2386 | 2455 |
$dbi->execute($create_table1); |
| 2387 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2456 |
+$dbi->execute($create_table2); |
|
| 2388 | 2457 |
|
| 2389 | 2458 |
$dbi->create_model( |
| 2390 | 2459 |
table => 'table1', |
| ... | ... |
@@ -2418,7 +2487,7 @@ test 'model method'; |
| 2418 | 2487 |
test 'create_model'; |
| 2419 | 2488 |
$dbi = DBIx::Custom->connect; |
| 2420 | 2489 |
eval { $dbi->execute('drop table table2') };
|
| 2421 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2490 |
+$dbi->execute($create_table2); |
|
| 2422 | 2491 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
| 2423 | 2492 |
$model = $dbi->create_model( |
| 2424 | 2493 |
table => 'table2' |
| ... | ... |
@@ -2449,7 +2518,7 @@ eval { $dbi->execute('drop table table1') };
|
| 2449 | 2518 |
$dbi->execute($create_table1); |
| 2450 | 2519 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2451 | 2520 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
|
| 2452 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2521 |
+$dbi->execute($create_table2); |
|
| 2453 | 2522 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4});
|
| 2454 | 2523 |
$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5});
|
| 2455 | 2524 |
$rows = $dbi->select( |
| ... | ... |
@@ -2792,7 +2861,7 @@ $dbi = MyDBI7->connect; |
| 2792 | 2861 |
eval { $dbi->execute('drop table table1') };
|
| 2793 | 2862 |
eval { $dbi->execute('drop table table2') };
|
| 2794 | 2863 |
$dbi->execute($create_table1); |
| 2795 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2864 |
+$dbi->execute($create_table2); |
|
| 2796 | 2865 |
$dbi->setup_model; |
| 2797 | 2866 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2798 | 2867 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
| ... | ... |
@@ -2818,7 +2887,7 @@ $dbi = DBIx::Custom->connect; |
| 2818 | 2887 |
eval { $dbi->execute('drop table table1') };
|
| 2819 | 2888 |
eval { $dbi->execute('drop table table2') };
|
| 2820 | 2889 |
$dbi->execute($create_table1); |
| 2821 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2890 |
+$dbi->execute($create_table2); |
|
| 2822 | 2891 |
|
| 2823 | 2892 |
$dbi->create_model( |
| 2824 | 2893 |
table => 'table1', |
| ... | ... |
@@ -2877,7 +2946,7 @@ $dbi = DBIx::Custom->connect; |
| 2877 | 2946 |
eval { $dbi->execute('drop table table1') };
|
| 2878 | 2947 |
eval { $dbi->execute('drop table table2') };
|
| 2879 | 2948 |
$dbi->execute($create_table1); |
| 2880 |
-$dbi->execute('create table table2 (key1 char(255), key3 char(255));');
|
|
| 2949 |
+$dbi->execute($create_table2); |
|
| 2881 | 2950 |
|
| 2882 | 2951 |
$dbi->create_model( |
| 2883 | 2952 |
table => 'table1', |
| ... | ... |
@@ -3769,3 +3838,49 @@ $result = $dbi->select(table => 'table1'); |
| 3769 | 3838 |
is($result->type_rule2_off->fetch_first->[0], '1bd'); |
| 3770 | 3839 |
$result = $dbi->select(table => 'table1'); |
| 3771 | 3840 |
is($result->type_rule2_on->fetch_first->[0], '1bde'); |
| 3841 |
+ |
|
| 3842 |
+test 'prefix'; |
|
| 3843 |
+$dbi = DBIx::Custom->connect; |
|
| 3844 |
+eval { $dbi->execute('drop table table1') };
|
|
| 3845 |
+$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 3846 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 3847 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4}, prefix => 'or replace');
|
|
| 3848 |
+$result = $dbi->execute('select * from table1;');
|
|
| 3849 |
+$rows = $result->all; |
|
| 3850 |
+is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 3851 |
+ |
|
| 3852 |
+$dbi = DBIx::Custom->connect; |
|
| 3853 |
+eval { $dbi->execute('drop table table1') };
|
|
| 3854 |
+$dbi->execute("create table table1 (key1 char(255), key2 char(255), primary key(key1))");
|
|
| 3855 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 3856 |
+$dbi->update(table => 'table1', param => {key2 => 4},
|
|
| 3857 |
+ where => {key1 => 1}, prefix => 'or replace');
|
|
| 3858 |
+$result = $dbi->execute('select * from table1;');
|
|
| 3859 |
+$rows = $result->all; |
|
| 3860 |
+is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 3861 |
+ |
|
| 3862 |
+ |
|
| 3863 |
+test 'reserved_word_quote'; |
|
| 3864 |
+$dbi = DBIx::Custom->connect; |
|
| 3865 |
+eval { $dbi->execute("drop table ${q}table$p") };
|
|
| 3866 |
+$dbi->reserved_word_quote('"');
|
|
| 3867 |
+$dbi->execute($create_table_reserved); |
|
| 3868 |
+$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
|
| 3869 |
+$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}});
|
|
| 3870 |
+$dbi->insert(table => 'table', param => {select => 1});
|
|
| 3871 |
+$dbi->update(table => 'table', where => {'table.select' => 1}, param => {update => 2});
|
|
| 3872 |
+$result = $dbi->execute("select * from ${q}table$p");
|
|
| 3873 |
+$rows = $result->all; |
|
| 3874 |
+is_deeply($rows, [{select => 2, update => 6}], "reserved word");
|
|
| 3875 |
+ |
|
| 3876 |
+test 'quote'; |
|
| 3877 |
+$dbi = DBIx::Custom->connect; |
|
| 3878 |
+$dbi->quote('"');
|
|
| 3879 |
+eval { $dbi->execute("drop table ${q}table$p") };
|
|
| 3880 |
+$dbi->execute($create_table_reserved); |
|
| 3881 |
+$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}});
|
|
| 3882 |
+$dbi->insert(table => 'table', param => {select => 1});
|
|
| 3883 |
+$dbi->delete(table => 'table', where => {select => 1});
|
|
| 3884 |
+$result = $dbi->execute("select * from ${q}table$p");
|
|
| 3885 |
+$rows = $result->all; |
|
| 3886 |
+is_deeply($rows, [], "reserved word"); |