提交 d61ad865 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 249: Improved compatiblity with MySQL in the MySQL mode: now the methods…

Issue 249: Improved compatiblity with MySQL in the MySQL mode: now the methods DatabaseMetaData methods stores*Case*Identifiers return the same as MySQL when using the MySQL mode.
上级 8537973a
...@@ -18,7 +18,10 @@ Change Log ...@@ -18,7 +18,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Issue 434: H2 Console didn't work in the Chrome browser <ul><li>Issue 249: Improved compatiblity with MySQL in the MySQL mode:
now the methods DatabaseMetaData methods stores*Case*Identifiers return the same as MySQL
when using the MySQL mode.
</li><li>Issue 434: H2 Console didn't work in the Chrome browser
due to a wrong viewport argument. due to a wrong viewport argument.
</li><li>There was a possibility that the .lock.db file was not deleted </li><li>There was a possibility that the .lock.db file was not deleted
when the database was closed, which could slow down opening the database. when the database was closed, which could slow down opening the database.
......
...@@ -28,6 +28,7 @@ import org.h2.util.StringUtils; ...@@ -28,6 +28,7 @@ import org.h2.util.StringUtils;
public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaData { public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaData {
private final JdbcConnection conn; private final JdbcConnection conn;
private String mode;
JdbcDatabaseMetaData(JdbcConnection conn, Trace trace, int id) { JdbcDatabaseMetaData(JdbcConnection conn, Trace trace, int id) {
setTrace(trace, TraceObject.DATABASE_META_DATA, id); setTrace(trace, TraceObject.DATABASE_META_DATA, id);
...@@ -2307,10 +2308,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2307,10 +2308,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if a table created with CREATE TABLE "Test"(ID INT) is a different * Checks if a table created with CREATE TABLE "Test"(ID INT) is a different
* table than a table created with CREATE TABLE TEST(ID INT). * table than a table created with CREATE TABLE TEST(ID INT).
* *
* @return true * @return true usually, and false in MySQL mode
*/ */
public boolean supportsMixedCaseQuotedIdentifiers() { public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("supportsMixedCaseQuotedIdentifiers"); debugCodeCall("supportsMixedCaseQuotedIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return false;
}
return true; return true;
} }
...@@ -2318,10 +2323,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2318,10 +2323,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if for CREATE TABLE Test(ID INT), getTables returns TEST as the * Checks if for CREATE TABLE Test(ID INT), getTables returns TEST as the
* table name. * table name.
* *
* @return true * @return true usually, and false in MySQL mode
*/ */
public boolean storesUpperCaseIdentifiers() { public boolean storesUpperCaseIdentifiers() throws SQLException {
debugCodeCall("storesUpperCaseIdentifiers"); debugCodeCall("storesUpperCaseIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return false;
}
return true; return true;
} }
...@@ -2329,10 +2338,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2329,10 +2338,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if for CREATE TABLE Test(ID INT), getTables returns test as the * Checks if for CREATE TABLE Test(ID INT), getTables returns test as the
* table name. * table name.
* *
* @return false * @return false usually, and true in MySQL mode
*/ */
public boolean storesLowerCaseIdentifiers() { public boolean storesLowerCaseIdentifiers() throws SQLException {
debugCodeCall("storesLowerCaseIdentifiers"); debugCodeCall("storesLowerCaseIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return true;
}
return false; return false;
} }
...@@ -2351,10 +2364,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2351,10 +2364,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns TEST as the * Checks if for CREATE TABLE "Test"(ID INT), getTables returns TEST as the
* table name. * table name.
* *
* @return false * @return false usually, and true in MySQL mode
*/ */
public boolean storesUpperCaseQuotedIdentifiers() { public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesUpperCaseQuotedIdentifiers"); debugCodeCall("storesUpperCaseQuotedIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return true;
}
return false; return false;
} }
...@@ -2362,10 +2379,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2362,10 +2379,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns test as the * Checks if for CREATE TABLE "Test"(ID INT), getTables returns test as the
* table name. * table name.
* *
* @return false * @return false usually, and true in MySQL mode
*/ */
public boolean storesLowerCaseQuotedIdentifiers() { public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesLowerCaseQuotedIdentifiers"); debugCodeCall("storesLowerCaseQuotedIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return true;
}
return false; return false;
} }
...@@ -2373,10 +2394,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2373,10 +2394,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns Test as the * Checks if for CREATE TABLE "Test"(ID INT), getTables returns Test as the
* table name. * table name.
* *
* @return true * @return true usually, and false in MySQL mode
*/ */
public boolean storesMixedCaseQuotedIdentifiers() { public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesMixedCaseQuotedIdentifiers"); debugCodeCall("storesMixedCaseQuotedIdentifiers");
String m = getMode();
if (m.equals("MySQL")) {
return false;
}
return true; return true;
} }
...@@ -2948,4 +2973,17 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2948,4 +2973,17 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
return getTraceObjectName() + ": " + conn; return getTraceObjectName() + ": " + conn;
} }
private String getMode() throws SQLException {
if (mode == null) {
PreparedStatement prep = conn.prepareStatement(
"SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?");
prep.setString(1, "MODE");
ResultSet rs = prep.executeQuery();
rs.next();
mode = rs.getString(1);
prep.close();
}
return mode;
}
} }
...@@ -237,6 +237,14 @@ public class TestCompatibility extends TestBase { ...@@ -237,6 +237,14 @@ public class TestCompatibility extends TestBase {
stat = conn.createStatement(); stat = conn.createStatement();
testLog(Math.log(10), stat); testLog(Math.log(10), stat);
DatabaseMetaData meta = conn.getMetaData();
assertTrue(meta.storesLowerCaseIdentifiers());
assertTrue(meta.storesLowerCaseQuotedIdentifiers());
assertFalse(meta.storesMixedCaseIdentifiers());
assertFalse(meta.storesMixedCaseQuotedIdentifiers());
assertFalse(meta.storesUpperCaseIdentifiers());
assertTrue(meta.storesUpperCaseQuotedIdentifiers());
stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
assertResult("test", stat, "SHOW TABLES"); assertResult("test", stat, "SHOW TABLES");
ResultSet rs = stat.executeQuery("SELECT * FROM TEST"); ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论