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

Merge branch 'master' of https://github.com/h2database/h2database

...@@ -24,6 +24,8 @@ Change Log ...@@ -24,6 +24,8 @@ Change Log
<li>For compatibility with other databases, support for (double and float) <li>For compatibility with other databases, support for (double and float)
-0.0 has been removed. 0.0 is used instead. -0.0 has been removed. 0.0 is used instead.
</li> </li>
<li>Fix for #134, Column name with a # character. Patch by bradmesserle.
</li>
<li>In version 1.4.186, "order by" was broken in some cases <li>In version 1.4.186, "order by" was broken in some cases
due to the change "Make the planner use indexes for sorting when doing a GROUP BY". due to the change "Make the planner use indexes for sorting when doing a GROUP BY".
The change was reverted. The change was reverted.
......
...@@ -14,7 +14,6 @@ import java.nio.charset.Charset; ...@@ -14,7 +14,6 @@ import java.nio.charset.Charset;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.ddl.AlterIndexRename; import org.h2.command.ddl.AlterIndexRename;
...@@ -3573,6 +3572,11 @@ public class Parser { ...@@ -3573,6 +3572,11 @@ public class Parser {
case '_': case '_':
type = CHAR_NAME; type = CHAR_NAME;
break; break;
case '#':
if (database.getMode().supportPoundSymbolForColumnNames) {
type = CHAR_NAME;
break;
}
default: default:
if (c >= 'a' && c <= 'z') { if (c >= 'a' && c <= 'z') {
if (identifiersToUpper) { if (identifiersToUpper) {
......
...@@ -382,42 +382,42 @@ public class ConnectionInfo implements Cloneable { ...@@ -382,42 +382,42 @@ public class ConnectionInfo implements Cloneable {
* @return the database name * @return the database name
*/ */
public String getName() { public String getName() {
if (persistent) { if (!persistent) {
if (nameNormalized == null) { return name;
if (!SysProperties.IMPLICIT_RELATIVE_PATH) { }
if (!FileUtils.isAbsolute(name)) { if (nameNormalized == null) {
if (name.indexOf("./") < 0 && if (!SysProperties.IMPLICIT_RELATIVE_PATH) {
name.indexOf(".\\") < 0 && if (!FileUtils.isAbsolute(name)) {
name.indexOf(":/") < 0 && if (name.indexOf("./") < 0 &&
name.indexOf(":\\") < 0) { name.indexOf(".\\") < 0 &&
// the name could start with "./", or name.indexOf(":/") < 0 &&
// it could start with a prefix such as "nio:./" name.indexOf(":\\") < 0) {
// for Windows, the path "\test" is not considered // the name could start with "./", or
// absolute as the drive letter is missing, // it could start with a prefix such as "nio:./"
// but we consider it absolute // for Windows, the path "\test" is not considered
throw DbException.get( // absolute as the drive letter is missing,
ErrorCode.URL_RELATIVE_TO_CWD, // but we consider it absolute
originalURL); throw DbException.get(
} ErrorCode.URL_RELATIVE_TO_CWD,
originalURL);
} }
} }
String suffix = Constants.SUFFIX_PAGE_FILE;
String n;
if (FileUtils.exists(name + suffix)) {
n = FileUtils.toRealPath(name + suffix);
} else {
suffix = Constants.SUFFIX_MV_FILE;
n = FileUtils.toRealPath(name + suffix);
}
String fileName = FileUtils.getName(n);
if (fileName.length() < suffix.length() + 1) {
throw DbException.get(ErrorCode.INVALID_DATABASE_NAME_1, name);
}
nameNormalized = n.substring(0, n.length() - suffix.length());
} }
return nameNormalized; String suffix = Constants.SUFFIX_PAGE_FILE;
String n;
if (FileUtils.exists(name + suffix)) {
n = FileUtils.toRealPath(name + suffix);
} else {
suffix = Constants.SUFFIX_MV_FILE;
n = FileUtils.toRealPath(name + suffix);
}
String fileName = FileUtils.getName(n);
if (fileName.length() < suffix.length() + 1) {
throw DbException.get(ErrorCode.INVALID_DATABASE_NAME_1, name);
}
nameNormalized = n.substring(0, n.length() - suffix.length());
} }
return name; return nameNormalized;
} }
/** /**
......
...@@ -137,6 +137,11 @@ public class Mode { ...@@ -137,6 +137,11 @@ public class Mode {
*/ */
public boolean onDuplicateKeyUpdate; public boolean onDuplicateKeyUpdate;
/**
* Support the # for column names
*/
public boolean supportPoundSymbolForColumnNames;
private final String name; private final String name;
static { static {
...@@ -173,6 +178,7 @@ public class Mode { ...@@ -173,6 +178,7 @@ public class Mode {
mode.uniqueIndexSingleNull = true; mode.uniqueIndexSingleNull = true;
mode.allowPlusForStringConcat = true; mode.allowPlusForStringConcat = true;
mode.swapConvertFunctionParameters = true; mode.swapConvertFunctionParameters = true;
mode.supportPoundSymbolForColumnNames = true;
add(mode); add(mode);
mode = new Mode("MySQL"); mode = new Mode("MySQL");
...@@ -187,6 +193,7 @@ public class Mode { ...@@ -187,6 +193,7 @@ public class Mode {
mode.convertOnlyToSmallerScale = true; mode.convertOnlyToSmallerScale = true;
mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true; mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true;
mode.treatEmptyStringsAsNull = true; mode.treatEmptyStringsAsNull = true;
mode.supportPoundSymbolForColumnNames = true;
add(mode); add(mode);
mode = new Mode("PostgreSQL"); mode = new Mode("PostgreSQL");
......
...@@ -34,6 +34,7 @@ public class TestCompatibilityOracle extends TestBase { ...@@ -34,6 +34,7 @@ public class TestCompatibilityOracle extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testTreatEmptyStringsAsNull(); testTreatEmptyStringsAsNull();
testDecimalScale(); testDecimalScale();
testPoundSymbolInColumnName();
} }
private void testTreatEmptyStringsAsNull() throws SQLException { private void testTreatEmptyStringsAsNull() throws SQLException {
...@@ -121,6 +122,22 @@ public class TestCompatibilityOracle extends TestBase { ...@@ -121,6 +122,22 @@ public class TestCompatibilityOracle extends TestBase {
conn.close(); conn.close();
} }
/**
* Test the # in a column name for oracle compatibility
*/
private void testPoundSymbolInColumnName() throws SQLException {
deleteDb("oracle");
Connection conn = getConnection("oracle;MODE=Oracle");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, U##NAME VARCHAR(255))");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'HelloWorld'), (3, 'HelloWorldWorld')");
assertResult("1", stat, "SELECT ID FROM TEST where U##NAME ='Hello'");
conn.close();
}
private void assertResult(Object[][] expectedRowsOfValues, Statement stat, private void assertResult(Object[][] expectedRowsOfValues, Statement stat,
String sql) throws SQLException { String sql) throws SQLException {
assertResult(newSimpleResultSet(expectedRowsOfValues), stat, sql); assertResult(newSimpleResultSet(expectedRowsOfValues), stat, sql);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论