sql执行器解析增加数据库类型判断

pull/12/head^2
diantu 2 years ago
parent b2d5a86da6
commit bcf675943c

@ -78,7 +78,7 @@
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>8.1.1.193</version>
<version>8.1.2.192</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>

@ -1,13 +1,11 @@
package com.zyplayer.doc.db.controller;
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.annotation.AuthMan;
import com.zyplayer.doc.core.exception.ConfirmException;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.DbFavorite;
@ -21,8 +19,7 @@ import com.zyplayer.doc.db.framework.consts.DbAuthType;
import com.zyplayer.doc.db.framework.db.mapper.base.*;
import com.zyplayer.doc.db.framework.db.transfer.SqlParseUtil;
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
import com.zyplayer.doc.db.framework.utils.JSONUtil;
import com.zyplayer.doc.db.framework.utils.SqlLogUtil;
import com.zyplayer.doc.db.framework.utils.SQLTransformUtils;
import com.zyplayer.doc.db.service.database.DatabaseServiceFactory;
import com.zyplayer.doc.db.service.database.DbBaseService;
import org.apache.commons.lang3.StringUtils;
@ -76,7 +73,11 @@ public class DbSqlExecutorController {
// 解析出多个执行的SQL
List<String> analysisQuerySqlList = new LinkedList<>();
try {
List<SQLStatement> sqlStatements = new MySqlStatementParser(sql).parseStatementList();
String driverClassName = dbBaseService.getDatabaseProduct().getDriverClassName();
List<SQLStatement> sqlStatements = new ArrayList<SQLStatement>();
//根据驱动程序类名获取数据库类型
DbType dbType = SQLTransformUtils.getDbTypeByDriverClassName(driverClassName);
sqlStatements = new SQLStatementParser(sql,dbType).parseStatementList();
for (SQLStatement sqlStatement : sqlStatements) {
analysisQuerySqlList.add(sqlStatement.toString());
}

@ -7,7 +7,7 @@ import com.alibaba.druid.sql.dialect.mysql.parser.MySqlLexer;
import com.alibaba.druid.sql.dialect.oracle.parser.OracleLexer;
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerLexer;
import com.alibaba.druid.sql.parser.Keywords;
import com.alibaba.druid.sql.parser.Lexer;
import com.zyplayer.doc.db.framework.db.enums.DatabaseProductEnum;
import com.zyplayer.doc.db.framework.db.sql.dialect.mysql.MySqlToOracleOutputVisitor;
import com.zyplayer.doc.db.framework.db.sql.dialect.mysql.MySqlToSqlServerOutputVisitor;
import com.zyplayer.doc.db.framework.db.sql.dialect.oracle.OracleToMySqlOutputVisitor;
@ -145,4 +145,29 @@ public class SQLTransformUtils {
}
return Keywords.DEFAULT_KEYWORDS.getKeywords().containsKey(name.toUpperCase());
}
/**
*
* @param driverClassName
* @return DbType
*/
public static DbType getDbTypeByDriverClassName(String driverClassName) {
DbType dbType;
if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.MYSQL.name())){
dbType = DbType.mysql;
}else if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.ORACLE.name())){
dbType = DbType.oracle;
}else if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.DM.name())){
dbType = DbType.dm;
}else if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.SQLSERVER.name())){
dbType = DbType.sqlserver;
}else if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.POSTGRESQL.name())){
dbType = DbType.postgresql;
}else if(driverClassName.equalsIgnoreCase(DatabaseProductEnum.HIVE.name())){
dbType = DbType.hive;
}else{
dbType = DbType.other;
}
return dbType;
}
}

Loading…
Cancel
Save