diff --git a/mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java b/mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java index 09415ea461..06bb7cc7ea 100644 --- a/mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java +++ b/mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java @@ -145,6 +145,24 @@ * *
Conditional Subqueries
* + * SafeSql's template syntax is designed to avoid control flows that could obfuscate SQL. Instead, + * complex control flow such as {@code if-else}, nested {@code if}, loops etc. should be performed + * in Java and passed in as subqueries. + * + *

That said, for trivial conditional subqueries such as selecting a column only if a flag is + * enabled, you can use the special conditional subquery operator {@code ->} in the template: + * + *

{@code
+ *   SafeSql sql = SafeSql.of(
+ *       "SELECT {shows_email -> email,} name FROM Users", showsEmail());
+ * }
+ * + * The text after the {@code ->} operator is the conditional subquery that's only included if + * {@code showEmail()} returns true. The subquery can include arbitrary characters except curly + * braces, so for example you can have multi-line conditional subqueries too. + * + *
Complex Dynamic Subqueries
+ * * By composing SafeSql objects that encapsulate subqueries, you can also parameterize by * arbitrary sub-queries that are computed dynamically. * @@ -186,23 +204,6 @@ * convenience methods, {@code statement.setObject(1, "%" + criteria.firstName().get() + "%")} * will be called to populate the PreparedStatement. * - *
Trivial Conditional Subqueries
- * - * SafeSql's template syntax is designed to avoid control flows that could obfuscate SQL. Instead, - * complex control flow such as {@code if-else}, nested {@code if}, loops etc. should be performed - * in Java and passed in as subqueries. - * - *

That said, for trivial conditional subqueries such as selecting a column only if a flag is - * enabled, you can use the special conditional subquery operator {@code ->} in the template: - * - *

{@code
- *   SafeSql sql = SafeSql.of(
- *       "SELECT {shows_email -> email,} name FROM Users", showsEmail());
- * }
- * - * The text after the {@code ->} operator is the conditional subquery that's only included if - * {@code showEmail()} returns true. - * *
Parameterize by Column Names or Table Names
* * Sometimes you may wish to parameterize by table names, column names etc.