Thursday, February 12, 2015

sqlsmush: primitive sql/iBATIS query log and parameters log merging

Last year I was doing some SQL log spelunking, and was getting frustrated when I wanted to rerun a query iBATIS had generated for me... it was generating SQL with great big heaps of parameters, but putting the actual injected parameters on a different line of the log, and merging the two was frustrating and error-prone.

I hatched up a primitive script to merge the two lines:

Roughly speaking, the top field gets something like

select * from user where firstname = ? and lastname = ?

and the bottom gets

Parameters: [FOO,BAR]

and then pressing the button spits out

select * from user where firstname = 'FOO' and lastname = 'BAR';

which can actually be copy and pasted into MySQL Workbench or wherever, and modified, and the results inspected.

(It turned out to be easier to suggest double clicking on the log in intelliJ to highlight the whole line, and then it can be copy and pasted in the blank, and so the primitive script kind of relies on that, like how the second line will start with Parameters:)

Primitive, not super-robust, but useful! Coworkers were asking about its location today, and so I thought it deserved its own devblog entry. I enjoy being able to craft and host simple tools such as this.

No comments:

Post a Comment