D
Deleted member 43669
Guest
As an SQL fan, I have lots of SQL statements in my application (right now most are embedded quoted within Java code, but I hope to change that). Of course, we all know the parameterization stuff:
However, there's the typical situation when you want to execute variations on SQL queries which are not really well covered by parameterization. For instance, a typical query to display a sortable table; which you might want to execute with different ORDER BY clauses, or a search functionality which lets you choose and combine different search criteria.
You can of course use string concatenation to build those queries, and typically it's not difficult to do it "properly", but I'm wondering if anyone's using a more "sophisticated" approach.
I was thinking SQL-like DSL languages, i.e. Query.build().select(ALL).from("foo").toSQL(), where you can programatically build SQL- this approach would work pretty well in these situations, but I've not found yet a suitable library to do this...
edit: there's also stored procedures... but I'm unsure about that...
... any other ideas?
Alex
Code:
execute("select * from foo where bar = :bar and baz >= :baz", { "bar": myVar, "baz" : 4 });
However, there's the typical situation when you want to execute variations on SQL queries which are not really well covered by parameterization. For instance, a typical query to display a sortable table; which you might want to execute with different ORDER BY clauses, or a search functionality which lets you choose and combine different search criteria.
You can of course use string concatenation to build those queries, and typically it's not difficult to do it "properly", but I'm wondering if anyone's using a more "sophisticated" approach.
I was thinking SQL-like DSL languages, i.e. Query.build().select(ALL).from("foo").toSQL(), where you can programatically build SQL- this approach would work pretty well in these situations, but I've not found yet a suitable library to do this...
edit: there's also stored procedures... but I'm unsure about that...
... any other ideas?
Alex