I need to log prepared queries in groovy

To prevent sql injections and the ability to autocomplete quotes for string values โ€‹โ€‹(this is important), I use the following construct:

String name = "ะŸะตั‚ั" Integer status = 1 def query = 'UPDATE my_tbl SET status=? WHERE name=?'; sql.execute (query, [status, name]) 

How can I get a prepared request with substituted parameters? Maybe there are other ways to solve this problem?

  • Why not just log in? Type this: Run the query: 'UPDATE my_tbl SET status =? WHERE name =? ' with parameters: status = 1, name = Peter - ezhov_da
  • @ezhov_da It is possible and so, but groovy performs interesting magic under the hood, for example, adds quotes to string values, converts the date to the appropriate format, and I would like to see the result of these transformations in the logs ideally. - RostD 3:16 pm
  • one
    I am 90% percent sure that this is not groovy, but the usual PreparedStatment, which is groovy and wraps up in the above example, and from there it is quite problematic to get the generated query (there is no open API) - ezhov_da
  • @ezhov_da Then yes, your option is probably the way out. Or, perhaps, is there any option to do this through reflexion? - RostD
  • I think then it is necessary to be tied on specific drivers to a DB. - ezhov_da

0