@@ -26,14 +26,25 @@ static org.hypertrace.core.documentstore.query.Query transformAndLog(
2626 protected ResultSet execute (final Connection connection , PostgresQueryParser queryParser )
2727 throws SQLException {
2828 final String sqlQuery = queryParser .parse ();
29- final PreparedStatement preparedStatement =
30- buildPreparedStatement (sqlQuery , queryParser .getParamsBuilder ().build (), connection );
31- log .debug ("Executing executeQueryV1 sqlQuery:{}" , preparedStatement .toString ());
32- return preparedStatement .executeQuery ();
29+ final Params params = queryParser .getParamsBuilder ().build ();
30+ // this is closed when the corresponding ResultSet is closed in the iterators
31+ PreparedStatement preparedStatement = buildPreparedStatement (sqlQuery , params , connection );
32+ try {
33+ log .debug ("Executing SQL query: {}" , sqlQuery );
34+ return preparedStatement .executeQuery ();
35+ } catch (SQLException e ) {
36+ log .error (
37+ "SQL execution failed. Query: {}, SQLState: {}, ErrorCode: {}" ,
38+ sqlQuery ,
39+ e .getSQLState (),
40+ e .getErrorCode (),
41+ e );
42+ throw e ;
43+ }
3344 }
3445
3546 public PreparedStatement buildPreparedStatement (
36- String sqlQuery , Params params , Connection connection ) throws SQLException , RuntimeException {
47+ String sqlQuery , Params params , Connection connection ) throws SQLException {
3748 PreparedStatement preparedStatement = connection .prepareStatement (sqlQuery );
3849 enrichPreparedStatementWithParams (preparedStatement , params );
3950 return preparedStatement ;
0 commit comments