[#7494] Regression on DB2's INSERT .. RETURNING emulation
This commit is contained in:
parent
b8d633bceb
commit
98880773d3
@ -44,26 +44,12 @@ package org.jooq;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface SelectField<T> extends SelectFieldOrAsterisk {
|
||||
public interface SelectField<T> extends SelectFieldOrAsterisk, Named {
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The name of the field.
|
||||
* <p>
|
||||
* The name is any of these:
|
||||
* <ul>
|
||||
* <li>The formal name of the field, if it is a <i>physical table/view
|
||||
* field</i></li>
|
||||
* <li>The alias of an <i>aliased field</i></li>
|
||||
* <li>A generated / unspecified value for any other <i>expression</i></li>
|
||||
* <li>The name of a parameter if it is a named {@link Param}</li>
|
||||
* </ul>
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The field's underlying {@link Converter}.
|
||||
* <p>
|
||||
|
||||
@ -64,6 +64,7 @@ import static org.jooq.impl.Keywords.K_SELECT;
|
||||
import static org.jooq.impl.Keywords.K_SQL;
|
||||
import static org.jooq.impl.Keywords.K_TABLE;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.EMPTY_SELECT_FIELD_OR_ASTERISK;
|
||||
import static org.jooq.impl.Tools.EMPTY_STRING;
|
||||
import static org.jooq.impl.Tools.DataKey.DATA_EMULATE_BULK_INSERT_RETURNING;
|
||||
import static org.jooq.util.sqlite.SQLiteDSL.rowid;
|
||||
@ -166,6 +167,8 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractQuery {
|
||||
returningResolvedAsterisks.addAll(Arrays.asList(((QualifiedAsterisk) f).qualifier().fields()));
|
||||
else if (f instanceof Asterisk)
|
||||
returningResolvedAsterisks.addAll(Arrays.asList(table.fields()));
|
||||
else
|
||||
throw new AssertionError("Type not supported: " + f);
|
||||
}
|
||||
|
||||
// @Override
|
||||
@ -387,6 +390,8 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractQuery {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -395,9 +395,9 @@ implements
|
||||
}
|
||||
|
||||
context.sql(' ')
|
||||
.visit(Tools.qualify(field, lhs))
|
||||
.visit(Tools.qualify(lhs, field))
|
||||
.sql(" = ")
|
||||
.visit(Tools.qualify(field, rhs));
|
||||
.visit(Tools.qualify(rhs, field));
|
||||
}
|
||||
|
||||
context.end(TABLE_JOIN_ON);
|
||||
|
||||
@ -1884,6 +1884,8 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
result.addAll(Arrays.asList(((QualifiedAsterisk) f).qualifier().fields()));
|
||||
else if (f instanceof Asterisk)
|
||||
result.addAll(resolveAsterisk(new QueryPartList<Field<?>>()));
|
||||
else
|
||||
throw new AssertionError("Type not supported: " + f);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -187,6 +187,7 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
// ...
|
||||
import org.jooq.Asterisk;
|
||||
import org.jooq.Attachable;
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Catalog;
|
||||
@ -205,6 +206,7 @@ import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.OrderField;
|
||||
import org.jooq.Param;
|
||||
import org.jooq.QualifiedAsterisk;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.Record;
|
||||
@ -220,6 +222,8 @@ import org.jooq.RowN;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.SelectField;
|
||||
import org.jooq.SelectFieldOrAsterisk;
|
||||
import org.jooq.SortField;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableRecord;
|
||||
@ -259,26 +263,27 @@ final class Tools {
|
||||
// Empty arrays for use with Collection.toArray()
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
static final byte[] EMPTY_BYTE = {};
|
||||
static final Class<?>[] EMPTY_CLASS = {};
|
||||
static final Clause[] EMPTY_CLAUSE = {};
|
||||
static final Collection<?>[] EMPTY_COLLECTION = {};
|
||||
static final CommonTableExpression<?>[] EMPTY_COMMON_TABLE_EXPRESSION = {};
|
||||
static final ExecuteListener[] EMPTY_EXECUTE_LISTENER = {};
|
||||
static final Field<?>[] EMPTY_FIELD = {};
|
||||
static final int[] EMPTY_INT = {};
|
||||
static final Name[] EMPTY_NAME = {};
|
||||
static final Param<?>[] EMPTY_PARAM = {};
|
||||
static final OrderField<?>[] EMPTY_ORDERFIELD = {};
|
||||
static final Query[] EMPTY_QUERY = {};
|
||||
static final QueryPart[] EMPTY_QUERYPART = {};
|
||||
static final Record[] EMPTY_RECORD = {};
|
||||
static final RowN[] EMPTY_ROWN = {};
|
||||
static final SortField<?>[] EMPTY_SORTFIELD = {};
|
||||
static final String[] EMPTY_STRING = {};
|
||||
static final Table<?>[] EMPTY_TABLE = {};
|
||||
static final TableRecord<?>[] EMPTY_TABLE_RECORD = {};
|
||||
static final UpdatableRecord<?>[] EMPTY_UPDATABLE_RECORD = {};
|
||||
static final byte[] EMPTY_BYTE = {};
|
||||
static final Class<?>[] EMPTY_CLASS = {};
|
||||
static final Clause[] EMPTY_CLAUSE = {};
|
||||
static final Collection<?>[] EMPTY_COLLECTION = {};
|
||||
static final CommonTableExpression<?>[] EMPTY_COMMON_TABLE_EXPRESSION = {};
|
||||
static final ExecuteListener[] EMPTY_EXECUTE_LISTENER = {};
|
||||
static final Field<?>[] EMPTY_FIELD = {};
|
||||
static final int[] EMPTY_INT = {};
|
||||
static final Name[] EMPTY_NAME = {};
|
||||
static final Param<?>[] EMPTY_PARAM = {};
|
||||
static final OrderField<?>[] EMPTY_ORDERFIELD = {};
|
||||
static final Query[] EMPTY_QUERY = {};
|
||||
static final QueryPart[] EMPTY_QUERYPART = {};
|
||||
static final Record[] EMPTY_RECORD = {};
|
||||
static final RowN[] EMPTY_ROWN = {};
|
||||
static final SelectFieldOrAsterisk[] EMPTY_SELECT_FIELD_OR_ASTERISK = {};
|
||||
static final SortField<?>[] EMPTY_SORTFIELD = {};
|
||||
static final String[] EMPTY_STRING = {};
|
||||
static final Table<?>[] EMPTY_TABLE = {};
|
||||
static final TableRecord<?>[] EMPTY_TABLE_RECORD = {};
|
||||
static final UpdatableRecord<?>[] EMPTY_UPDATABLE_RECORD = {};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Some constants for use with Context.data()
|
||||
@ -4399,7 +4404,33 @@ final class Tools {
|
||||
return false;
|
||||
}
|
||||
|
||||
static final <T> Field<T> qualify(Field<T> field, Table<?> table) {
|
||||
static final SelectFieldOrAsterisk[] qualify(Table<?> table, SelectFieldOrAsterisk... fields) {
|
||||
if (fields == null)
|
||||
return null;
|
||||
|
||||
SelectFieldOrAsterisk[] result = new SelectFieldOrAsterisk[fields.length];
|
||||
Name[] part = table.getQualifiedName().parts();
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
if (fields[i] instanceof SelectField) {
|
||||
SelectField<?> field = (SelectField<?>) fields[i];
|
||||
Name[] name = new Name[part.length + 1];
|
||||
System.arraycopy(part, 0, name, 0, part.length);
|
||||
name[part.length] = field.getUnqualifiedName();
|
||||
result[i] = DSL.field(DSL.name(name), field.getDataType());
|
||||
}
|
||||
else if (fields[i] instanceof QualifiedAsterisk)
|
||||
result[i] = table.asterisk();
|
||||
else if (fields[i] instanceof Asterisk)
|
||||
result[i] = fields[i];
|
||||
else
|
||||
throw new AssertionError("Type not supported: " + fields[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static final <T> Field<T> qualify(Table<?> table, Field<T> field) {
|
||||
Field<T> result = table.field(field);
|
||||
|
||||
if (result != null)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user