提交 40f0e66b authored 作者: Thomas Mueller's avatar Thomas Mueller

Fulltext search did not support table names with a backslash.

上级 046bca7e
...@@ -693,7 +693,10 @@ public class FullText { ...@@ -693,7 +693,10 @@ public class FullText {
setting = FullTextSettings.getInstance(conn); setting = FullTextSettings.getInstance(conn);
ArrayList keyList = new ArrayList(); ArrayList keyList = new ArrayList();
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null, schemaName, tableName, null); ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
ArrayList columnList = new ArrayList(); ArrayList columnList = new ArrayList();
while (rs.next()) { while (rs.next()) {
columnList.add(rs.getString("COLUMN_NAME")); columnList.add(rs.getString("COLUMN_NAME"));
...@@ -704,12 +707,17 @@ public class FullText { ...@@ -704,12 +707,17 @@ public class FullText {
index.table = tableName; index.table = tableName;
index.columns = new String[columnList.size()]; index.columns = new String[columnList.size()];
columnList.toArray(index.columns); columnList.toArray(index.columns);
rs = meta.getColumns(null, schemaName, tableName, null); rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
for (int i = 0; rs.next(); i++) { for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE"); columnTypes[i] = rs.getInt("DATA_TYPE");
} }
if (keyList.size() == 0) { if (keyList.size() == 0) {
rs = meta.getPrimaryKeys(null, schemaName, tableName); rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
tableName);
while (rs.next()) { while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
} }
......
...@@ -38,6 +38,7 @@ import org.h2.expression.ExpressionColumn; ...@@ -38,6 +38,7 @@ import org.h2.expression.ExpressionColumn;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.store.fs.FileSystem; import org.h2.store.fs.FileSystem;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.JdbcUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
//## Java 1.4 end ## //## Java 1.4 end ##
...@@ -368,7 +369,10 @@ public class FullTextLucene extends FullText { ...@@ -368,7 +369,10 @@ public class FullTextLucene extends FullText {
this.indexModifier = getIndexModifier(conn); this.indexModifier = getIndexModifier(conn);
ArrayList keyList = new ArrayList(); ArrayList keyList = new ArrayList();
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null, schemaName, tableName, null); ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
ArrayList columnList = new ArrayList(); ArrayList columnList = new ArrayList();
while (rs.next()) { while (rs.next()) {
columnList.add(rs.getString("COLUMN_NAME")); columnList.add(rs.getString("COLUMN_NAME"));
...@@ -376,12 +380,17 @@ public class FullTextLucene extends FullText { ...@@ -376,12 +380,17 @@ public class FullTextLucene extends FullText {
columnTypes = new int[columnList.size()]; columnTypes = new int[columnList.size()];
columns = new String[columnList.size()]; columns = new String[columnList.size()];
columnList.toArray(columns); columnList.toArray(columns);
rs = meta.getColumns(null, schemaName, tableName, null); rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName),
null);
for (int i = 0; rs.next(); i++) { for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE"); columnTypes[i] = rs.getInt("DATA_TYPE");
} }
if (keyList.size() == 0) { if (keyList.size() == 0) {
rs = meta.getPrimaryKeys(null, schemaName, tableName); rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName),
tableName);
while (rs.next()) { while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
} }
...@@ -390,7 +399,9 @@ public class FullTextLucene extends FullText { ...@@ -390,7 +399,9 @@ public class FullTextLucene extends FullText {
throw new SQLException("No primary key for table " + tableName); throw new SQLException("No primary key for table " + tableName);
} }
ArrayList indexList = new ArrayList(); ArrayList indexList = new ArrayList();
PreparedStatement prep = conn.prepareStatement("SELECT COLUMNS FROM "+SCHEMA+".INDEXES WHERE SCHEMA=? AND TABLE=?"); PreparedStatement prep = conn.prepareStatement(
"SELECT COLUMNS FROM " + SCHEMA
+ ".INDEXES WHERE SCHEMA=? AND TABLE=?");
prep.setString(1, schemaName); prep.setString(1, schemaName);
prep.setString(2, tableName); prep.setString(2, tableName);
rs = prep.executeQuery(); rs = prep.executeQuery();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论