Unverified 提交 2a6869f9 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1784 from grandinj/improve_db_not_found_error

improve database not found error
......@@ -611,13 +611,11 @@ public class ErrorCode {
public static final int PARAMETER_NOT_SET_1 = 90012;
/**
* The error with code <code>90013</code> is thrown when trying to open a
* database that does not exist remotely without enabling remote database
* creation first, or using the flag IFEXISTS=TRUE, or when trying to access
* The error with code <code>90013</code> is thrown when when trying to access
* a database object with a catalog name that does not match the database
* name.
* <pre>
* jdbc:h2:./database_that_does_not_exist
* SELECT * FROM database_that_does_not_exist.table_name
* </pre>
*/
public static final int DATABASE_NOT_FOUND_1 = 90013;
......@@ -2052,7 +2050,17 @@ public class ErrorCode {
public static final int FOR_UPDATE_IS_NOT_ALLOWED_IN_DISTINCT_OR_GROUPED_SELECT = 90145;
// next is 90146
/**
* The error with code <code>90146</code> is thrown when trying to open a
* database that does not exist remotely without enabling remote database
* creation first, or using the flag IFEXISTS=TRUE
* <pre>
* jdbc:h2:./database_that_does_not_exist
* </pre>
*/
public static final int DATABASE_NOT_FOUND_2 = 90146;
// next is 90147
private ErrorCode() {
// utility class
......
......@@ -64,7 +64,7 @@ public class Engine implements SessionFactory {
}
if (database == null) {
if (ifExists && !Database.exists(name)) {
throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_1, name);
throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_2, name);
}
database = new Database(ci, cipher);
opened = true;
......
......@@ -587,6 +587,7 @@ public class DbException extends RuntimeException {
return new JdbcSQLDataException(message, sql, state, errorCode, cause, stackTrace);
case URL_RELATIVE_TO_CWD:
case DATABASE_NOT_FOUND_1:
case DATABASE_NOT_FOUND_2:
case TRACE_CONNECTION_NOT_CLOSED:
case DATABASE_ALREADY_OPEN_1:
case FILE_CORRUPTED_1:
......
......@@ -177,6 +177,7 @@
90143=Row {1} not found in primary index {0}
90144=Authenticator not enabled on database {0}
90145=FOR UPDATE is not allowed in DISTINCT or grouped select
90146=Database {0} not found, and IFEXISTS=true, so we can't auto-create it
HY000=General error: {0}
HY004=Unknown data type: {0}
HYC00=Feature not supported: {0}
......
......@@ -1125,12 +1125,12 @@ public class TestTools extends TestDb {
final int prt = tcpServerWithPassword.getPort();
remainingServers.add(tcpServerWithPassword);
// must not be able to create new db
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) {
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_2) {
@Override
public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:"+prt+"/test2", "sa", "");
}};
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_1) {
new AssertThrows(ErrorCode.DATABASE_NOT_FOUND_2) {
@Override
public void test() throws SQLException {
getConnection("jdbc:h2:tcp://localhost:"+prt+"/test2;ifexists=false", "sa", "");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论