2323import java .io .Serializable ;
2424import java .sql .Connection ;
2525import java .sql .SQLException ;
26+ import java .util .Collection ;
2627import java .util .List ;
2728import java .util .Map ;
2829import java .util .Properties ;
@@ -123,7 +124,6 @@ public synchronized void removeCache(String sql, SQLConfig config) {
123124 // Redis 缓存 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
124125
125126 public static final String DATABASE_NEBULA = "NEBULA" ;
126- public static final String DATABASE_INFLUXDB = "INFLUXDB" ;
127127
128128 // 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount, dbPassword
129129 @ Override
@@ -195,16 +195,20 @@ public Connection getConnection(SQLConfig config) throws Exception {
195195
196196
197197 @ Override
198- public JSONObject execute (SQLConfig config , boolean unknownType ) throws Exception {
199- if (DATABASE_INFLUXDB .equals (config .getDatabase ())) {
198+ public JSONObject execute (@ NotNull SQLConfig config , boolean unknownType ) throws Exception {
199+ if (DemoSQLConfig . DATABASE_INFLUXDB .equals (config .getDatabase ())) {
200200 InfluxDB influxDB = InfluxDBFactory .connect (config .getDBUri (), config .getDBAccount (), config .getDBPassword ());
201-
202201 influxDB .setDatabase (config .getSchema ());
203202
204203 String sql = config .getSQL (config .isPrepared ());
205- String trimmedSQL = sql == null ? null : sql .trim ();
206- String sqlPrefix = trimmedSQL == null || trimmedSQL .length () < 7 ? "" : trimmedSQL .substring (0 , 7 ).toUpperCase ();
207- boolean isWrite = sqlPrefix .startsWith ("INSERT " ) || sqlPrefix .startsWith ("UPDATE " ) || sqlPrefix .startsWith ("DELETE " );
204+
205+ RequestMethod method = config .getMethod ();
206+ boolean isWrite = ! RequestMethod .isQueryMethod (method );
207+ if (method == null && ! isWrite ) {
208+ String trimmedSQL = sql == null ? null : sql .trim ();
209+ String sqlPrefix = trimmedSQL == null || trimmedSQL .length () < 7 ? "" : trimmedSQL .substring (0 , 7 ).toUpperCase ();
210+ isWrite = sqlPrefix .startsWith ("INSERT " ) || sqlPrefix .startsWith ("UPDATE " ) || sqlPrefix .startsWith ("DELETE " );
211+ }
208212
209213 if (isWrite ) {
210214 influxDB .enableBatch (
@@ -220,8 +224,30 @@ public JSONObject execute(SQLConfig config, boolean unknownType) throws Exceptio
220224
221225 influxDB .write (sql );
222226
223- JSONObject result = new JSONObject (true );
224- result .put (JSONResponse .KEY_COUNT , 1 ); // FIXME
227+ JSONObject result = DemoParser .newSuccessResult ();
228+
229+ if (method == RequestMethod .POST ) {
230+ List <List <Object >> values = config .getValues ();
231+ result .put (JSONResponse .KEY_COUNT , values == null ? 0 : values .size ());
232+ } else {
233+ String idKey = config .getIdKey ();
234+ Object id = config .getId ();
235+ Object idIn = config .getIdIn ();
236+ if (id != null ) {
237+ result .put (idKey , id );
238+ }
239+ if (idIn != null ) {
240+ result .put (idKey + "[]" , idIn );
241+ }
242+
243+ if (method == RequestMethod .PUT ) {
244+ Map <String , Object > content = config .getContent ();
245+ result .put (JSONResponse .KEY_COUNT , content == null ? 0 : content .size ());
246+ } else {
247+ result .put (JSONResponse .KEY_COUNT , id == null && idIn instanceof Collection ? ((Collection <?>) idIn ).size () : 1 ); // FIXME 直接 SQLAuto 传 Flux/InfluxQL INSERT 如何取数量?
248+ }
249+ }
250+
225251 return result ;
226252 }
227253
@@ -238,7 +264,7 @@ public JSONObject execute(SQLConfig config, boolean unknownType) throws Exceptio
238264 }
239265
240266 JSONObject result = JSON .parseObject (list .get (0 ));
241- if (list .size () > 0 ) {
267+ if (list .size () > 1 ) {
242268 result .put (KEY_RAW_LIST , list );
243269 }
244270
0 commit comments