Skip to content

Commit

Permalink
Merge pull request #408 from EMResearch/update_h2
Browse files Browse the repository at this point in the history
update H2 to v200
  • Loading branch information
arcuri82 committed Nov 11, 2021
2 parents 804a137 + 861d3b0 commit 7a5e430
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testInsertWhenForeignKey() throws Exception {
" id bigint generated by default as identity " +
", barId bigint not null " +
");" +
" CREATE TABLE Bar(id bigint generated by default as identity);" +
" CREATE TABLE Bar(id bigint generated by default as identity primary key);" +
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ public void testBasicConstraints() throws Exception {
@Test
public void testBasicForeignKey() throws Exception {

SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(" +
" id bigint generated by default as identity " +
", barId bigint not null " +
");" +
" CREATE TABLE Bar(id bigint generated by default as identity);" +
SqlScriptRunner.execCommand(getConnection(),
" CREATE TABLE Bar(id bigint generated by default as identity primary key);"
+
"CREATE TABLE Foo(" +
" id bigint generated by default as identity " +
", barId bigint not null " +
");"
+
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
);

Expand Down Expand Up @@ -189,7 +192,7 @@ public void testColumnUpperBoundConstraint() throws Exception {
assertEquals("INTEGER", columnDto.type);

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(AGE_MAX <= 100)", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"AGE_MAX\" <= 100)", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);


}
Expand All @@ -212,7 +215,7 @@ public void testTableConstraint() throws Exception {
assertTrue(fooTable.columns.stream().anyMatch(c -> c.name.equalsIgnoreCase("age_max")));

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(AGE_MAX <= 100)", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"AGE_MAX\" <= 100)", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);


}
Expand Down Expand Up @@ -259,7 +262,7 @@ public void testEnumStringConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN('A', 'B'))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN('A', 'B'))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -283,7 +286,7 @@ public void testEnumBooleanConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(TRUE, FALSE))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(TRUE, FALSE))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -307,7 +310,7 @@ public void testEnumIntegerConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);


}
Expand All @@ -332,7 +335,7 @@ public void testEnumTinyIntConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -356,7 +359,7 @@ public void testEnumSmallIntConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);


}
Expand All @@ -381,7 +384,7 @@ public void testEnumBigIntConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(42, 77))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -405,7 +408,7 @@ public void testEnumDoubleConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -430,7 +433,7 @@ public void testEnumRealConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);

}

Expand All @@ -454,7 +457,7 @@ public void testEnumDecimalConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN(1.0, 2.5))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
}

@Test
Expand All @@ -476,7 +479,7 @@ public void testEnumCharConstraint() throws Exception {
ColumnDto statusColumn = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("status")).findFirst().get();

