@Override public String getSearchStringEscape() throws SQLException { return metaData.getSearchStringEscape(); }
private static String escapeLikeExpression(Connection connection, String value) throws SQLException { String escapeString = connection.getMetaData().getSearchStringEscape(); return value.replace(escapeString, escapeString + escapeString).replace("_", escapeString + "_").replace("%", escapeString + "%"); }
@Override protected ResultSet getTables(Connection connection, String schemaName, String tableName) throws SQLException { // MySQL maps their "database" to SQL catalogs and does not have schemas DatabaseMetaData metadata = connection.getMetaData(); String escape = metadata.getSearchStringEscape(); return metadata.getTables( schemaName, null, escapeNamePattern(tableName, escape), new String[] {"TABLE", "VIEW"}); }
@Override protected ResultSet getTables(Connection connection, String schemaName, String tableName) throws SQLException { DatabaseMetaData metadata = connection.getMetaData(); String escape = metadata.getSearchStringEscape(); return metadata.getTables( connection.getCatalog(), escapeNamePattern(schemaName, escape), escapeNamePattern(tableName, escape), new String[] {"TABLE", "VIEW", "MATERIALIZED VIEW", "FOREIGN TABLE"}); }
protected ResultSet getTables(Connection connection, String schemaName, String tableName) throws SQLException { DatabaseMetaData metadata = connection.getMetaData(); String escape = metadata.getSearchStringEscape(); return metadata.getTables( connection.getCatalog(), escapeNamePattern(schemaName, escape), escapeNamePattern(tableName, escape), new String[] {"TABLE", "VIEW"}); }
private static ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata) throws SQLException { String escape = metadata.getSearchStringEscape(); return metadata.getColumns( tableHandle.getCatalogName(), escapeNamePattern(tableHandle.getSchemaName(), escape), escapeNamePattern(tableHandle.getTableName(), escape), null); } }
@Test public void testPassEscapeInMetaDataQuery() throws Exception { DatabaseMetaData metaData = connection.getMetaData(); Set<String> queries = captureQueries(() -> { String schemaPattern = "defau" + metaData.getSearchStringEscape() + "_t"; try (ResultSet resultSet = metaData.getColumns("blackhole", schemaPattern, null, null)) { assertFalse(resultSet.next(), "There should be no results"); } return null; }); assertEquals(queries.size(), 1, "Expected exactly one query, got " + queries.size()); String query = getOnlyElement(queries); assertContains(query, "_t' ESCAPE '", "Metadata query does not contain ESCAPE"); }
tableNameFilter = databaseTablePrefix + "ACT" + databaseMetaData.getSearchStringEscape() + "_%";
@Override public String getSearchStringEscape() throws SQLException { return metaData.getSearchStringEscape(); }
/** * Returns {@code true} if the database contains data. This method returns {@code false} if an * empty EPSG database has been automatically created by HSQL and not yet populated. */ static boolean dataExists(final Connection connection) throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); try (final ResultSet tables = metaData.getTables( null, null, "EPSG" + metaData.getSearchStringEscape() + "_%", new String[] {"TABLE"})) { return tables.next(); } } }
/** * Escapes all sql wildcards in the given string, returns the same string if it doesn't contain * any sql wildcards * * @param oldString the string in which to escape the sql wildcards * @param connection The underlying database connection * @return the string with sql wildcards escaped if any found otherwise the original string is * returned */ public static String escapeSqlWildcards(String oldString, Connection connection) { //replace all sql wildcards if any if (!StringUtils.isBlank(oldString)) { String escapeCharacter = ""; try { //get the database specific escape character from the metadata escapeCharacter = connection.getMetaData().getSearchStringEscape(); } catch (SQLException e) { log.warn("Error generated", e); } //insert an escape character before each sql wildcard in the search phrase return StringUtils.replaceEach(oldString, new String[] { "%", "_", "*", "'" }, new String[] { escapeCharacter + "%", escapeCharacter + "_", escapeCharacter + "*", "''" }); } else { return oldString; } }
/** * Escapes a name pattern used in e.g. {@link java.sql.DatabaseMetaData#getColumns(String, * String, String, String)} when passed in argument is an exact name and not a pattern. * * <p>When a table name or column name contains underscore (or percen, but this is rare) the * underscore is treated as a placeholder and not an actual character. So if our intention is to * match an exact name, we must escape such characters. */ public String escapeNamePattern(DatabaseMetaData metaData, String name) throws SQLException { if (namePatternEscaping == null) { namePatternEscaping = new NamePatternEscaping(metaData.getSearchStringEscape()); } return namePatternEscaping.escape(name); } }
systemFunctions = databaseMetaData.getSystemFunctions(); timeDateFunctions = databaseMetaData.getTimeDateFunctions(); searchStringEscape = databaseMetaData.getSearchStringEscape(); extraNameCharacters = databaseMetaData.getExtraNameCharacters(); supportsAlterTableWithAddColumn = databaseMetaData.supportsAlterTableWithAddColumn();
r.refOfIndex("schemaTerm").assign(metaData.getSchemaTerm()); r.refOfIndex("procedureTerm").assign(metaData.getProcedureTerm()); r.refOfIndex("searchStringEscape").assign(metaData.getSearchStringEscape());
@Override public String getSearchStringEscape() throws SQLException { return parent.getSearchStringEscape(); }
@Override public String getSearchStringEscape() throws SQLException { try { return databaseMetaData.getSearchStringEscape(); } catch (final SQLException e) { handleException(e); throw new AssertionError(); } }
public String getSearchStringEscape() throws SQLException { try { return dbmd.getSearchStringEscape(); } catch (SQLException e) { c.connectionError(e); throw e; } }
@Override public String getSearchStringEscape() throws SQLException { try { return wrapped.getSearchStringEscape(); } catch (SQLException e) { throw new UcanaccessSQLException(e); } }
public DremioMetaClientImpl(DremioConnectionImpl connection) throws SQLException { this.connection = connection; this.identifierQuote = connection.getMetaData().getIdentifierQuoteString(); this.searchStringEscape = connection.getMetaData().getSearchStringEscape(); }
private static ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata) throws SQLException { String escape = metadata.getSearchStringEscape(); return metadata.getColumns( tableHandle.getCatalogName(), escapeNamePattern(tableHandle.getSchemaName(), escape), escapeNamePattern(tableHandle.getTableName(), escape), null); } }