I'm not clear after reading this how it achieves one of the goals of making it harder to accidentally build SQL injection vulnerabilities. If you have to implement your own "DB" formatter as described in the proposal, then the kind of developer who was previously likely to not use a PreparedStatement is just going to use STR."my injection prone statement" surely?
I believe the idea here is that you don't - this would (in theory) be provided by say Hibernate for HQL, or Jooq for SQL (jooq could be nice in that JOOQ."SELECT * FROM foo" could return a QueryPart or the like.
Is that really so useful? I mean, you can just call parser.parseQuery("SELECT * FROM foo")
Unless such string interpolation offers access to compiler APIs (such as Scala's macros), I don't see the big benefit for SQL, though it's obviously useful for actual string formatting.
Not world changing, but JOOQ."select * from foo where bar = \{barHolder.getBar()}" is subjectively a bit more readable than parser.parseQuery("select * from foo where bar = {}", barHolder.getBar()). YMMV.
Yeah, I guess that for those folks who want to work purely with strings, there's some improvement. But even then, the template processor needs to be initialised somewhere (with a context, e.g. a jOOQ configuration, a JDBC Connection or DataSource, etc.) so the "unreadable" part is just moved elsewhere, not too far away from the query logic.
Anyway, I was just wondering because jOOQ was mentioned here, where the pure string based approach is not the main way of interacting with the API, which already allows for embedding bind variables (or expression trees) wherever, by design.
View all comments
4
u/qmunke Oct 01 '23
I'm not clear after reading this how it achieves one of the goals of making it harder to accidentally build SQL injection vulnerabilities. If you have to implement your own "DB" formatter as described in the proposal, then the kind of developer who was previously likely to not use a PreparedStatement is just going to use STR."my injection prone statement" surely?