提交 e4068946 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Throw exception if unknown mode is specified in database URL

上级 9ba3f6ea
...@@ -285,7 +285,10 @@ public class Database implements DataHandler { ...@@ -285,7 +285,10 @@ public class Database implements DataHandler {
} }
String modeName = ci.removeProperty("MODE", null); String modeName = ci.removeProperty("MODE", null);
if (modeName != null) { if (modeName != null) {
this.mode = Mode.getInstance(modeName); mode = Mode.getInstance(modeName);
if (mode == null) {
throw DbException.get(ErrorCode.UNKNOWN_MODE_1, modeName);
}
} }
this.logMode = this.logMode =
ci.getProperty("LOG", PageStore.LOG_MODE_SYNC); ci.getProperty("LOG", PageStore.LOG_MODE_SYNC);
......
...@@ -373,4 +373,9 @@ public class Mode { ...@@ -373,4 +373,9 @@ public class Mode {
return this.modeEnum; return this.modeEnum;
} }
@Override
public String toString() {
return name;
}
} }
...@@ -15,6 +15,7 @@ import java.sql.ResultSetMetaData; ...@@ -15,6 +15,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.jdbc.JdbcSQLException;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.TestDb; import org.h2.test.TestDb;
...@@ -54,8 +55,12 @@ public class TestCompatibility extends TestDb { ...@@ -54,8 +55,12 @@ public class TestCompatibility extends TestDb {
testSybaseAndMSSQLServer(); testSybaseAndMSSQLServer();
testIgnite(); testIgnite();
testUnknownSet();
conn.close(); conn.close();
deleteDb("compatibility"); deleteDb("compatibility");
testUnknownURL();
} }
private void testKeyAsColumnInMySQLMode() throws SQLException { private void testKeyAsColumnInMySQLMode() throws SQLException {
...@@ -660,4 +665,21 @@ public class TestCompatibility extends TestDb { ...@@ -660,4 +665,21 @@ public class TestCompatibility extends TestDb {
stat.execute("DROP TABLE IF EXISTS TEST"); stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("create table test(id int, v1 varchar, v2 long, primary key(v1, id), shard key (id))"); stat.execute("create table test(id int, v1 varchar, v2 long, primary key(v1, id), shard key (id))");
} }
private void testUnknownSet() throws SQLException {
Statement stat = conn.createStatement();
assertThrows(ErrorCode.UNKNOWN_MODE_1, stat).execute("SET MODE Unknown");
}
private void testUnknownURL() throws SQLException {
try {
getConnection("compatibility;MODE=Unknown").close();
deleteDb("compatibility");
} catch (JdbcSQLException ex) {
assertEquals(ErrorCode.UNKNOWN_MODE_1, ex.getErrorCode());
return;
}
fail();
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论