@@ -317,34 +317,24 @@ public List<Map<String, Object>> executeQuery(String sql, List<?> params) {
317317 try (PreparedStatement pstmt = getConnection ().prepareStatement (sql )) {
318318 bindParameters (pstmt , params );
319319
320- boolean isQuery = sql .trim ().toLowerCase ().startsWith ("select" );
321-
322- if (isQuery ) {
323- try (ResultSet rs = pstmt .executeQuery ()) {
324- ResultSetMetaData metaData = rs .getMetaData ();
325- int columnCount = metaData .getColumnCount ();
326-
327- while (rs .next ()) {
328- Map <String , Object > row = new LinkedHashMap <>();
329- for (int i = 1 ; i <= columnCount ; i ++) {
330- String colName = metaData .getColumnLabel (i );
331- if (colName == null || colName .isEmpty ()) {
332- colName = metaData .getColumnName (i );
333- }
334- row .put (colName , rs .getObject (i ));
320+ try (ResultSet rs = pstmt .executeQuery ()) {
321+ ResultSetMetaData metaData = rs .getMetaData ();
322+ int columnCount = metaData .getColumnCount ();
323+
324+ while (rs .next ()) {
325+ Map <String , Object > row = new LinkedHashMap <>();
326+ for (int i = 1 ; i <= columnCount ; i ++) {
327+ String colName = metaData .getColumnLabel (i );
328+ if (colName == null || colName .isEmpty ()) {
329+ colName = metaData .getColumnName (i );
335330 }
336- results . add ( row );
331+ row . put ( colName , rs . getObject ( i ) );
337332 }
333+ results .add (row );
338334 }
339- logger .debug ("Query returned " + results .size () + " rows" );
340- } else {
341- int affected = pstmt .executeUpdate ();
342- logger .debug ("Update affected " + affected + " rows" );
343- Map <String , Object > resultRow = new LinkedHashMap <>();
344- resultRow .put ("affectedRows" , affected );
345- results .add (resultRow );
346335 }
347-
336+
337+ logger .debug ("Query returned " + results .size () + " rows" );
348338 return results ;
349339 } catch (SQLException e ) {
350340 logger .error ("Query failed: " + e .getMessage () + " [SQL: " + sql + "]" );
@@ -1033,15 +1023,15 @@ public long count(String tableName, Map<String, Object> whereClause) {
10331023 validateIdentifier (tableName );
10341024
10351025 StringBuilder sql = new StringBuilder ("SELECT COUNT(*) FROM " )
1036- .append (quoteIdentifier (tableName ));
1026+ .append (quoteIdentifier (tableName ));
10371027
10381028 List <Object > whereValues = new ArrayList <>();
10391029 if (whereClause != null && !whereClause .isEmpty ()) {
10401030 List <String > whereConditions = new ArrayList <>();
10411031 for (Map .Entry <String , Object > entry : whereClause .entrySet ()) {
10421032 validateIdentifier (entry .getKey ());
10431033 whereConditions .add (quoteIdentifier (entry .getKey ()) +
1044- (entry .getValue () == null ? " IS ?" : " = ?" ));
1034+ (entry .getValue () == null ? " IS ?" : " = ?" ));
10451035 whereValues .add (entry .getValue ());
10461036 }
10471037 sql .append (" WHERE " ).append (String .join (" AND " , whereConditions ));
@@ -1065,7 +1055,7 @@ public long count(String tableName, Map<String, Object> whereClause) {
10651055 }
10661056 } catch (SQLException e ) {
10671057 logger .error ("Count failed for table '" + tableName + "': " +
1068- e .getMessage () + " [SQL: " + sqlString + "]" );
1058+ e .getMessage () + " [SQL: " + sqlString + "]" );
10691059 throw new RuntimeException (e );
10701060 }
10711061 }
@@ -1096,4 +1086,4 @@ public void execute(String sql, List<?> params) {
10961086 public void execute (String sql , Object ... params ) {
10971087 execute (sql , Arrays .asList (params ));
10981088 }
1099- }
1089+ }
0 commit comments