提交 421cc9fc authored 作者: Thomas Mueller's avatar Thomas Mueller

Creating a comment on a column didn't work if the schema name was equal the database name.

上级 f86ebb5c
...@@ -1086,18 +1086,34 @@ public class Parser { ...@@ -1086,18 +1086,34 @@ public class Parser {
throw getSyntaxError(); throw getSyntaxError();
} }
SetComment command = new SetComment(session); SetComment command = new SetComment(session);
String objectName = readIdentifierWithSchema(); String objectName;
if (column) { if (column) {
String columnName = objectName; // can't use readIdentifierWithSchema() because
objectName = schemaName; // it wouldn't read schema.table.column correctly
// if the db name is equal to the schema name
ArrayList<String> list = New.arrayList();
do {
list.add(readUniqueIdentifier());
} while (readIf("."));
schemaName = session.getCurrentSchemaName(); schemaName = session.getCurrentSchemaName();
if (readIf(".")) { if (list.size() == 4) {
schemaName = objectName; if (!equalsToken(database.getShortName(), list.get(0))) {
objectName = columnName; throw DbException.getSyntaxError(sqlCommand, parseIndex, "database name");
columnName = readUniqueIdentifier(); }
list.remove(0);
} }
if (list.size() == 3) {
schemaName = list.get(0);
list.remove(0);
}
if (list.size() != 2) {
throw DbException.getSyntaxError(sqlCommand, parseIndex, "table.column");
}
objectName = list.get(0);
command.setColumn(true); command.setColumn(true);
command.setColumnName(columnName); command.setColumnName(list.get(1));
} else {
objectName = readIdentifierWithSchema();
} }
command.setSchemaName(schemaName); command.setSchemaName(schemaName);
command.setObjectName(objectName); command.setObjectName(objectName);
......
...@@ -37,6 +37,7 @@ public class TestCases extends TestBase { ...@@ -37,6 +37,7 @@ public class TestCases extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testOuterJoin(); testOuterJoin();
testCommentOnColumnWithSchemaEqualDatabase();
testColumnWithConstraintAndComment(); testColumnWithConstraintAndComment();
testTruncateConstraintsDisabled(); testTruncateConstraintsDisabled();
testPreparedSubquery2(); testPreparedSubquery2();
...@@ -109,6 +110,17 @@ public class TestCases extends TestBase { ...@@ -109,6 +110,17 @@ public class TestCases extends TestBase {
conn.close(); conn.close();
} }
private void testCommentOnColumnWithSchemaEqualDatabase() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create schema cases");
stat.execute("create table cases.cases(cases int)");
stat.execute("comment on column cases.cases.cases is 'schema.table.column'");
stat.execute("comment on column cases.cases.cases.cases is 'db.schema.table.column'");
conn.close();
}
private void testColumnWithConstraintAndComment() throws SQLException { private void testColumnWithConstraintAndComment() throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论