Skip to content

Commit

Permalink
Minor refactor of databaseType usage
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu committed Nov 30, 2023
1 parent d71de3d commit 42320c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ public int[] executeBatch() throws SQLException {
private QueryContext createQueryContext(final String originSQL) {
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
String sql = sqlParserRule.isSqlCommentParseEnabled() ? originSQL : SQLHintUtils.removeHint(originSQL);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(getDatabaseType()).parse(sql, false);
HintValueContext hintValueContext = sqlParserRule.isSqlCommentParseEnabled() ? new HintValueContext() : SQLHintUtils.extractHint(originSQL).orElseGet(HintValueContext::new);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(getDatabaseType()).parse(sql, false);
SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), databaseName, hintValueContext).bind(sqlStatement, Collections.emptyList());
return new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereMetaData
SQLParserRule sqlParserRule = globalRuleMetaData.getSingleRule(SQLParserRule.class);
String sql = sqlParserRule.isSqlCommentParseEnabled() ? sqlStatement.getSql() : SQLHintUtils.removeHint(sqlStatement.getSql());
DatabaseType protocolType = metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType();
SQLStatement previewedStatement = sqlParserRule.getSQLParserEngine(protocolType.getTrunkDatabaseType().orElse(protocolType)).parse(sql, false);
HintValueContext hintValueContext = sqlParserRule.isSqlCommentParseEnabled() ? new HintValueContext() : SQLHintUtils.extractHint(sqlStatement.getSql()).orElseGet(HintValueContext::new);
DatabaseType databaseType = protocolType.getTrunkDatabaseType().orElse(protocolType);
SQLStatement previewedStatement = sqlParserRule.getSQLParserEngine(databaseType).parse(sql, false);
SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), databaseName, hintValueContext).bind(previewedStatement, Collections.emptyList());
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext);
connectionSession.setQueryContext(queryContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public Collection<DatabasePacket> execute() {
failedIfContainsMultiStatements();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(packet.getSQL(), true);
DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "MySQL");
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(databaseType).parse(packet.getSQL(), true);
if (!MySQLComStmtPrepareChecker.isAllowedStatement(sqlStatement)) {
throw new UnsupportedPreparedStatementException();
}
Expand Down

0 comments on commit 42320c3

Please sign in to comment.