IDEMPIERE-5717 MColumn.getForeignKeyConstraint doesn't always generate unique foreign key constraint name (#1830)

This commit is contained in:
hengsin 2023-05-11 18:43:00 +08:00 committed by GitHub
parent 6716cace06
commit cc90586aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -1184,6 +1184,18 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
if (constraintName.length() > 30)
constraintName = new StringBuilder(constraintName.substring(0, 30));
fkConstraintName = constraintName.toString();
int duplicateId = DB.getSQLValueEx(column.get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE Upper(FkConstraintName)=?", fkConstraintName.toUpperCase());
int loop = 0;
while (duplicateId > 0)
{
loop++;
String suffix = "" + loop;
if (fkConstraintName.length() + suffix.length() > 30)
fkConstraintName = fkConstraintName.substring(0, fkConstraintName.length() - (fkConstraintName.length() + suffix.length() - 30));
fkConstraintName = fkConstraintName + loop;
duplicateId = DB.getSQLValueEx(column.get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE Upper(FkConstraintName)=?", fkConstraintName.toUpperCase());
}
}
StringBuilder fkConstraint = new StringBuilder();