Skip to content

Commit

Permalink
JDBC-331 Fix pattern workaround so it also works with a connection ch…
Browse files Browse the repository at this point in the history
…aracterset other than NONE/UNICODE_FSS when the maximum object length has been reached.
  • Loading branch information
mrotteveel committed Nov 24, 2013
1 parent 95c2000 commit 11f22eb
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main/org/firebirdsql/jdbc/AbstractDatabaseMetaData.java
Expand Up @@ -57,15 +57,14 @@
public abstract class AbstractDatabaseMetaData implements FirebirdDatabaseMetaData {

private final static Logger log = LoggerFactory.getLogger(FBDatabaseMetaData.class,false);
public static final String SPACES = " ";//31 spaces
private static final String SPACES_31 = " "; // 31 spaces
private static final String SPACES_15 = " "; // 15 spaces

private GDSHelper gdsHelper;
private AbstractConnection connection;

HashMap statements = new HashMap();

//PreparedStatement tables = null;

protected AbstractDatabaseMetaData(GDSHelper gdsHelper) {
this.gdsHelper = gdsHelper;
}
Expand Down Expand Up @@ -2354,15 +2353,15 @@ public ResultSet getProcedureColumns(String catalog,
private static final String GET_TABLES_LIKE =
TABLE_COLUMNS_SYSTEM
+ " where ? = 'T' and RDB$SYSTEM_FLAG = 1 and RDB$VIEW_SOURCE is null"
+ " and RDB$RELATION_NAME || '" + SPACES + "' like ? escape '\\'"
+ " and RDB$RELATION_NAME || '" + SPACES_31 + "' like ? escape '\\'"
+ " union"
+ TABLE_COLUMNS_NORMAL
+ " where ? = 'T' and RDB$SYSTEM_FLAG = 0 and RDB$VIEW_SOURCE is null"
+ " and RDB$RELATION_NAME || '" + SPACES + "' like ? escape '\\'"
+ " and RDB$RELATION_NAME || '" + SPACES_31 + "' like ? escape '\\'"
+ " union"
+ TABLE_COLUMNS_VIEW
+ " where ? = 'T' and RDB$VIEW_SOURCE is not null"
+ " and RDB$RELATION_NAME || '" + SPACES + "' like ? escape '\\' "
+ " and RDB$RELATION_NAME || '" + SPACES_31 + "' like ? escape '\\' "
+ " order by 3 ";

/**
Expand Down Expand Up @@ -2441,8 +2440,9 @@ else if (hasNoWildcards(tableNamePattern)) {
params.add(tableNamePattern);
}
else {
// TODO Usages of 1) uppercase and 2) SPACES + % might be wrong
tableNamePattern = stripQuotes(tableNamePattern, true) + SPACES + "%";
// TODO Usages of 1) uppercase and 2) SPACES_15 + % might be wrong
// See also comment in Clause for explanation
tableNamePattern = stripQuotes(tableNamePattern, true) + SPACES_15 + "%";
sql = GET_TABLES_LIKE;
params.add(getWantsSystemTables(types));
params.add(tableNamePattern);
Expand Down Expand Up @@ -6122,9 +6122,11 @@ else if (hasNoWildcards(pattern)) {
condition = "CAST(" + columnName + " AS VARCHAR(40)) = ? and ";
}
else {
value = stripQuotes(pattern, true) + SPACES + "%";
originalCaseValue = stripQuotes(pattern, false) + SPACES + "%";
condition = columnName + " || '" + SPACES + "' like ? escape '\\' and ";
// We are padding the column with 31 spaces to accommodate arguments longer than the actual column length.
// The argument itself is padded with 15 spaces and a % to prevent false positives, this allows 15 character longer patterns
value = stripQuotes(pattern, true) + SPACES_15 + "%";
originalCaseValue = stripQuotes(pattern, false) + SPACES_15 + "%";
condition = columnName + " || '" + SPACES_31 + "' like ? escape '\\' and ";
}
}

Expand Down

0 comments on commit 11f22eb

Please sign in to comment.