|
12 | 12 | import net.sf.jsqlparser.JSQLParserException; |
13 | 13 | import net.sf.jsqlparser.parser.AbstractJSqlParser.Dialect; |
14 | 14 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
| 15 | +import net.sf.jsqlparser.statement.update.Update; |
| 16 | +import net.sf.jsqlparser.statement.update.UpdateConflictAlgorithm; |
15 | 17 | import net.sf.jsqlparser.test.TestUtils; |
16 | 18 | import org.junit.jupiter.api.Test; |
17 | 19 | import org.junit.jupiter.params.ParameterizedTest; |
18 | 20 | import org.junit.jupiter.params.provider.ValueSource; |
19 | 21 |
|
20 | 22 | import java.util.Locale; |
21 | 23 |
|
| 24 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 25 | +import static org.junit.jupiter.api.Assertions.assertNull; |
22 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows; |
23 | 27 |
|
24 | 28 | public class SQLiteTest { |
@@ -52,4 +56,42 @@ void testInsertOrUnknownAlgorithm() { |
52 | 56 | () -> CCJSqlParserUtil.parse("INSERT OR NOTHING INTO t VALUES (1)", |
53 | 57 | parser -> parser.withDialect(Dialect.SQLITE))); |
54 | 58 | } |
| 59 | + |
| 60 | + @ParameterizedTest |
| 61 | + @ValueSource(strings = {"ABORT", "FAIL", "IGNORE", "REPLACE", "ROLLBACK"}) |
| 62 | + void testUpdateOrConflictAlgorithm(String algorithm) throws JSQLParserException { |
| 63 | + Update update = (Update) TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 64 | + "UPDATE OR " + algorithm + " t SET a = 1, b = 2 WHERE c = 3", true, |
| 65 | + parser -> parser.withDialect(Dialect.SQLITE)); |
| 66 | + assertEquals(UpdateConflictAlgorithm.valueOf(algorithm), update.getConflictAlgorithm()); |
| 67 | + |
| 68 | + TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 69 | + "update or " + algorithm.toLowerCase(Locale.ROOT) + " t set a = 1", true, |
| 70 | + parser -> parser.withDialect(Dialect.SQLITE)); |
| 71 | + } |
| 72 | + |
| 73 | + // A parser without any UPDATE OR support throws here too: these cases pin the SQLITE |
| 74 | + // dialect guard, they do not show that UPDATE OR parses. |
| 75 | + @ParameterizedTest |
| 76 | + @ValueSource(strings = {"ABORT", "FAIL", "IGNORE", "REPLACE", "ROLLBACK"}) |
| 77 | + void testUpdateOrConflictAlgorithmNeedsSqliteDialect(String algorithm) { |
| 78 | + assertThrows(JSQLParserException.class, |
| 79 | + () -> CCJSqlParserUtil.parse("UPDATE OR " + algorithm + " t SET a = 1")); |
| 80 | + } |
| 81 | + |
| 82 | + // A parser without any UPDATE OR support throws here too: this case pins the check of the |
| 83 | + // word after OR, it does not show that UPDATE OR parses. |
| 84 | + @Test |
| 85 | + void testUpdateOrUnknownAlgorithm() { |
| 86 | + assertThrows(JSQLParserException.class, |
| 87 | + () -> CCJSqlParserUtil.parse("UPDATE OR NOTHING t SET a = 1", |
| 88 | + parser -> parser.withDialect(Dialect.SQLITE))); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + void testUpdateWithoutConflictAlgorithm() throws JSQLParserException { |
| 93 | + Update update = (Update) TestUtils.assertSqlCanBeParsedAndDeparsed( |
| 94 | + "UPDATE t SET a = 1", true, parser -> parser.withDialect(Dialect.SQLITE)); |
| 95 | + assertNull(update.getConflictAlgorithm()); |
| 96 | + } |
55 | 97 | } |
0 commit comments