IDEMPIERE-5511 When you want to create a new label display an Oracle Error: ORA-01747: invalid user.table.column, table.column, or column specification (#1602)

* IDEMPIERE-5511 When you want to create a new label display an Oracle Error: ORA-01747: invalid user.table.column, table.column, or column specification

* - correct select
This commit is contained in:
Carlos Ruiz 2022-12-06 08:26:57 +01:00 committed by GitHub
parent 5466250d93
commit 8011c72926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 23 deletions

View File

@ -145,32 +145,36 @@ public class LabelsSearchController implements EventListener<Event>{
int currentIndex = 0; int currentIndex = 0;
int foundIndex = 0; int foundIndex = 0;
String sql = "SELECT" StringBuilder sql = new StringBuilder();
+ " AD_Label.AD_Label_ID," sql.append("SELECT ");
+ " AD_Label.Name," sql.append(" AD_Label.AD_Label_ID, ");
+ " COUNT(AD_LabelAssignment.*)," sql.append(" AD_Label.Name, ");
+ " CASE " sql.append(" COUNT(AD_LabelAssignment.AD_LabelAssignment_ID), ");
+ " WHEN AD_Label.AD_LabelCategory_ID > 0 AND AD_LabelCategory.IsCanBeUsedInAllTables = 'N'" sql.append(" CASE ");
+ " AND AD_LabelCategoryTable.AD_Table_ID <> ? THEN 'N'" sql.append(" WHEN AD_Label.AD_LabelCategory_ID > 0 AND AD_LabelCategory.IsCanBeUsedInAllTables = 'N' ");
+ " ELSE 'Y'" sql.append(" AND AD_LabelCategoryTable.AD_Table_ID <> ").append(labelsPanel.getAD_Table_ID()).append(" THEN 'N' ");
+ " END AS IsAllowed" sql.append(" ELSE 'Y' ");
+ " FROM AD_Label" sql.append(" END AS IsAllowed ");
+ " LEFT JOIN AD_LabelAssignment ON AD_LabelAssignment.AD_Label_ID = AD_Label.AD_Label_ID" sql.append(" FROM AD_Label ");
+ " LEFT JOIN AD_LabelCategory ON AD_LabelCategory.AD_LabelCategory_ID = AD_LabelCategory.AD_LabelCategory_ID" sql.append(" LEFT JOIN AD_LabelAssignment ON AD_LabelAssignment.AD_Label_ID = AD_Label.AD_Label_ID ");
+ " LEFT JOIN AD_LabelCategoryTable ON AD_LabelCategoryTable.AD_LabelCategory_ID = AD_LabelCategory.AD_LabelCategory_ID" sql.append(" LEFT JOIN AD_LabelCategory ON AD_LabelCategory.AD_LabelCategory_ID = AD_LabelCategory.AD_LabelCategory_ID ");
+ " WHERE AD_Label.AD_Client_ID = ? AND AD_Label.Name ILIKE ?" sql.append(" LEFT JOIN AD_LabelCategoryTable ON AD_LabelCategoryTable.AD_LabelCategory_ID = AD_LabelCategory.AD_LabelCategory_ID ");
+ " GROUP BY AD_Label.AD_Label_ID, AD_Label.Name, IsAllowed" sql.append(" WHERE AD_Label.AD_Client_ID = ? AND LOWER(AD_Label.Name) LIKE LOWER(?) ");
+ " ORDER BY COUNT(AD_LabelAssignment.*) DESC"; sql.append(" GROUP BY AD_Label.AD_Label_ID, AD_Label.Name, ");
//+ " FETCH FIRST 15 ROWS ONLY"; sql.append(" CASE ");
sql.append(" WHEN AD_Label.AD_LabelCategory_ID > 0 AND AD_LabelCategory.IsCanBeUsedInAllTables = 'N' ");
sql.append(" AND AD_LabelCategoryTable.AD_Table_ID <> ").append(labelsPanel.getAD_Table_ID()).append(" THEN 'N' ");
sql.append(" ELSE 'Y' ");
sql.append(" END ");
sql.append(" ORDER BY COUNT(AD_LabelAssignment.AD_LabelAssignment_ID) DESC");
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, labelsPanel.getAD_Table_ID()); pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
pstmt.setInt(2, Env.getAD_Client_ID(Env.getCtx())); pstmt.setString(2, "%" + value + "%");
pstmt.setString(3, "%" + value + "%");
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();