IDEMPIERE-5565 Cannot create report with virtual column where reference is table with display column = ID (#1735)

* IDEMPIERE-5565 Cannot create report with virtual column where reference is table with display column = ID

* - make it consistent with the actual approach
This commit is contained in:
Carlos Ruiz 2023-03-17 07:27:00 +01:00 committed by GitHub
parent 47987c0314
commit eab0574dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 56 deletions

View File

@ -29,13 +29,11 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.compiere.db.AdempiereDatabase;
import org.compiere.db.Database;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -167,9 +165,6 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
/** Cache */
private static ImmutableIntPOCache<Integer,MColumn> s_cache = new ImmutableIntPOCache<Integer,MColumn>(Table_Name, 20);
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MColumn.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
@ -689,7 +684,6 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
return sb.toString ();
} // toString
//begin vpj-cd e-evolution
/**
* get Column ID
* @param TableName
@ -697,37 +691,14 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
* @return int retValue
*/
public static int getColumn_ID(String TableName,String columnName) {
int m_table_id = MTable.getTable_ID(TableName);
if (m_table_id == 0)
MTable table = MTable.get(Env.getCtx(), TableName);
if (table == null)
return 0;
int retValue = 0;
String SQL = "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID = ? AND columnname = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, m_table_id);
pstmt.setString(2, columnName);
rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getInt(1);
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, SQL, e);
retValue = -1;
}
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return retValue;
MColumn column = table.getColumn(columnName);
if (column == null)
return 0;
return column.getAD_Column_ID();
}
//end vpj-cd e-evolution
/**
* Get Table Id for a column

View File

@ -614,7 +614,7 @@ public class MLookupFactory
* @param AD_Reference_Value_ID reference value
* @return SELECT Name FROM Table
*/
static public String getLookup_TableEmbed (Language language,
public static String getLookup_TableEmbed (Language language,
String BaseColumn, String BaseTable, int AD_Reference_Value_ID)
{
String sql = "SELECT t.TableName,ck.ColumnName AS KeyColumn,"
@ -664,9 +664,14 @@ public class MLookupFactory
pstmt = null;
}
int Column_ID = MColumn.getColumn_ID(BaseTable, BaseColumn);
MColumn column = MColumn.get(Env.getCtx(), Column_ID);
boolean showID = DisplayColumn.equals(TableName+"_ID");
if (showID) {
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, BaseColumn);
if (column.isVirtualColumn())
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, column.getColumnSQL());
else
return getLookup_TableDirEmbed(language, DisplayColumn, BaseTable, BaseColumn);
}
// If it's self referencing then use other alias - teo_sarca [ 1739544 ]
@ -725,8 +730,6 @@ public class MLookupFactory
embedSQL.append(" WHERE ");
int Column_ID = MColumn.getColumn_ID(BaseTable, BaseColumn);
MColumn column = MColumn.get(Env.getCtx(), Column_ID);
// If is not virtual column - teo_sarca [ 1739530 ]
if (!column.isVirtualColumn())
{
@ -735,7 +738,7 @@ public class MLookupFactory
} else if (translated) {
embedSQL.append(TableNameAlias).append(".").append(KeyColumn).append("=").append(column.getColumnSQL(true));
} else {
embedSQL.append(KeyColumn).append("=").append(column.getColumnSQL(true));
embedSQL.append(TableNameAlias).append(".").append(KeyColumn).append("=").append(column.getColumnSQL(true));
}
return embedSQL.toString();
@ -1007,8 +1010,7 @@ public class MLookupFactory
// If is not virtual column - teo_sarca [ 1739530 ]
if (! BaseColumn.trim().startsWith("(")) {
embedSQL.append(BaseTable).append(".").append(BaseColumn);
}
else {
} else {
embedSQL.append(BaseColumn);
}
embedSQL.append("=").append(TableName).append(".").append(ColumnName);

View File

@ -484,16 +484,10 @@ public class DataEngine
|| (AD_Reference_ID == DisplayType.Search && AD_Reference_Value_ID != 0)
)
{
String eSql;
String eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnName, tableName, AD_Reference_Value_ID);
if (ColumnSQL.length() > 0)
{
lookupSQL = ColumnSQL;
eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnSQL, tableName, AD_Reference_Value_ID);
}
else
{
eSql = MLookupFactory.getLookup_TableEmbed(m_language, ColumnName, tableName, AD_Reference_Value_ID);
}
// DisplayColumn
String display = ColumnName;

View File

@ -1020,7 +1020,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
boolean haveNotProcess = !haveProcess; // A field is editabile only if is not readonly and theres a process;
int index = infoColumn.getSelectClause().indexOf(".");
if (index == infoColumn.getSelectClause().lastIndexOf("."))
if (index >= 0 && index == infoColumn.getSelectClause().lastIndexOf("."))
{
String synonym = infoColumn.getSelectClause().substring(0, index);
for(TableInfo tableInfo : tableInfos)

View File

@ -690,12 +690,17 @@ public class InfoGeneralPanel extends InfoPanel implements EventListener<Event>
MTable table = MTable.get(Env.getCtx(), p_tableName);
MColumn column = table.getColumn(columnName);
String baseColumn = column.isVirtualColumn() ? columnSql : columnName;
String embedded = AD_Reference_Value_ID > 0 ? MLookupFactory.getLookup_TableEmbed(Env.getLanguage(Env.getCtx()), baseColumn, p_tableName, AD_Reference_Value_ID)
: MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, baseColumn);
String embedded;
if (AD_Reference_Value_ID > 0) {
embedded = MLookupFactory.getLookup_TableEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, AD_Reference_Value_ID);
} else {
if (column.isVirtualColumn())
embedded = MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, column.getColumnSQL());
else
embedded = MLookupFactory.getLookup_TableDirEmbed(Env.getLanguage(Env.getCtx()), columnName, p_tableName, columnName);
}
embedded = "(" + embedded + ")";
if (embedded.contains("@"))
embedded = "NULL";