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

MySQL compatibility: linked tables had lower case column names on some systems.

上级 2c705386
...@@ -46,6 +46,10 @@ public class TableLink extends Table { ...@@ -46,6 +46,10 @@ public class TableLink extends Table {
private final boolean emitUpdates; private final boolean emitUpdates;
private LinkedIndex linkedIndex; private LinkedIndex linkedIndex;
private SQLException connectException; private SQLException connectException;
private boolean storesLowerCase;
private boolean storesMixedCase;
private boolean supportsMixedCaseIdentifiers;
public TableLink(Schema schema, int id, String name, String driver, String url, String user, String password, public TableLink(Schema schema, int id, String name, String driver, String url, String user, String password,
String originalTable, boolean emitUpdates, boolean force) throws SQLException { String originalTable, boolean emitUpdates, boolean force) throws SQLException {
...@@ -73,9 +77,9 @@ public class TableLink extends Table { ...@@ -73,9 +77,9 @@ public class TableLink extends Table {
private void connect() throws SQLException { private void connect() throws SQLException {
conn = JdbcUtils.getConnection(driver, url, user, password); conn = JdbcUtils.getConnection(driver, url, user, password);
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
boolean storesLowerCase = meta.storesLowerCaseIdentifiers(); storesLowerCase = meta.storesLowerCaseIdentifiers();
boolean storesMixedCase = meta.storesMixedCaseIdentifiers(); storesMixedCase = meta.storesMixedCaseIdentifiers();
boolean supportsMixedCaseIdentifiers = meta.supportsMixedCaseIdentifiers(); supportsMixedCaseIdentifiers = meta.supportsMixedCaseIdentifiers();
ResultSet rs = meta.getColumns(null, null, originalTable, null); ResultSet rs = meta.getColumns(null, null, originalTable, null);
int i = 0; int i = 0;
ObjectArray columnList = new ObjectArray(); ObjectArray columnList = new ObjectArray();
...@@ -98,12 +102,7 @@ public class TableLink extends Table { ...@@ -98,12 +102,7 @@ public class TableLink extends Table {
break; break;
} }
String n = rs.getString("COLUMN_NAME"); String n = rs.getString("COLUMN_NAME");
if (storesLowerCase && n.equals(StringUtils.toLowerEnglish(n))) { n = convertColumnName(n);
n = StringUtils.toUpperEnglish(n);
} else if (storesMixedCase && !supportsMixedCaseIdentifiers) {
// TeraData
n = StringUtils.toUpperEnglish(n);
}
int sqlType = rs.getInt("DATA_TYPE"); int sqlType = rs.getInt("DATA_TYPE");
long precision = rs.getInt("COLUMN_SIZE"); long precision = rs.getInt("COLUMN_SIZE");
int scale = rs.getInt("DECIMAL_DIGITS"); int scale = rs.getInt("DECIMAL_DIGITS");
...@@ -177,6 +176,7 @@ public class TableLink extends Table { ...@@ -177,6 +176,7 @@ public class TableLink extends Table {
list.add(null); list.add(null);
} }
String col = rs.getString("COLUMN_NAME"); String col = rs.getString("COLUMN_NAME");
col = convertColumnName(col);
Column column = (Column) columnMap.get(col); Column column = (Column) columnMap.get(col);
list.set(idx - 1, column); list.set(idx - 1, column);
} while (rs.next()); } while (rs.next());
...@@ -208,6 +208,7 @@ public class TableLink extends Table { ...@@ -208,6 +208,7 @@ public class TableLink extends Table {
boolean unique = !rs.getBoolean("NON_UNIQUE"); boolean unique = !rs.getBoolean("NON_UNIQUE");
indexType = unique ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false); indexType = unique ? IndexType.createUnique(false, false) : IndexType.createNonUnique(false);
String col = rs.getString("COLUMN_NAME"); String col = rs.getString("COLUMN_NAME");
col = convertColumnName(col);
Column column = (Column) columnMap.get(col); Column column = (Column) columnMap.get(col);
list.add(column); list.add(column);
} }
...@@ -216,6 +217,16 @@ public class TableLink extends Table { ...@@ -216,6 +217,16 @@ public class TableLink extends Table {
} }
} }
private String convertColumnName(String columnName) {
if ((storesMixedCase || storesLowerCase) && columnName.equals(StringUtils.toLowerEnglish(columnName))) {
columnName = StringUtils.toUpperEnglish(columnName);
} else if (storesMixedCase && !supportsMixedCaseIdentifiers) {
// TeraData
columnName = StringUtils.toUpperEnglish(columnName);
}
return columnName;
}
private void addIndex(ObjectArray list, IndexType indexType) { private void addIndex(ObjectArray list, IndexType indexType) {
Column[] cols = new Column[list.size()]; Column[] cols = new Column[list.size()];
list.toArray(cols); list.toArray(cols);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论