assertEquals(1, fooTable.tableCheckExpressions.size());
assertEquals("(STATUS IN('A', 'B'))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);
assertEquals("(\"STATUS\" IN('A', 'B'))", fooTable.tableCheckExpressions.get(0).sqlCheckExpression);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ public void givenASelectNextValueInASequenceThenTheQueryIsIgnoredToCalculateHeur

try {

ExecutionDto dto = executeCommand(starter, "SELECT currval('foo_id_seq')", true);
ExecutionDto dto = executeCommand(starter, "SELECT nextval('foo_id_seq')", true);

assertNotNull(dto);
assertNotNull(dto.queriedData);
assertEquals(0, dto.queriedData.size());

ExecutionDto dto2 = executeCommand(starter, "SELECT currval('foo_id_seq')", true);
assertNotNull(dto2);
assertNotNull(dto2.queriedData);
assertEquals(0, dto2.queriedData.size());


} finally {
starter.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SqlInsertBuilderTest {

SqlScriptRunner.execCommand(connection, """
CREATE TABLE Foo(
id bigint generated by default as identity,
id bigint generated by default as identity primary key,
x INT,
y INT not null,
z INT
Expand Down Expand Up @@ -172,7 +172,7 @@ class SqlInsertBuilderTest {

SqlScriptRunner.execCommand(connection, """
create table Foo (
time timestamp not null,
time timestamp not null
)
""")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AlterTableCheckEnumTest : ExtractTestBaseH2() {
assertTrue(schema.tables.first { it.name == "X" }.columns.any { it.name == "STATUS" });

assertEquals(1, schema.tables.first { it.name == "X" }.tableCheckExpressions.size)
assertEquals("(STATUS IN('A', 'B'))", schema.tables.first { it.name == "X" }.tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"STATUS\" IN('A', 'B'))", schema.tables.first { it.name == "X" }.tableCheckExpressions[0].sqlCheckExpression)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AlterTableCheckTest : ExtractTestBaseH2() {
assertTrue(schema.tables.first { it.name == "PEOPLE" }.columns.any { it.name == "AGE" });

assertEquals(1, schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions.size)
assertEquals("(AGE <= 100)", schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"AGE\" <= 100)", schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions[0].sqlCheckExpression)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AlterTableUniqueTest : ExtractTestBaseH2() {
assertEquals(true, schema.tables.filter { it.name == "PASSPORTS" }.first().columns.filter { it.name == "PASSPORT_NUMBER"}.first().unique)

assertEquals(1, schema.tables.filter { it.name == "PASSPORTS" }.first().tableCheckExpressions.size)
assertEquals("(PASSPORT_NUMBER > 0)", schema.tables.filter { it.name == "PASSPORTS" }.first().tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"PASSPORT_NUMBER\" > 0)", schema.tables.filter { it.name == "PASSPORTS" }.first().tableCheckExpressions[0].sqlCheckExpression)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CreateTableCheckEnumTest : ExtractTestBaseH2() {
assertTrue(schema.tables.first { it.name == "X" }.columns.any { it.name == "STATUS" });

assertEquals(1, schema.tables.first { it.name == "X" }.tableCheckExpressions.size)
assertEquals("(STATUS IN('A', 'B'))", schema.tables.first { it.name == "X" }.tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"STATUS\" IN('A', 'B'))", schema.tables.first { it.name == "X" }.tableCheckExpressions[0].sqlCheckExpression)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CreateTableCheckTest : ExtractTestBaseH2() {
assertTrue(schema.tables.first { it.name == "PEOPLE" }.columns.any { it.name == "AGE" });

assertEquals(1, schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions.size)
assertEquals("(AGE <= 100)", schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"AGE\" <= 100)", schema.tables.first { it.name == "PEOPLE" }.tableCheckExpressions[0].sqlCheckExpression)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ScoutApiSqlExtractTest : ExtractTestBaseH2() {
assertEquals(true, schema.tables.filter { it.name == "SYSTEM_MESSAGE" }.first().columns.filter { it.name == "key".toUpperCase() }.first().unique)

assertEquals(2, schema.tables.filter { it.name == "ACTIVITY_PROPERTIES" }.first().tableCheckExpressions.size)
assertEquals("(AGE_MAX <= 100)", schema.tables.filter { it.name == "ACTIVITY_PROPERTIES" }.first().tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(AGE_MIN <= 100)", schema.tables.filter { it.name == "ACTIVITY_PROPERTIES" }.first().tableCheckExpressions[1].sqlCheckExpression)
assertEquals("(\"AGE_MAX\" <= 100)", schema.tables.filter { it.name == "ACTIVITY_PROPERTIES" }.first().tableCheckExpressions[0].sqlCheckExpression)
assertEquals("(\"AGE_MIN\" <= 100)", schema.tables.filter { it.name == "ACTIVITY_PROPERTIES" }.first().tableCheckExpressions[1].sqlCheckExpression)


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,34 @@ public void visit(NotEqualsTo notEqualsTo) {
throw new RuntimeException("Extraction of condition not yet implemented");
}

private static String QUOTE_CHAR = "\"";

private static boolean hasSurroundingQuotes(String str) {
return str.length()>1 && str.startsWith(QUOTE_CHAR) && str.endsWith(QUOTE_CHAR);
}

private static String removeSurroundingQuotes(String str) {
return str.substring(1,str.length()-1);
}

@Override
public void visit(Column column) {
String columnName = column.getColumnName();

/**
* The SQL:1999 standard specifies that double quote (")
* (QUOTATION MARK) is used to delimit identifiers.
* Oracle, PostgreSQL, MySQL, MSSQL and SQlite all
* support " as the identifier delimiter.
* e.g.
* 'foo' is an SQL string
* "foo" is an SQL identifier (column/table/etc)
*
* https://stackoverflow.com/questions/2901453/sql-standard-to-escape-column-names
*/
if (hasSurroundingQuotes(columnName)) {
columnName = removeSurroundingQuotes(columnName);
}
if (column.getTable() != null) {
String tableName = column.getTable().getName();
stack.push(new SqlColumn(tableName, columnName));
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
Expand Down

0 comments on commit 7a5e430

Please sign in to comment.