Skip to content

Commit

Permalink
fix(sql-check): failed to check statement when connect to a lower cas…
Browse files Browse the repository at this point in the history
…e schema (#1341)

* fix issue #1337

* update submodule
  • Loading branch information
yhilmare committed Jan 3, 2024
1 parent c461bcd commit 9dc1b3d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,36 @@ private static String getDbUser(@NonNull ConnectionConfig connectionConfig) {
return username;
}

public static String getSchema(@NonNull String schema, @NonNull DialectType dialectType) {
switch (dialectType) {
case OB_ORACLE:
case ORACLE:
return "\"" + schema + "\"";
case OB_MYSQL:
case MYSQL:
case ODP_SHARDING_OB_MYSQL:
return schema;
default:
return null;
}
}

public static String getDefaultSchema(@NonNull ConnectionConfig connectionConfig) {
String defaultSchema = connectionConfig.getDefaultSchema();
switch (connectionConfig.getDialectType()) {
case OB_ORACLE:
case ORACLE:
if (StringUtils.isNotEmpty(defaultSchema)) {
return "\"" + defaultSchema + "\"";
return getSchema(defaultSchema, connectionConfig.getDialectType());
}
return "\"" + getDbUser(connectionConfig) + "\"";
return getSchema(getDbUser(connectionConfig), connectionConfig.getDialectType());
case OB_MYSQL:
case MYSQL:
case ODP_SHARDING_OB_MYSQL:
if (StringUtils.isNotEmpty(defaultSchema)) {
return defaultSchema;
return getSchema(defaultSchema, connectionConfig.getDialectType());
}
return OdcConstants.MYSQL_DEFAULT_SCHEMA;
return getSchema(OdcConstants.MYSQL_DEFAULT_SCHEMA, connectionConfig.getDialectType());
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public List<CheckViolation> check(@NotNull Long environmentId, @NonNull String d
Environment env = this.environmentService.detail(environmentId);
List<Rule> rules = this.ruleService.list(env.getRulesetId(), QueryRuleMetadataParams.builder().build());
OBConsoleDataSourceFactory factory = new OBConsoleDataSourceFactory(config, true, false);
factory.resetSchema(origin -> databaseName);
factory.resetSchema(origin -> OBConsoleDataSourceFactory.getSchema(databaseName, config.getDialectType()));
SqlCheckContext checkContext = new SqlCheckContext((long) sqls.size());
try (SingleConnectionDataSource dataSource = (SingleConnectionDataSource) factory.getDataSource()) {
JdbcTemplate jdbc = new JdbcTemplate(dataSource);
Expand Down

0 comments on commit 9dc1b3d

Please sign in to comment.