[#7479] Log warning when { Insert | Update | Delete }ReturningStep.returning() is used with arbitrary column expressions

This commit is contained in:
lukaseder 2018-05-11 17:23:33 +02:00
parent 2549c14e6e
commit 12ca10cd0a

View File

@ -179,17 +179,29 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractQuery {
// @Override
@SuppressWarnings("unchecked")
public final Result<R> getReturnedRecords() {
if (returned == null)
if (returned == null) {
// [#3682] Plain SQL tables do not have any fields
if (table.fields().length > 0)
if (table.fields().length > 0) {
// [#7479] [#7475] Warn users about potential API misuse
warnOnAPIMisuse();
returned = getResult().into(table);
else
}
else {
returned = (Result<R>) getResult();
}
}
return returned;
}
private final void warnOnAPIMisuse() {
for (Field<?> field : getResult().fields())
if (table.field(field) == null)
log.warn("API misuse", "Column " + field + " has been requested through the returning() clause, which is not present in table " + table + ". Use StoreQuery.getResult() or the returningResult() clause instead.");
}
// @Override
public final Result<?> getResult() {
if (returnedResult == null)