提交 efe3c311 authored 作者: Noel Grandin's avatar Noel Grandin

Fix for #134, Column name with a # character. Patch by bradmesserle.

上级 792e08c8
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<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
due to the change "Make the planner use indexes for sorting when doing a GROUP BY".
The change was reverted.
......
......@@ -14,7 +14,6 @@ import java.nio.charset.Charset;
import java.text.Collator;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.api.ErrorCode;
import org.h2.api.Trigger;
import org.h2.command.ddl.AlterIndexRename;
......@@ -3573,6 +3572,11 @@ public class Parser {
case '_':
type = CHAR_NAME;
break;
case '#':
if (database.getMode().supportPoundSymbolForColumnNames) {
type = CHAR_NAME;
break;
}
default:
if (c >= 'a' && c <= 'z') {
if (identifiersToUpper) {
......
......@@ -137,6 +137,11 @@ public class Mode {
*/
public boolean onDuplicateKeyUpdate;
/**
* Support the # for column names
*/
public boolean supportPoundSymbolForColumnNames;
private final String name;
static {
......@@ -173,6 +178,7 @@ public class Mode {
mode.uniqueIndexSingleNull = true;
mode.allowPlusForStringConcat = true;
mode.swapConvertFunctionParameters = true;
mode.supportPoundSymbolForColumnNames = true;
add(mode);
mode = new Mode("MySQL");
......@@ -187,6 +193,7 @@ public class Mode {
mode.convertOnlyToSmallerScale = true;
mode.uniqueIndexSingleNullExceptAllColumnsAreNull = true;
mode.treatEmptyStringsAsNull = true;
mode.supportPoundSymbolForColumnNames = true;
add(mode);
mode = new Mode("PostgreSQL");
......
......@@ -34,6 +34,7 @@ public class TestCompatibilityOracle extends TestBase {
public void test() throws Exception {
testTreatEmptyStringsAsNull();
testDecimalScale();
testPoundSymbolInColumnName();
}
private void testTreatEmptyStringsAsNull() throws SQLException {
......@@ -121,6 +122,22 @@ public class TestCompatibilityOracle extends TestBase {
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,
String sql) throws SQLException {
assertResult(newSimpleResultSet(expectedRowsOfValues), stat, sql);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论