Repository navigation
Expand file tree
/
Copy pathSQLiteTest.java
More file actions
55 lines (48 loc) · 2.02 KB
/
Copy pathSQLiteTest.java
File metadata and controls
55 lines (48 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2023 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.select;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.AbstractJSqlParser.Dialect;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class SQLiteTest {
@Test
void testInsertOrReplaceUpsert() throws JSQLParserException {
String sqlString = "INSERT OR REPLACE INTO kjobLocks VALUES (?, ?, ?)";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlString, true);
}
@ParameterizedTest
@ValueSource(strings = {"ABORT", "FAIL", "IGNORE", "REPLACE", "ROLLBACK"})
void testInsertOrConflictAlgorithm(String algorithm) throws JSQLParserException {
TestUtils.assertSqlCanBeParsedAndDeparsed(
"INSERT OR " + algorithm + " INTO t (a, b) VALUES (1, 2)", true,
parser -> parser.withDialect(Dialect.SQLITE));
TestUtils.assertSqlCanBeParsedAndDeparsed(
"insert or " + algorithm.toLowerCase(Locale.ROOT) + " into t select * from s", true,
parser -> parser.withDialect(Dialect.SQLITE));
}
@ParameterizedTest
@ValueSource(strings = {"ABORT", "FAIL", "IGNORE", "ROLLBACK"})
void testInsertOrConflictAlgorithmNeedsSqliteDialect(String algorithm) {
assertThrows(JSQLParserException.class,
() -> CCJSqlParserUtil.parse("INSERT OR " + algorithm + " INTO t VALUES (1)"));
}
@Test
void testInsertOrUnknownAlgorithm() {
assertThrows(JSQLParserException.class,
() -> CCJSqlParserUtil.parse("INSERT OR NOTHING INTO t VALUES (1)",
parser -> parser.withDialect(Dialect.SQLITE)));
}
}