There are lots of scenarios where you want to include/exclude a fragment from the SQL statement depending on what is bound to a particular parameter:
String SELECT = "SELECT * FROM something { id => WHERE id = :id }";
// these queries would be executed with the WHERE clause excluded:
handle.createQuery(SELECT).list();
handle.createQuery(SELECT).bind("id", null).list();
handle.createQuery(SELECT).bind("id", Optional.empty()).list();
// these queries would be executed with the WHERE clause included:
handle.createQuery(SELECT).bind("id", 1).list();
handle.createQuery(SELECT).bind("id", Optional.of(1)).list();
The { id => WHERE id = :id } is certainly up for debate--we'd have to ensure that whatever syntax we picked didn't conflict with valid SQL tokens.
This could be implemented in our default statement rewriters.
There are lots of scenarios where you want to include/exclude a fragment from the SQL statement depending on what is bound to a particular parameter:
The
{ id => WHERE id = :id }is certainly up for debate--we'd have to ensure that whatever syntax we picked didn't conflict with valid SQL tokens.This could be implemented in our default statement rewriters.