FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix:解决数据源为Oracle时,@explain 报错问题;使用自增主键,代码中获取不到插入id问题 by ifooling · Pull Request #434 · APIJSON/APIJSON · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3979,7 +3979,7 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
}
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();
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,13 @@ public PreparedStatement getStatement(@NotNull SQLConfig config, String sql) thr

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);
Expand Down Expand Up @@ -1250,7 +1256,7 @@ public int executeUpdate(@NotNull SQLConfig config, String sql) throws Exception
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));
}
}

Expand Down

Back | FazBrowse Home | New Git URL