|
28 | 28 | import io.vertx.ext.unit.TestContext; |
29 | 29 | import org.junit.Test; |
30 | 30 |
|
| 31 | +import java.util.Arrays; |
31 | 32 | import java.util.List; |
32 | 33 |
|
33 | 34 | public abstract class SQLTestBase extends AbstractTestBase { |
@@ -459,6 +460,94 @@ public void testDateValueSelection(TestContext context) { |
459 | 460 | }); |
460 | 461 | } |
461 | 462 |
|
| 463 | + protected abstract String createByteArray1TableColumn(); |
| 464 | + protected abstract String createByteArray2TableColumn(); |
| 465 | + protected abstract String createByteArray3TableColumn(); |
| 466 | + protected abstract String[] insertByteArray1Values(); |
| 467 | + protected abstract String[] insertByteArray2Values(); |
| 468 | + protected abstract String[] insertByteArray3Values(); |
| 469 | + |
| 470 | + @Test |
| 471 | + public void testByteA1Fields(TestContext context) { |
| 472 | + Async async = context.async(); |
| 473 | + client.getConnection(arConn -> { |
| 474 | + ensureSuccess(context, arConn); |
| 475 | + conn = arConn.result(); |
| 476 | + conn.execute("DROP TABLE IF EXISTS test_table", arDrop -> { |
| 477 | + ensureSuccess(context, arDrop); |
| 478 | + conn.execute("CREATE TABLE test_table (id INT, some_bit " + createByteArray1TableColumn() + ")", arCreate -> { |
| 479 | + ensureSuccess(context, arCreate); |
| 480 | + String[] s = insertByteArray1Values(); |
| 481 | + conn.execute("INSERT INTO test_table (id, some_bit) VALUES (1, " + s[0] + "),(2, " + s[1] + "),(3, " + s[2] + ")", arInsert -> { |
| 482 | + ensureSuccess(context, arInsert); |
| 483 | + conn.query("SELECT some_bit FROM test_table ORDER BY id", arQuery -> { |
| 484 | + ensureSuccess(context, arQuery); |
| 485 | + ResultSet res = arQuery.result(); |
| 486 | + context.assertTrue(Arrays.equals(new byte[]{0b1}, res.getRows().get(0).getBinary("some_bit"))); |
| 487 | + context.assertTrue(Arrays.equals(new byte[]{0b0}, res.getResults().get(1).getBinary(0))); |
| 488 | + context.assertTrue(Arrays.equals(new byte[]{0b1}, res.getRows().get(2).getBinary("some_bit"))); |
| 489 | + async.complete(); |
| 490 | + }); |
| 491 | + }); |
| 492 | + }); |
| 493 | + }); |
| 494 | + }); |
| 495 | + } |
| 496 | + |
| 497 | + @Test |
| 498 | + public void testByteA2Fields(TestContext context) { |
| 499 | + Async async = context.async(); |
| 500 | + client.getConnection(arConn -> { |
| 501 | + ensureSuccess(context, arConn); |
| 502 | + conn = arConn.result(); |
| 503 | + conn.execute("DROP TABLE IF EXISTS test_table", arDrop -> { |
| 504 | + ensureSuccess(context, arDrop); |
| 505 | + conn.execute("CREATE TABLE test_table (id INT, some_bit " + createByteArray2TableColumn() + ")", arCreate -> { |
| 506 | + ensureSuccess(context, arCreate); |
| 507 | + String[] s = insertByteArray2Values(); |
| 508 | + conn.execute("INSERT INTO test_table (id, some_bit) VALUES (1, " + s[0] + "),(2, " + s[1] + "),(3, " + s[2] + ")", arInsert -> { |
| 509 | + ensureSuccess(context, arInsert); |
| 510 | + conn.query("SELECT some_bit FROM test_table ORDER BY id", arQuery -> { |
| 511 | + ensureSuccess(context, arQuery); |
| 512 | + ResultSet res = arQuery.result(); |
| 513 | + context.assertTrue(Arrays.equals(new byte[]{0b10}, res.getRows().get(0).getBinary("some_bit"))); |
| 514 | + context.assertTrue(Arrays.equals(new byte[]{0b01}, res.getResults().get(1).getBinary(0))); |
| 515 | + context.assertTrue(Arrays.equals(new byte[]{0b11}, res.getRows().get(2).getBinary("some_bit"))); |
| 516 | + async.complete(); |
| 517 | + }); |
| 518 | + }); |
| 519 | + }); |
| 520 | + }); |
| 521 | + }); |
| 522 | + } |
| 523 | + |
| 524 | + @Test |
| 525 | + public void testByteA3Fields(TestContext context) { |
| 526 | + Async async = context.async(); |
| 527 | + client.getConnection(arConn -> { |
| 528 | + ensureSuccess(context, arConn); |
| 529 | + conn = arConn.result(); |
| 530 | + conn.execute("DROP TABLE IF EXISTS test_table", arDrop -> { |
| 531 | + ensureSuccess(context, arDrop); |
| 532 | + conn.execute("CREATE TABLE test_table (id INT, some_bit " + createByteArray3TableColumn() + ")", arCreate -> { |
| 533 | + ensureSuccess(context, arCreate); |
| 534 | + String[] s = insertByteArray3Values(); |
| 535 | + conn.execute("INSERT INTO test_table (id, some_bit) VALUES (1, " + s[0] + "),(2, " + s[1] + "),(3, " + s[2] + ")", arInsert -> { |
| 536 | + ensureSuccess(context, arInsert); |
| 537 | + conn.query("SELECT some_bit FROM test_table ORDER BY id", arQuery -> { |
| 538 | + ensureSuccess(context, arQuery); |
| 539 | + ResultSet res = arQuery.result(); |
| 540 | + context.assertTrue(Arrays.equals(new byte[]{0b1, 0b0}, res.getRows().get(0).getBinary("some_bit"))); |
| 541 | + context.assertTrue(Arrays.equals(new byte[]{0b0, 0b1}, res.getResults().get(1).getBinary(0))); |
| 542 | + context.assertTrue(Arrays.equals(new byte[]{0b1, 0b1}, res.getRows().get(2).getBinary("some_bit"))); |
| 543 | + async.complete(); |
| 544 | + }); |
| 545 | + }); |
| 546 | + }); |
| 547 | + }); |
| 548 | + }); |
| 549 | + } |
| 550 | + |
462 | 551 | protected void setSqlModeIfPossible(Handler<Void> handler) { |
463 | 552 | handler.handle(null); |
464 | 553 | } |
|
0 commit comments