-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented incl. tests and changes file (#143)
- Loading branch information
Showing
14 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Virtual Schema Common JDBC 10.5.0, released 2023-03-15 | ||
|
||
Code name: Escape SQL Wild Cards Optionally | ||
|
||
## Summary | ||
|
||
Release 10.3.0 introduced escaping wild cards in the names of database schemas and tables when retrieving column metadata from JDBC. | ||
|
||
The current release fixes two problems in this area | ||
|
||
| Problem | Fix | | ||
|------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------| | ||
| VSCJDBC also escaped wild cards in the name of the database catalog, conflicting with the parameter's documentation as literal string. | Do not escape potential wild cards in the name of the database catalog. | | ||
| VSCJDBC always used the backslash as escape string, while there are SQL dialects with different escape string, e.g. VSORA using a forward slash `/`. | Use `java.sql.DatabaseMetaData.getSearchStringEscape()` to inquire the escape string for the specific SQL dialect. | | ||
|
||
Additionally the current release makes wild card escaping optional. In case of problems SQL dialects then can simply override `BaseColumnMetadataReader.getColumnMetadata`: | ||
```java | ||
@Override | ||
protected ResultSet getColumnMetadata(String catalogName, String schemaName, String tableName) throws SQLException { | ||
return getColumnMetadataAllowingPatterns(catalogName, schemaName, tableName); | ||
} | ||
``` | ||
|
||
## Bugfixes | ||
|
||
* #142: Fixed escaping wildcards in column lookup and made escaping optional | ||
|
||
## Dependency Updates | ||
|
||
### Test Dependency Updates | ||
|
||
* Updated `org.mockito:mockito-junit-jupiter:5.1.1` to `5.2.0` | ||
|
||
### Plugin Dependency Updates | ||
|
||
* Updated `com.exasol:project-keeper-maven-plugin:2.9.3` to `2.9.4` | ||
* Updated `org.apache.maven.plugins:maven-deploy-plugin:3.0.0` to `3.1.0` | ||
* Updated `org.apache.maven.plugins:maven-enforcer-plugin:3.1.0` to `3.2.1` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/exasol/adapter/jdbc/WildcardEscaper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.exasol.adapter.jdbc; | ||
|
||
import java.sql.DatabaseMetaData; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Escape SQL wild cards in string to enable to request column metadata from JDBC driver with exact match for names of | ||
* catalog, schema, and table. | ||
*/ | ||
public class WildcardEscaper { | ||
|
||
private static final Pattern REGEX_WILDCARDS = Pattern.compile("[\\\\$]"); | ||
private static final Pattern SQL_WINDCARDS = Pattern.compile("[_%]"); | ||
|
||
/** | ||
* Create a new instance of the {@link WildcardEscaper}. | ||
* <p> | ||
* Use {@link DatabaseMetaData#getSearchStringEscape()} to get the escape string for wild card characters. | ||
* | ||
* @param searchStringEscape string that should be used to escape SQL wild cards | ||
* @return new instance of the {@link WildcardEscaper} | ||
*/ | ||
public static WildcardEscaper instance(final String searchStringEscape) { | ||
final String escaped = new WildcardEscaper(REGEX_WILDCARDS, "\\\\").escape(searchStringEscape); | ||
return new WildcardEscaper(SQL_WINDCARDS, escaped); | ||
} | ||
|
||
private final Pattern pattern; | ||
private final String replacement; | ||
|
||
WildcardEscaper(final Pattern pattern, final String replacement) { | ||
this.pattern = pattern; | ||
this.replacement = replacement + "$0"; | ||
} | ||
|
||
/** | ||
* @param input Name of catalog, schema, or table | ||
* @return name with potential wild cards escaped. | ||
*/ | ||
public String escape(final String input) { | ||
final Matcher matcher = this.pattern.matcher(input); | ||
return matcher.find() ? matcher.replaceAll(this.replacement) : input; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.