From 452c495ab54eeec9e840c5f3546f664a349ffc40 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 17 May 2008 00:52:22 +0000 Subject: [PATCH] Fix [ 1965744 ] Dependent entities access problem --- base/src/org/compiere/model/MRole.java | 39 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/base/src/org/compiere/model/MRole.java b/base/src/org/compiere/model/MRole.java index 084503b715..0754fa4715 100644 --- a/base/src/org/compiere/model/MRole.java +++ b/base/src/org/compiere/model/MRole.java @@ -1,5 +1,4 @@ /****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * @@ -1877,17 +1876,29 @@ public final class MRole extends X_AD_Role String columnName = m_recordDependentAccess[i].getKeyColumnName (asp.getTableInfo(asp.getMainSqlIndex()) ); if (columnName == null) - continue; // no key column - int posColumn = mainSql.indexOf(columnName); - if (posColumn == -1) - continue; - // we found the column name - make sure it's a clumn name - char charCheck = mainSql.charAt(posColumn-1); // before - if (!(charCheck == ',' || charCheck == '.' || charCheck == ' ' || charCheck == '(')) - continue; - charCheck = mainSql.charAt(posColumn+columnName.length()); // after - if (!(charCheck == ',' || charCheck == ' ' || charCheck == ')')) - continue; + continue; // no key column + + if (mainSql.toUpperCase().startsWith("SELECT COUNT(*) FROM ")) { + // globalqss - Carlos Ruiz - [ 1965744 ] Dependent entities access problem + // this is the count select, it doesn't have the column but needs to be filtered + MTable table = MTable.get(getCtx(), tableName); + if (table == null) + continue; + MColumn column = table.getColumn(columnName); + if (column == null || column.isVirtualColumn() || !column.isActive()) + continue; + } else { + int posColumn = mainSql.indexOf(columnName); + if (posColumn == -1) + continue; + // we found the column name - make sure it's a column name + char charCheck = mainSql.charAt(posColumn-1); // before + if (!(charCheck == ',' || charCheck == '.' || charCheck == ' ' || charCheck == '(')) + continue; + charCheck = mainSql.charAt(posColumn+columnName.length()); // after + if (!(charCheck == ',' || charCheck == ' ' || charCheck == ')')) + continue; + } if (AD_Table_ID != 0 && AD_Table_ID != m_recordDependentAccess[i].getAD_Table_ID()) retSQL.append(getDependentAccess(whereColumnName, includes, excludes)); @@ -1969,7 +1980,9 @@ public final class MRole extends X_AD_Role private String getDependentRecordWhereColumn (String mainSql, String columnName) { String retValue = columnName; // if nothing else found - int index = mainSql.indexOf(columnName); + int index = mainSql.indexOf(columnName); + if (index == -1) + return retValue; // see if there are table synonym int offset = index - 1; char c = mainSql.charAt(offset);