From ba236e720eb059f0f43740d259952c7d3e3be342 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Sun, 18 Dec 2011 17:27:56 +0000 Subject: [PATCH] [#1003] Sybase / SQL Server / MySQL / Ingres / H2 / Derby INSERT .. RETURNING returns null if a table has an IDENTITY column, but no main unique key --- jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java | 2 -- .../main/java/org/jooq/impl/InsertQueryImpl.java | 14 +++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index 9dd088b26b..cde519f8b0 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -678,8 +678,6 @@ public abstract class jOOQAbstractTest< // Identity tables without primary key if (TIdentity() != null) { - - // TODO [#1003] This doesn't work for Sybase, SQL Server, Ingres, H2, Derby, ASE testInsertIdentity0(TIdentity(), TIdentity_ID(), TIdentity_VAL()); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index e0080df344..679d8592b7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -447,13 +447,13 @@ class InsertQueryImpl extends AbstractStoreQuery implements */ @SuppressWarnings("unchecked") private final void selectReturning(Configuration configuration, Object... values) { - if (getInto() instanceof UpdatableTable) { - UpdatableTable updatable = (UpdatableTable) getInto(); + if (values != null && values.length > 0) { + Table into = getInto(); // This shouldn't be null, as relevant dialects should // return empty generated keys ResultSet - if (updatable.getIdentity() != null) { - Field field = (Field) updatable.getIdentity().getField(); + if (into.getIdentity() != null) { + Field field = (Field) into.getIdentity().getField(); Number[] ids = new Number[values.length]; for (int i = 0; i < values.length; i++) { ids[i] = field.getDataType().convert(values[i]); @@ -463,7 +463,7 @@ class InsertQueryImpl extends AbstractStoreQuery implements // additional query if (returning.size() == 1 && returning.get(0).equals(field)) { for (Number id : ids) { - R typed = Util.newRecord(getInto(), configuration); + R typed = Util.newRecord(into, configuration); ((AbstractRecord) typed).setValue(field, new Value(id)); getReturnedRecords().add(typed); } @@ -473,9 +473,9 @@ class InsertQueryImpl extends AbstractStoreQuery implements else { returned = create(configuration).select(returning) - .from(updatable) + .from(into) .where(field.in(ids)) - .fetchInto(getInto()); + .fetchInto(into); } } }