|
16 | 16 | import org.slf4j.LoggerFactory; |
17 | 17 |
|
18 | 18 | import tech.ydb.common.transaction.TxMode; |
| 19 | +import tech.ydb.core.Issue; |
19 | 20 | import tech.ydb.core.Result; |
20 | 21 | import tech.ydb.core.Status; |
21 | 22 | import tech.ydb.core.StatusCode; |
@@ -519,4 +520,52 @@ public void testMultiStatement() { |
519 | 520 | } |
520 | 521 | } |
521 | 522 | } |
| 523 | + |
| 524 | + @Test |
| 525 | + public void testNoTxStatement() { |
| 526 | + try (QueryClient client = QueryClient.newClient(ydbTransport).build()) { |
| 527 | + try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) { |
| 528 | + String query = "" |
| 529 | + + "DECLARE $s1 AS Int32;" |
| 530 | + + "DECLARE $s2 AS Int32;" |
| 531 | + + "DECLARE $id1 AS Int32;" |
| 532 | + + "DECLARE $id2 AS Int32;" |
| 533 | + + "DECLARE $name1 AS Text;" |
| 534 | + + "DECLARE $name2 AS Text;" |
| 535 | + + "SELECT * FROM `" + TEST_TABLE + "` WHERE id = $s1;" |
| 536 | + + "INSERT INTO `" + TEST_TABLE + "` (id, name) VALUES ($id1, $name1);" |
| 537 | + + "SELECT * FROM `" + TEST_TABLE + "` WHERE id = $s2;" |
| 538 | + + "INSERT INTO `" + TEST_TABLE + "` (id, name) VALUES ($id2, $name2);" |
| 539 | + + "SELECT * FROM `" + TEST_TABLE + "` ORDER BY id"; |
| 540 | + |
| 541 | + Params params = Params.of( |
| 542 | + "$s1", PrimitiveValue.newInt32(100), |
| 543 | + "$s2", PrimitiveValue.newInt32(100), |
| 544 | + "$id1", PrimitiveValue.newInt32(100), |
| 545 | + "$name1", PrimitiveValue.newText("TEST1"), |
| 546 | + "$id2", PrimitiveValue.newInt32(100), |
| 547 | + "$name2", PrimitiveValue.newText("TEST2") |
| 548 | + ); |
| 549 | + |
| 550 | + Result<QueryReader> result = QueryReader.readFrom( |
| 551 | + session.createQuery(query, TxMode.NONE, params) |
| 552 | + ).join(); |
| 553 | + |
| 554 | + Assert.assertFalse(result.isSuccess()); |
| 555 | + Assert.assertEquals(StatusCode.PRECONDITION_FAILED, result.getStatus().getCode()); |
| 556 | + Assert.assertArrayEquals( |
| 557 | + new Issue[] { Issue.of(2012, "Conflict with existing key.", Issue.Severity.ERROR)}, |
| 558 | + result.getStatus().getIssues() |
| 559 | + ); |
| 560 | + |
| 561 | + Iterator<ResultSetReader> rsIter = QueryReader.readFrom( |
| 562 | + session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id", TxMode.NONE) |
| 563 | + ).join().getValue().iterator(); |
| 564 | + |
| 565 | + Assert.assertTrue(rsIter.hasNext()); |
| 566 | + ResultSetReader rs = rsIter.next(); |
| 567 | + Assert.assertFalse(rs.next()); |
| 568 | + } |
| 569 | + } |
| 570 | + } |
522 | 571 | } |
0 commit comments