IDEMPIERE-1615 Multiple key columns lead to data corruption or data loss

This commit is contained in:
Carlos Ruiz 2019-02-14 16:56:02 +01:00
parent ec50409760
commit 5f1c8e0860
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,11 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-1615 Multiple key columns lead to data corruption or data loss
-- Feb 14, 2019, 4:51:33 PM CET
INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The table has already a key column, there can be just one key.',0,0,'Y',TO_DATE('2019-02-14 16:51:32','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-02-14 16:51:32','YYYY-MM-DD HH24:MI:SS'),100,200488,'KeyColumnAlreadyDefined','D','c5011666-1371-4620-a5bc-aa29265f5d90')
;
SELECT register_migration_script('201902141651_IDEMPIERE-1615.sql') FROM dual
;

View File

@ -0,0 +1,8 @@
-- IDEMPIERE-1615 Multiple key columns lead to data corruption or data loss
-- Feb 14, 2019, 4:51:33 PM CET
INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The table has already a key column, there can be just one key.',0,0,'Y',TO_TIMESTAMP('2019-02-14 16:51:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-02-14 16:51:32','YYYY-MM-DD HH24:MI:SS'),100,200488,'KeyColumnAlreadyDefined','D','c5011666-1371-4620-a5bc-aa29265f5d90')
;
SELECT register_migration_script('201902141651_IDEMPIERE-1615.sql') FROM dual
;

View File

@ -413,6 +413,17 @@ public class MColumn extends X_AD_Column
}
}
// IDEMPIERE-1615 Multiple key columns lead to data corruption or data loss
if ((is_ValueChanged(COLUMNNAME_IsKey) || is_ValueChanged(COLUMNNAME_IsActive)) && isKey() && isActive()) {
int cnt = DB.getSQLValueEx(get_TrxName(),
"SELECT COUNT(*) FROM AD_Column WHERE AD_Table_ID=? AND IsActive='Y' AND AD_Column_ID!=? AND IsKey='Y'",
getAD_Table_ID(), getAD_Column_ID());
if (cnt > 0) {
log.saveError("Error", Msg.getMsg(getCtx(), "KeyColumnAlreadyDefined"));
return false;
}
}
return true;
} // beforeSave