|
27 | 27 | import java.util.Map.Entry; |
28 | 28 | import java.util.Objects; |
29 | 29 | import java.util.Set; |
| 30 | +import java.util.regex.Pattern; |
30 | 31 |
|
31 | 32 | import com.alibaba.fastjson.JSON; |
32 | 33 | import com.alibaba.fastjson.JSONObject; |
|
36 | 37 | import apijson.NotNull; |
37 | 38 | import apijson.RequestMethod; |
38 | 39 | import apijson.StringUtil; |
| 40 | +import apijson.orm.AbstractSQLConfig; |
39 | 41 |
|
40 | 42 | /**executor for query(read) or update(write) MySQL database |
41 | 43 | * @author Lemon |
@@ -706,7 +708,15 @@ protected List<JSONObject> onPutTable(@NotNull SQLConfig config, @NotNull Result |
706 | 708 |
|
707 | 709 | protected String getKey(@NotNull SQLConfig config, @NotNull ResultSet rs, @NotNull ResultSetMetaData rsmd |
708 | 710 | , final int tablePosition, @NotNull JSONObject table, final int columnIndex, Map<String, JSONObject> childMap) throws Exception { |
709 | | - return rsmd.getColumnLabel(columnIndex); // dotIndex < 0 ? lable : lable.substring(dotIndex + 1); |
| 711 | + String key = rsmd.getColumnLabel(columnIndex);// dotIndex < 0 ? lable : lable.substring(dotIndex + 1); |
| 712 | + if (config.isHive()) { |
| 713 | + String table_name = config.getTable(); |
| 714 | + if(AbstractSQLConfig.TABLE_KEY_MAP.containsKey(table_name)) table_name = AbstractSQLConfig.TABLE_KEY_MAP.get(table_name); |
| 715 | + String pattern = "^" + table_name + "\\." + "[a-zA-Z]+$"; |
| 716 | + boolean isMatch = Pattern.matches(pattern, key); |
| 717 | + if(isMatch) key = key.split("\\.")[1]; |
| 718 | + } |
| 719 | + return key; |
710 | 720 | } |
711 | 721 |
|
712 | 722 | protected Object getValue(@NotNull SQLConfig config, @NotNull ResultSet rs, @NotNull ResultSetMetaData rsmd |
@@ -962,6 +972,7 @@ public ResultSet executeQuery(@NotNull SQLConfig config) throws Exception { |
962 | 972 | public int executeUpdate(@NotNull SQLConfig config) throws Exception { |
963 | 973 | PreparedStatement s = getStatement(config); |
964 | 974 | int count = s.executeUpdate(); //PreparedStatement 不用传 SQL |
| 975 | + if (config.isHive() && count==0) count = 1; |
965 | 976 |
|
966 | 977 | if (config.getMethod() == RequestMethod.POST && config.getId() == null) { //自增id |
967 | 978 | ResultSet rs = s.getGeneratedKeys(); |
|
0 commit comments