@@ -1371,99 +1371,147 @@ public String execute(@RequestBody String request, HttpSession session) {
13711371 long startTime = System .currentTimeMillis ();
13721372
13731373 JSONObject req = JSON .parseObject (request );
1374+ String sql = req == null ? null : req .getString ("sql" );
1375+ if (StringUtil .isEmpty (sql )) {
1376+ throw new IllegalArgumentException ("SQL 不能为空!" );
1377+ }
1378+
13741379 String database = req .getString ("database" );
1380+ String schema = req .getString ("schema" );
13751381 String uri = req .getString ("uri" );
13761382 String account = req .getString ("account" );
13771383 String password = req .getString ("password" );
1378- String sql = req .getString ("sql" );
13791384 JSONArray arg = req .getJSONArray ("args" );
13801385 try {
1381- String trimmedSQL = sql .trim ();
1386+ if (StringUtil .isEmpty (database , true )) {
1387+
1388+ int start = uri .indexOf ("://" );
1389+ String prefix = uri .substring (0 , start );
1390+ int mid = prefix .lastIndexOf (":" );
1391+ if (mid >= 0 ) {
1392+ prefix = prefix .substring (mid + 1 );
1393+ }
1394+
1395+ if (DemoSQLExecutor .DATABASE_INFLUXDB .equalsIgnoreCase (prefix )) {
1396+ database = prefix .toUpperCase ();
1397+
1398+ int end = uri .lastIndexOf ("/" );
1399+ if (end >= 0 ) {
1400+ if (StringUtil .isEmpty (schema , true )) {
1401+ schema = uri .substring (end + 1 );
1402+ }
1403+ uri = uri .substring (0 , end );
1404+ }
1405+
1406+ uri = "http" + uri .substring (start );
1407+
1408+ account = "root" ;
1409+ password = "apijson@123" ;
1410+ } else if (DemoSQLExecutor .DATABASE_NEBULA .equalsIgnoreCase (prefix )) {
1411+ database = prefix .toUpperCase ();
1412+ }
1413+ }
1414+
1415+
1416+ String trimmedSQL = sql == null ? null : sql .trim ();
13821417
13831418 List <Object > valueList = arg ;
13841419
13851420 DemoSQLExecutor executor = new DemoSQLExecutor ();
13861421 DemoSQLConfig config = new DemoSQLConfig ();
13871422
1388- config .setDatabase (database ); // "NEBULA"); //
1423+ config .setDatabase (database );
1424+ config .setSchema (schema );
13891425 config .setDBUri (uri );
13901426 config .setDBAccount (account );
13911427 config .setDBPassword (password );
13921428 config .setPrepared (true );
13931429 config .setPreparedValueList (valueList );
1430+ config .setSql (sql );
13941431
1395- String sqlPrefix = trimmedSQL .length () >= 7 ? trimmedSQL .substring (0 , 7 ).toUpperCase () : "" ;
1432+ String sqlPrefix = trimmedSQL == null || trimmedSQL .length () < 7 ? "" : trimmedSQL .substring (0 , 7 ).toUpperCase ();
13961433 boolean isWrite = sqlPrefix .startsWith ("INSERT " ) || sqlPrefix .startsWith ("UPDATE " ) || sqlPrefix .startsWith ("DELETE " );
13971434
1398- long executeStartTime = System . currentTimeMillis () ;
1435+ JSONArray arr = null ;
13991436
1437+ long updateCount = 0 ;
1438+ long executeDuration = 0 ;
1439+ long cursorDuration = 0 ;
1440+ long rsDuration = 0 ;
1441+ long executeStartTime = System .currentTimeMillis ();
14001442
1401- Statement statement = executor .getStatement (config , trimmedSQL );
1402- if (statement instanceof PreparedStatement ) {
1403- if (EXECUTE_STRICTLY ) {
1404- if (isWrite ) {
1405- ((PreparedStatement ) statement ).executeUpdate ();
1443+ if (DemoSQLExecutor .DATABASE_INFLUXDB .equals (database )) {
1444+ JSONObject result = executor .execute (config , false );
1445+ if (isWrite ) {
1446+ updateCount = result == null ? 0 : result .getIntValue (JSONResponse .KEY_COUNT );
1447+ } else {
1448+ arr = result == null ? null : result .getJSONArray (DemoSQLExecutor .KEY_RAW_LIST );
1449+ }
1450+ } else {
1451+ Statement statement = executor .getStatement (config , trimmedSQL );
1452+ if (statement instanceof PreparedStatement ) {
1453+ if (EXECUTE_STRICTLY ) {
1454+ if (isWrite ) {
1455+ ((PreparedStatement ) statement ).executeUpdate ();
1456+ } else {
1457+ ((PreparedStatement ) statement ).executeQuery ();
1458+ }
14061459 } else {
1407- ((PreparedStatement ) statement ).executeQuery ();
1460+ ((PreparedStatement ) statement ).execute ();
1461+ }
1462+ } else {
1463+ if (arg != null && !arg .isEmpty ()) {
1464+ throw new UnsupportedOperationException ("非预编译模式不允许传参 arg !" );
14081465 }
1409- }
1410- else {
1411- ((PreparedStatement ) statement ).execute ();
1412- }
1413- } else {
1414- if (arg != null && ! arg .isEmpty ()) {
1415- throw new UnsupportedOperationException ("非预编译模式不允许传参 arg !" );
1416- }
14171466
1418- if (EXECUTE_STRICTLY ) {
1419- if (isWrite ) {
1420- statement .executeUpdate (sql );
1467+ if (EXECUTE_STRICTLY ) {
1468+ if (isWrite ) {
1469+ statement .executeUpdate (sql );
1470+ } else {
1471+ statement .executeQuery (sql );
1472+ }
14211473 } else {
1422- statement .executeQuery (sql );
1474+ statement .execute (sql );
14231475 }
14241476 }
1425- else {
1426- statement .execute (sql );
1427- }
1428- }
14291477
1430- long executeDuration = System .currentTimeMillis () - executeStartTime ;
1478+ executeDuration = System .currentTimeMillis () - executeStartTime ;
14311479
1432- ResultSet rs = statement .getResultSet ();
1433- ResultSetMetaData rsmd = rs == null ? null : rs .getMetaData ();
1434- int length = rsmd == null ? 0 : rsmd .getColumnCount ();
1480+ arr = new JSONArray ();
1481+ ResultSet rs = statement .getResultSet ();
1482+ ResultSetMetaData rsmd = rs == null ? null : rs .getMetaData ();
1483+ int length = rsmd == null ? 0 : rsmd .getColumnCount ();
14351484
1436- JSONArray arr = new JSONArray ();
14371485
1438- long cursorDuration = 0 ;
1439- long rsDuration = 0 ;
1486+ long cursorStartTime = System .currentTimeMillis ();
1487+ while (rs != null && rs .next ()) {
1488+ cursorDuration += System .currentTimeMillis () - cursorStartTime ;
14401489
1441- long cursorStartTime = System .currentTimeMillis ();
1442- while (rs != null && rs .next ()) {
1443- cursorDuration += System .currentTimeMillis () - cursorStartTime ;
1490+ JSONObject obj = new JSONObject (true );
1491+ for (int i = 1 ; i <= length ; i ++) {
1492+ long sqlStartTime = System .currentTimeMillis ();
1493+ String name = rsmd .getColumnName (i ); // rsmd.getColumnLable(i);
1494+ Object value = rs .getObject (i );
1495+ rsDuration += System .currentTimeMillis () - sqlStartTime ;
14441496
1445- JSONObject obj = new JSONObject (true );
1446- for (int i = 1 ; i <= length ; i ++) {
1447- long sqlStartTime = System .currentTimeMillis ();
1448- String name = rsmd .getColumnName (i ); // rsmd.getColumnLable(i);
1449- Object value = rs .getObject (i );
1450- rsDuration += System .currentTimeMillis () - sqlStartTime ;
1497+ obj .put (name , value );
1498+ }
14511499
1452- obj . put ( name , value );
1500+ arr . add ( obj );
14531501 }
14541502
1455- arr .add (obj );
1503+ // try {
1504+ updateCount = statement .getUpdateCount ();
1505+ // } catch (Throwable e) {
1506+ // e.printStackTrace();
1507+ // }
14561508 }
14571509
14581510 JSONObject result = DemoParser .newSuccessResult ();
14591511 result .put ("sql" , sql );
14601512 result .put ("args" , arg );
14611513 if (isWrite ) {
1462- // try {
1463- result .put ("count" , statement .getUpdateCount ());
1464- // } catch (Throwable e) {
1465- // e.printStackTrace();
1466- // }
1514+ result .put ("count" , updateCount );
14671515 }
14681516 result .put ("list" , arr );
14691517
@@ -1475,7 +1523,10 @@ public String execute(@RequestBody String request, HttpSession session) {
14751523
14761524 result .put ("time:start|duration|end|parse|sql" , startTime + "|" + duration + "|" + endTime + "|" + parseDuration + "|" + sqlDuration );
14771525
1478- // return result.toJSONString();
1526+ if (DemoSQLExecutor .DATABASE_NEBULA .equalsIgnoreCase (database ) == false ) {
1527+ return result .toJSONString ();
1528+ }
1529+
14791530 return com .alibaba .fastjson .JSON .toJSONString (result , new ValueFilter () {
14801531 @ Override
14811532 public Object process (Object o , String key , Object val ) {
0 commit comments