提交 7747fff1 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add tests

上级 0923d5bb
...@@ -14,6 +14,7 @@ import java.sql.ResultSet; ...@@ -14,6 +14,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Locale;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.TestDb; import org.h2.test.TestDb;
...@@ -57,6 +58,7 @@ public class TestCompatibility extends TestDb { ...@@ -57,6 +58,7 @@ public class TestCompatibility extends TestDb {
testUnknownSet(); testUnknownSet();
conn.close(); conn.close();
testIdentifiers();
deleteDb("compatibility"); deleteDb("compatibility");
testUnknownURL(); testUnknownURL();
...@@ -682,6 +684,62 @@ public class TestCompatibility extends TestDb { ...@@ -682,6 +684,62 @@ public class TestCompatibility extends TestDb {
assertThrows(ErrorCode.UNKNOWN_MODE_1, stat).execute("SET MODE Unknown"); assertThrows(ErrorCode.UNKNOWN_MODE_1, stat).execute("SET MODE Unknown");
} }
private void testIdentifiers() throws SQLException {
deleteDb("compatibility");
testIdentifiers(false, false, false);
testIdentifiers(false, false, true);
testIdentifiers(true, false, false);
testIdentifiers(true, false, true);
testIdentifiers(false, true, false);
testIdentifiers(false, true, true);
}
private void testIdentifiers(boolean upper, boolean lower, boolean caseInsensitiveIdentifiers) throws SQLException
{
try (Connection conn = getConnection("compatibility;DATABASE_TO_UPPER=" + upper + ";DATABASE_TO_LOWER=" + lower
+ ";CASE_INSENSITIVE_IDENTIFIERS=" + caseInsensitiveIdentifiers)) {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Test(Id INT) AS VALUES 2");
String schema = "PUBLIC", table = "Test", column = "Id";
if (upper) {
table = table.toUpperCase(Locale.ROOT);
column = column.toUpperCase(Locale.ROOT);
} else if (lower) {
schema = schema.toLowerCase(Locale.ROOT);
table = table.toLowerCase(Locale.ROOT);
column = column.toLowerCase(Locale.ROOT);
}
try (ResultSet rs = stat.executeQuery("SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME"
+ " FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ILIKE 'Test'")) {
assertTrue(rs.next());
assertEquals(schema, rs.getString(1));
assertEquals(table, rs.getString(2));
assertEquals(column, rs.getString(3));
}
testIdentifiers(stat, "Test", "Id", true);
boolean ok = upper || lower || caseInsensitiveIdentifiers;
testIdentifiers(stat, "TEST", "ID", ok);
testIdentifiers(stat, "test", "id", ok);
testIdentifiers(stat, '"' + table + '"', '"' + column + '"', true);
testIdentifiers(stat, "\"TeSt\"", "\"iD\"", caseInsensitiveIdentifiers);
} finally {
deleteDb("compatibility");
}
}
private void testIdentifiers(Statement stat, String table, String column, boolean ok) throws SQLException {
String query = "SELECT _ROWID_, " + column + " FROM " + table;
if (ok) {
try (ResultSet rs = stat.executeQuery(query)) {
assertTrue(rs.next());
assertEquals(1L, rs.getLong(1));
assertEquals(2, rs.getInt(2));
}
} else {
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat).executeQuery(query);
}
}
private void testUnknownURL() throws SQLException { private void testUnknownURL() throws SQLException {
try { try {
getConnection("compatibility;MODE=Unknown").close(); getConnection("compatibility;MODE=Unknown").close();
......
...@@ -79,12 +79,10 @@ public class TestKeywords extends TestBase { ...@@ -79,12 +79,10 @@ public class TestKeywords extends TestBase {
try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:keywords")) { try (Connection conn = DriverManager.getConnection("jdbc:h2:mem:keywords")) {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
for (String s : set) { for (String s : set) {
// _ROWID_ is a special virtual column
String column = s.equals("_ROWID_") ? "C" : s;
try { try {
stat.execute("CREATE TABLE " + s + '(' + column + " INT)"); stat.execute("CREATE TABLE " + s + '(' + s + " INT)");
stat.execute("INSERT INTO " + s + '(' + column + ") VALUES (10)"); stat.execute("INSERT INTO " + s + '(' + s + ") VALUES (10)");
try (ResultSet rs = stat.executeQuery("SELECT " + column + " FROM " + s)) { try (ResultSet rs = stat.executeQuery("SELECT " + s + " FROM " + s)) {
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals(10, rs.getInt(1)); assertEquals(10, rs.getInt(1));
assertFalse(rs.next()); assertFalse(rs.next());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论