mirror of
https://github.com/actiontech/dble.git
synced 2026-05-01 03:51:06 -05:00
Co-authored-by: Collapsar <838800176@qq.com>
This commit is contained in:
@@ -489,7 +489,7 @@ public class ServerSchemaStatVisitor extends MySqlSchemaStatVisitor {
|
||||
tableName = getOwnerTableName(betweenExpr, column);
|
||||
}
|
||||
if (tableName != null && !"".equals(tableName)) {
|
||||
checkAliasInColumn(tableName);
|
||||
checkAliasInColumn(tableName, false);
|
||||
return new Column(tableName, column);
|
||||
}
|
||||
}
|
||||
@@ -509,42 +509,43 @@ public class ServerSchemaStatVisitor extends MySqlSchemaStatVisitor {
|
||||
private Column getColumnByExpr(SQLPropertyExpr expr) {
|
||||
SQLExpr owner = expr.getOwner();
|
||||
String column = expr.getName();
|
||||
|
||||
boolean containSchema = false;
|
||||
if (owner instanceof SQLIdentifierExpr || owner instanceof SQLPropertyExpr) {
|
||||
String tableName;
|
||||
if (owner instanceof SQLPropertyExpr) {
|
||||
tableName = ((SQLPropertyExpr) owner).getName();
|
||||
if (((SQLPropertyExpr) owner).getOwner() instanceof SQLIdentifierExpr) {
|
||||
containSchema = true;
|
||||
tableName = ((SQLIdentifierExpr) ((SQLPropertyExpr) owner).getOwner()).getName() + "." + tableName;
|
||||
}
|
||||
} else {
|
||||
tableName = ((SQLIdentifierExpr) owner).getName();
|
||||
}
|
||||
checkAliasInColumn(tableName);
|
||||
checkAliasInColumn(tableName, containSchema);
|
||||
return new Column(tableName, column);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void checkAliasInColumn(String tableName) {
|
||||
private void checkAliasInColumn(String tableName, boolean containSchema) {
|
||||
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
|
||||
tableName = tableName.toLowerCase();
|
||||
}
|
||||
if (aliasMap.containsKey(tableName)) {
|
||||
return;
|
||||
}
|
||||
if (containSchema) {
|
||||
putAliasToMap(tableName, tableName.replace("`", ""));
|
||||
return;
|
||||
}
|
||||
String tempStr;
|
||||
if (StringUtil.isAlias(tableName)) {
|
||||
if (StringUtil.containsApostrophe(tableName)) {
|
||||
tempStr = tableName.replace("`", "");
|
||||
} else {
|
||||
tempStr = "`" + tableName + "`";
|
||||
}
|
||||
if (aliasMap.containsKey(tempStr)) {
|
||||
putAliasToMap(tableName, aliasMap.get(tempStr));
|
||||
} else {
|
||||
putAliasToMap(tableName, tableName.replace("`", ""));
|
||||
}
|
||||
putAliasToMap(tableName, aliasMap.getOrDefault(tempStr, tempStr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -926,6 +927,7 @@ public class ServerSchemaStatVisitor extends MySqlSchemaStatVisitor {
|
||||
if (name != null) {
|
||||
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
|
||||
name = name.toLowerCase();
|
||||
value = value.toLowerCase();
|
||||
}
|
||||
aliasMap.put(name, value);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 ActionTech.
|
||||
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
* Copyright (C) 2016-2020 ActionTech.
|
||||
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
package com.actiontech.dble.util;
|
||||
|
||||
import com.actiontech.dble.backend.mysql.CharsetUtil;
|
||||
@@ -493,12 +493,9 @@ public final class StringUtil {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static boolean isAlias(String aliasName) {
|
||||
if (aliasName.contains("`.") || aliasName.contains(".`") || aliasName.contains(".")) {
|
||||
return false;
|
||||
}
|
||||
char firstValue = aliasName.charAt(0);
|
||||
return (firstValue == '`') && (firstValue == aliasName.charAt(aliasName.length() - 1));
|
||||
public static boolean containsApostrophe(String tableName) {
|
||||
char firstValue = tableName.charAt(0);
|
||||
return (firstValue == '`') && (firstValue == tableName.charAt(tableName.length() - 1));
|
||||
}
|
||||
|
||||
public static String removeAllApostrophe(String str) {
|
||||
|
||||
Reference in New Issue
Block a user