Merge pull request #434 from ifooling/master

fix:解决数据源为Oracle时,@explain 报错问题;使用自增主键,代码中获取不到插入id问题
This commit is contained in:
TommyLemon 2022-08-12 18:30:51 +08:00 committed by GitHub
commit fca6ffd206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -3979,7 +3979,7 @@ public abstract class AbstractSQLConfig implements SQLConfig {
}
return "DELETE FROM " + tablePath + config.getWhereString(true) + (config.isMySQL() ? config.getLimitString() : ""); // PostgreSQL 不允许 LIMIT
default:
String explain = (config.isExplain() ? (config.isSQLServer() || config.isOracle() ? "SET STATISTICS PROFILE ON " : "EXPLAIN ") : "");
String explain = config.isExplain() ? (config.isSQLServer() ? "SET STATISTICS PROFILE ON " : (config.isOracle() ? "EXPLAIN PLAN FOR " : "EXPLAIN ")) : "";
if (config.isTest() && RequestMethod.isGetMethod(config.getMethod(), true)) { // FIXME 为啥是 code 而不是 count
String q = config.getQuote(); // 生成 SELECT ( (24 >=0 AND 24 <3) ) AS `code` LIMIT 1 OFFSET 0
return explain + "SELECT " + config.getWhereString(false) + " AS " + q + JSONResponse.KEY_COUNT + q + config.getLimitString();

View File

@ -1068,7 +1068,13 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
PreparedStatement statement; //创建Statement对象
if (config.getMethod() == RequestMethod.POST && config.getId() == null) { //自增id
statement = getConnection(config).prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
if (config.isOracle()) {
// 解决 oracle 使用自增主键 插入获取不到id问题
String[] generatedColumns = {config.getIdKey()};
statement = getConnection(config).prepareStatement(sql, generatedColumns);
} else {
statement = getConnection(config).prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
}
}
else if (RequestMethod.isGetMethod(config.getMethod(), true)) {
statement = getConnection(config).prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
@ -1250,7 +1256,7 @@ public abstract class AbstractSQLExecutor implements SQLExecutor {
if (config.getId() == null && config.getMethod() == RequestMethod.POST) { // 自增id
ResultSet rs = stt.getGeneratedKeys();
if (rs != null && rs.next()) {
config.setId(rs.getLong(1)); //返回插入的主键id FIXME Oracle 拿不到
config.setId(rs.getLong(1));
}
}