[#1343] Regression in insertInto(...).values(...). Cannot pass Field<?>

to values()
This commit is contained in:
Lukas Eder 2012-04-22 12:24:47 +02:00
parent 6bc74d2577
commit 1df7156550
2 changed files with 26 additions and 1 deletions

View File

@ -52,6 +52,7 @@ import static org.jooq.SQLDialect.SYBASE;
import static org.jooq.impl.Factory.cast;
import static org.jooq.impl.Factory.castNull;
import static org.jooq.impl.Factory.count;
import static org.jooq.impl.Factory.inline;
import static org.jooq.impl.Factory.max;
import static org.jooq.impl.Factory.val;
import static org.jooq.impl.Factory.vals;
@ -345,6 +346,18 @@ extends BaseTest<A, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658, T725
assertEquals(37, (int) author2.getValue(TAuthor_ID()));
assertEquals("Erich", author2.getValue(TAuthor_FIRST_NAME()));
assertEquals("Kästner", author2.getValue(TAuthor_LAST_NAME()));
// [#1343] Conversion mustn't be done on jOOQ artefacts
assertEquals(1,
create().insertInto(TAuthor())
.values(
create().select(vals(38)),
val("Alfred"),
inline("Hitchcock"),
val(null),
inline((Object) null),
create().select(val(null)).asField())
.execute());
}
@Test

View File

@ -44,6 +44,7 @@ import java.util.Map;
import org.jooq.AttachableInternal;
import org.jooq.Configuration;
import org.jooq.Field;
import org.jooq.FieldLike;
import org.jooq.Insert;
import org.jooq.InsertOnDuplicateSetMoreStep;
import org.jooq.InsertQuery;
@ -133,8 +134,19 @@ class InsertImpl<R extends Record>
return values(values.toArray());
}
@SuppressWarnings("unchecked")
private <T> void addValue(InsertQuery<R> delegate, Field<T> field, Object object) {
delegate.addValue(field, field.getDataType().convert(object));
// [#1343] Only convert non-jOOQ objects
if (object instanceof Field) {
delegate.addValue(field, (Field<T>) object);
}
else if (object instanceof FieldLike) {
delegate.addValue(field, ((FieldLike) object).<T>asField());
}
else {
delegate.addValue(field, field.getDataType().convert(object));
}
}
@SuppressWarnings("unchecked")