提交 511fceff authored 作者: Thomas Mueller's avatar Thomas Mueller

Move method to StringUtils to avoid classloading problems on Android.

上级 b9337c2d
...@@ -36,7 +36,6 @@ import org.h2.jdbc.JdbcConnection; ...@@ -36,7 +36,6 @@ import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -847,8 +846,8 @@ public class FullText { ...@@ -847,8 +846,8 @@ public class FullText {
ArrayList<String> keyList = New.arrayList(); ArrayList<String> keyList = New.arrayList();
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null, ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName), StringUtils.escapeMetaDataPattern(tableName),
null); null);
ArrayList<String> columnList = New.arrayList(); ArrayList<String> columnList = New.arrayList();
while (rs.next()) { while (rs.next()) {
...@@ -861,15 +860,15 @@ public class FullText { ...@@ -861,15 +860,15 @@ public class FullText {
index.columns = new String[columnList.size()]; index.columns = new String[columnList.size()];
columnList.toArray(index.columns); columnList.toArray(index.columns);
rs = meta.getColumns(null, rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName), StringUtils.escapeMetaDataPattern(tableName),
null); 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, rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName); tableName);
while (rs.next()) { while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
......
...@@ -33,7 +33,6 @@ import org.h2.expression.ExpressionColumn; ...@@ -33,7 +33,6 @@ import org.h2.expression.ExpressionColumn;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -531,8 +530,8 @@ public class FullTextLucene extends FullText { ...@@ -531,8 +530,8 @@ public class FullTextLucene extends FullText {
ArrayList<String> keyList = New.arrayList(); ArrayList<String> keyList = New.arrayList();
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getColumns(null, ResultSet rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName), StringUtils.escapeMetaDataPattern(tableName),
null); null);
ArrayList<String> columnList = New.arrayList(); ArrayList<String> columnList = New.arrayList();
while (rs.next()) { while (rs.next()) {
...@@ -542,15 +541,15 @@ public class FullTextLucene extends FullText { ...@@ -542,15 +541,15 @@ public class FullTextLucene extends FullText {
columns = new String[columnList.size()]; columns = new String[columnList.size()];
columnList.toArray(columns); columnList.toArray(columns);
rs = meta.getColumns(null, rs = meta.getColumns(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName), StringUtils.escapeMetaDataPattern(tableName),
null); 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, rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName); tableName);
while (rs.next()) { while (rs.next()) {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
......
...@@ -14,7 +14,6 @@ import java.util.ArrayList; ...@@ -14,7 +14,6 @@ import java.util.ArrayList;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
...@@ -66,8 +65,8 @@ public class UpdatableRow { ...@@ -66,8 +65,8 @@ public class UpdatableRow {
} }
final DatabaseMetaData meta = conn.getMetaData(); final DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getTables(null, ResultSet rs = meta.getTables(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
JdbcUtils.escapeMetaDataPattern(tableName), StringUtils.escapeMetaDataPattern(tableName),
new String[] { "TABLE" }); new String[] { "TABLE" });
if (!rs.next()) { if (!rs.next()) {
return; return;
...@@ -83,7 +82,7 @@ public class UpdatableRow { ...@@ -83,7 +82,7 @@ public class UpdatableRow {
boolean toUpper = !table.equals(tableName) && table.equalsIgnoreCase(tableName); boolean toUpper = !table.equals(tableName) && table.equalsIgnoreCase(tableName);
key = New.arrayList(); key = New.arrayList();
rs = meta.getPrimaryKeys(null, rs = meta.getPrimaryKeys(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName); tableName);
while (rs.next()) { while (rs.next()) {
String c = rs.getString("COLUMN_NAME"); String c = rs.getString("COLUMN_NAME");
...@@ -95,7 +94,7 @@ public class UpdatableRow { ...@@ -95,7 +94,7 @@ public class UpdatableRow {
} }
key.clear(); key.clear();
rs = meta.getIndexInfo(null, rs = meta.getIndexInfo(null,
JdbcUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName, true, true); tableName, true, true);
while (rs.next()) { while (rs.next()) {
int pos = rs.getShort("ORDINAL_POSITION"); int pos = rs.getShort("ORDINAL_POSITION");
......
...@@ -118,19 +118,6 @@ public class JdbcUtils { ...@@ -118,19 +118,6 @@ public class JdbcUtils {
return getConnection(driver, url, prop); return getConnection(driver, url, prop);
} }
/**
* Escape table or schema patterns used for DatabaseMetaData functions.
*
* @param pattern the pattern
* @return the escaped pattern
*/
public static String escapeMetaDataPattern(String pattern) {
if (pattern == null || pattern.length() == 0) {
return pattern;
}
return StringUtils.replaceAll(pattern, "\\", "\\\\");
}
/** /**
* Open a new database connection with the given settings. * Open a new database connection with the given settings.
* *
......
...@@ -1078,4 +1078,17 @@ public class StringUtils { ...@@ -1078,4 +1078,17 @@ public class StringUtils {
} }
} }
/**
* Escape table or schema patterns used for DatabaseMetaData functions.
*
* @param pattern the pattern
* @return the escaped pattern
*/
public static String escapeMetaDataPattern(String pattern) {
if (pattern == null || pattern.length() == 0) {
return pattern;
}
return replaceAll(pattern, "\\", "\\\\");
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论