Fix [2529670] - Undesirable effect having default -1 in AD_Column

https://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2529670&group_id=176962
Solve also the "DEFAULT NULL NOT NULL" problem with Oracle-11G reported here:
https://sourceforge.net/forum/message.php?msg_id=5578383
This commit is contained in:
Carlos Ruiz 2009-01-23 17:23:48 +00:00
parent 19cc25a39e
commit 7b34dc4a61
1 changed files with 25 additions and 25 deletions

View File

@ -310,35 +310,34 @@ public class MColumn extends X_AD_Column
StringBuffer sql = new StringBuffer (getColumnName()) StringBuffer sql = new StringBuffer (getColumnName())
.append(" ").append(getSQLDataType()); .append(" ").append(getSQLDataType());
// Default // Default
if (getDefaultValue() != null && getDefaultValue().length() > 0) String defaultValue = getDefaultValue();
{ if (defaultValue != null
sql.append(" DEFAULT ");
// if (DisplayType.isText(getAD_Reference_ID()))
// sql.append(DB.TO_STRING(getDefaultValue()));
// else
// sql.append(getDefaultValue());
String defaultValue = getDefaultValue();
if (defaultValue != null
&& defaultValue.length() > 0 && defaultValue.length() > 0
&& defaultValue.indexOf('@') == -1) // no variables && defaultValue.indexOf('@') == -1 // no variables
{ && ( ! (DisplayType.isID(getAD_Reference_ID()) && defaultValue.equals("-1") ) ) ) // not for ID's with default -1
if (DisplayType.isText(getAD_Reference_ID()) {
if (DisplayType.isText(getAD_Reference_ID())
|| getAD_Reference_ID() == DisplayType.List || getAD_Reference_ID() == DisplayType.List
|| getAD_Reference_ID() == DisplayType.YesNo || getAD_Reference_ID() == DisplayType.YesNo
// Two special columns: Defined as Table but DB Type is String // Two special columns: Defined as Table but DB Type is String
|| getColumnName().equals("EntityType") || getColumnName().equals("AD_Language") || getColumnName().equals("EntityType") || getColumnName().equals("AD_Language")
|| (getAD_Reference_ID() == DisplayType.Button && || (getAD_Reference_ID() == DisplayType.Button &&
!(getColumnName().endsWith("_ID")))) !(getColumnName().endsWith("_ID"))))
{ {
if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'")) if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'"))
defaultValue = DB.TO_STRING(defaultValue); defaultValue = DB.TO_STRING(defaultValue);
}
} else {
defaultValue = " NULL ";
} }
sql.append(defaultValue); sql.append(" DEFAULT ").append(defaultValue);
} }
else
{
if (! isMandatory())
sql.append(" DEFAULT NULL ");
defaultValue = null;
}
// Inline Constraint // Inline Constraint
if (getAD_Reference_ID() == DisplayType.YesNo) if (getAD_Reference_ID() == DisplayType.YesNo)
sql.append(" CHECK (").append(getColumnName()).append(" IN ('Y','N'))"); sql.append(" CHECK (").append(getColumnName()).append(" IN ('Y','N'))");
@ -364,12 +363,12 @@ public class MColumn extends X_AD_Column
// Default // Default
StringBuffer sqlDefault = new StringBuffer(sqlBase) StringBuffer sqlDefault = new StringBuffer(sqlBase)
.append(" ").append(getSQLDataType()) .append(" ").append(getSQLDataType());
.append(" DEFAULT ");
String defaultValue = getDefaultValue(); String defaultValue = getDefaultValue();
if (defaultValue != null if (defaultValue != null
&& defaultValue.length() > 0 && defaultValue.length() > 0
&& defaultValue.indexOf('@') == -1) // no variables && defaultValue.indexOf('@') == -1 // no variables
&& ( ! (DisplayType.isID(getAD_Reference_ID()) && defaultValue.equals("-1") ) ) ) // not for ID's with default -1
{ {
if (DisplayType.isText(getAD_Reference_ID()) if (DisplayType.isText(getAD_Reference_ID())
|| getAD_Reference_ID() == DisplayType.List || getAD_Reference_ID() == DisplayType.List
@ -382,11 +381,12 @@ public class MColumn extends X_AD_Column
if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'")) if (!defaultValue.startsWith("'") && !defaultValue.endsWith("'"))
defaultValue = DB.TO_STRING(defaultValue); defaultValue = DB.TO_STRING(defaultValue);
} }
sqlDefault.append(defaultValue); sqlDefault.append(" DEFAULT ").append(defaultValue);
} }
else else
{ {
sqlDefault.append(" NULL "); if (! isMandatory())
sqlDefault.append(" DEFAULT NULL ");
defaultValue = null; defaultValue = null;
} }
sql.append(sqlDefault); sql.append(sqlDefault);