|
24 | 24 | import static com.google.common.collect.Streams.stream; |
25 | 25 | import static com.google.mu.safesql.InternalCollectors.skippingEmpty; |
26 | 26 | import static com.google.mu.safesql.SafeQuery.checkIdentifier; |
| 27 | +import static com.google.mu.util.Substring.all; |
27 | 28 | import static com.google.mu.util.Substring.first; |
28 | 29 | import static com.google.mu.util.Substring.firstOccurrence; |
29 | 30 | import static com.google.mu.util.Substring.prefix; |
@@ -1068,12 +1069,16 @@ public static Template<Integer> prepareToUpdate( |
1068 | 1069 | } |
1069 | 1070 |
|
1070 | 1071 | /** |
1071 | | - * Returns the parameter values in the order they occur in the SQL. They are used by methods |
1072 | | - * like {@link #query query()}, {@link #update update()} or {@link #prepareStatement} to |
1073 | | - * populate the {@link PreparedStatement}. |
| 1072 | + * Returns a query string with the parameter values embedded for easier debugging (logging, |
| 1073 | + * testing, golden file etc.). DO NOT use it as the production SQL query because embedding the |
| 1074 | + * parameter values isn't safe from SQL injection. |
| 1075 | + * |
| 1076 | + * @since 8.8 |
1074 | 1077 | */ |
1075 | | - List<?> getParameters() { |
1076 | | - return paramValues; |
| 1078 | + public String debugString() { |
| 1079 | + StringFormat placeholderWithValue = new StringFormat("? /* {...} */"); |
| 1080 | + Iterator<?> args = paramValues.iterator(); |
| 1081 | + return all("?").replaceAllFrom(sql, q -> placeholderWithValue.format(args.next())); |
1077 | 1082 | } |
1078 | 1083 |
|
1079 | 1084 | /** |
@@ -1448,7 +1453,7 @@ private static final class Builder { |
1448 | 1453 |
|
1449 | 1454 | @CanIgnoreReturnValue Builder addSubQuery(SafeSql subQuery) { |
1450 | 1455 | safeAppend(subQuery.sql); |
1451 | | - paramValues.addAll(subQuery.getParameters()); |
| 1456 | + paramValues.addAll(subQuery.paramValues); |
1452 | 1457 | return this; |
1453 | 1458 | } |
1454 | 1459 |
|
|
0 commit comments