|
10 | 10 | package net.sf.jsqlparser.statement.insert; |
11 | 11 |
|
12 | 12 | import net.sf.jsqlparser.JSQLParserException; |
| 13 | +import net.sf.jsqlparser.expression.Alias; |
13 | 14 | import net.sf.jsqlparser.expression.DoubleValue; |
14 | 15 | import net.sf.jsqlparser.expression.Expression; |
15 | 16 | import net.sf.jsqlparser.expression.JdbcParameter; |
@@ -590,4 +591,55 @@ void testMultiColumnConflictTargetIssue955() throws JSQLParserException { |
590 | 591 | + "on conflict(xxx0, xxx1) do update set xxx1=?, update_time=?"; |
591 | 592 | assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
592 | 593 | } |
| 594 | + |
| 595 | + @Test |
| 596 | + public void testDefaultValues() throws JSQLParserException { |
| 597 | + String statement = "INSERT INTO mytable DEFAULT VALUES"; |
| 598 | + //assertSqlCanBeParsedAndDeparsed(statement); |
| 599 | + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); |
| 600 | + assertEquals("mytable", insert.getTable().getFullyQualifiedName()); |
| 601 | + assertEquals("INSERT INTO MYTABLE DEFAULT VALUES", insert.toString().toUpperCase()); |
| 602 | + assertTrue(insert.isOnlyDefaultValues()); |
| 603 | + assertDeparse(new Insert() |
| 604 | + .withTable(new Table("mytable")) |
| 605 | + .withOnlyDefaultValues(true), statement); |
| 606 | + } |
| 607 | + |
| 608 | + @Test |
| 609 | + public void testDefaultValuesWithAlias() throws JSQLParserException { |
| 610 | + String statement = "INSERT INTO mytable x DEFAULT VALUES"; |
| 611 | + assertSqlCanBeParsedAndDeparsed(statement); |
| 612 | + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); |
| 613 | + assertEquals("mytable", insert.getTable().getFullyQualifiedName()); |
| 614 | + assertEquals("INSERT INTO MYTABLE X DEFAULT VALUES", insert.toString().toUpperCase()); |
| 615 | + assertEquals("x", insert.getTable().getAlias().getName()); |
| 616 | + assertTrue(insert.isOnlyDefaultValues()); |
| 617 | + assertDeparse(new Insert() |
| 618 | + .withTable(new Table("mytable") |
| 619 | + .withAlias(new Alias("x").withUseAs(false))) |
| 620 | + .withOnlyDefaultValues(true), statement); |
| 621 | + } |
| 622 | + |
| 623 | + @Test |
| 624 | + public void testDefaultValuesWithAliasAndAs() throws JSQLParserException { |
| 625 | + String statement = "INSERT INTO mytable AS x DEFAULT VALUES"; |
| 626 | + assertSqlCanBeParsedAndDeparsed(statement); |
| 627 | + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); |
| 628 | + assertEquals("mytable", insert.getTable().getFullyQualifiedName()); |
| 629 | + assertEquals("INSERT INTO MYTABLE AS X DEFAULT VALUES", insert.toString().toUpperCase()); |
| 630 | + assertEquals("x", insert.getTable().getAlias().getName()); |
| 631 | + assertTrue(insert.isOnlyDefaultValues()); |
| 632 | + assertDeparse(new Insert() |
| 633 | + .withTable(new Table("mytable") |
| 634 | + .withAlias(new Alias("x").withUseAs(true))) |
| 635 | + .withOnlyDefaultValues(true), statement); |
| 636 | + } |
| 637 | + |
| 638 | + @Test |
| 639 | + public void throwsParseWhenDefaultKeyowrdUsedAsAlias() { |
| 640 | + String statement = "INSERT INTO mytable default DEFAULT VALUES"; |
| 641 | + assertThrows(JSQLParserException.class, |
| 642 | + () -> parserManager.parse(new StringReader(statement))); |
| 643 | + } |
| 644 | + |
593 | 645 | } |
0 commit comments