[#2835] UpdatableRecord.store() and DSLContext.executeInsert() show different behaviour with respect to NULL value insertion

This commit is contained in:
Lukas Eder 2013-12-07 12:10:28 +01:00
parent 46feeb8da7
commit 8875940e9d
6 changed files with 36 additions and 17 deletions

View File

@ -790,6 +790,26 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
catch (DataChangedException expected) {}
}
@Test
public void testStoreVsExecuteInsert() throws Exception {
if (TIdentityPK() == null) {
log.info("SKIPPING", "store() vs. executeInsert() tests");
return;
}
jOOQAbstractTest.reset = false;
// [#2835] The two means of data insertion should show exactly the same behaviour
// with respect to NULL values for identity columns.
IPK i1 = create().newRecord(TIdentityPK());
i1.setValue(TIdentityPK_VAL(), 1);
assertEquals(1, create().executeInsert(i1));
IPK i2 = create().newRecord(TIdentityPK());
i2.setValue(TIdentityPK_VAL(), 1);
assertEquals(1, i2.store());
}
@Test
public void testUpdatablesWithUpdatablePK() throws Exception {
DSLContext create = create();

View File

@ -61,7 +61,7 @@ CREATE TABLE t_2327_uk_only (
/
CREATE TABLE t_identity_pk (
id INTEGER AUTO_INCREMENT,
id INTEGER NOT NULL AUTO_INCREMENT,
val int,
CONSTRAINT pk_t_identity_pk PRIMARY KEY (id)

View File

@ -1796,6 +1796,11 @@ public abstract class jOOQAbstractTest<
new CRUDTests(this).testStoreWithOptimisticLock();
}
@Test
public void testStoreVsExecuteInsert() throws Exception {
new CRUDTests(this).testStoreVsExecuteInsert();
}
@Test
public void testFetchFromTXT() throws Exception {
new FormatTests(this).testFetchFromTXT();

View File

@ -100,6 +100,16 @@ abstract class AbstractStoreQuery<R extends Record> extends AbstractQuery implem
return into;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public final void setRecord(R record) {
for (int i = 0; i < record.size(); i++) {
if (record.changed(i)) {
addValue((Field) record.field(i), record.getValue(i));
}
}
}
final <T> void addValue(R record, Field<T> field) {
addValue(field, record.getValue(field));
}

View File

@ -94,13 +94,6 @@ class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
insertMaps = new FieldMapsForInsert();
}
@Override
public final void setRecord(R record) {
for (Field<?> field : record.fields()) {
addValue(record, field);
}
}
@Override
public final void newRecord() {
insertMaps.newRecord();

View File

@ -141,15 +141,6 @@ class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
return updateMap;
}
@Override
public final void setRecord(R record) {
for (Field<?> field : record.fields()) {
if (((AbstractRecord) record).getValue0(field).isChanged()) {
addValue(record, field);
}
}
}
// [jooq-tools] START [addValues]
@Generated("This method was generated using jOOQ-tools")