|
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
|
|
import net.sf.jsqlparser.JSQLParserException;
|
|
|
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
|
|
import net.sf.jsqlparser.statement.Statement;
|
|
|
+import net.sf.jsqlparser.statement.Statements;
|
|
|
import net.sf.jsqlparser.statement.delete.Delete;
|
|
|
import net.sf.jsqlparser.statement.insert.Insert;
|
|
|
import net.sf.jsqlparser.statement.select.Select;
|
|
@@ -60,10 +61,21 @@ public abstract class AbstractJsqlParser implements ISqlParser {
|
|
|
public SqlInfo optimizeSql(MetaObject metaObject, String sql) {
|
|
|
if (this.allowProcess(metaObject)) {
|
|
|
try {
|
|
|
- Statement statement = CCJSqlParserUtil.parse(sql);
|
|
|
logger.debug("Original SQL: " + sql);
|
|
|
- if (null != statement) {
|
|
|
- return this.processParser(statement);
|
|
|
+ // fixed github pull/295
|
|
|
+ StringBuilder sqlStringBuilder = new StringBuilder();
|
|
|
+ Statements statements = CCJSqlParserUtil.parseStatements(sql);
|
|
|
+ int i = 0;
|
|
|
+ for (Statement statement : statements.getStatements()) {
|
|
|
+ if (null != statement) {
|
|
|
+ if (i++ > 0) {
|
|
|
+ sqlStringBuilder.append(';');
|
|
|
+ }
|
|
|
+ sqlStringBuilder.append(this.processParser(statement).getSql());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sqlStringBuilder.length() > 0) {
|
|
|
+ return SqlInfo.newInstance().setSql(sqlStringBuilder.toString());
|
|
|
}
|
|
|
} catch (JSQLParserException e) {
|
|
|
throw new MybatisPlusException("Failed to process, please exclude the tableName or statementId.\n Error SQL: " + sql, e);
|