diff --git a/base/src/org/compiere/model/MTable.java b/base/src/org/compiere/model/MTable.java index dd3af9b748..94c35ce45e 100644 --- a/base/src/org/compiere/model/MTable.java +++ b/base/src/org/compiere/model/MTable.java @@ -529,19 +529,44 @@ public class MTable extends X_AD_Table * @return PO for Record or null */ public PO getPO (String whereClause, String trxName) + { + return getPO(whereClause, null, trxName); + } // getPO + + /** + * Get PO class instance + * @param whereClause + * @param params + * @param trxName + * @return + */ + public PO getPO(String whereClause, Object[] params, String trxName) { if (whereClause == null || whereClause.length() == 0) return null; // PO po = null; - String sql = "SELECT * FROM " + getTableName() + " WHERE " + whereClause; + POInfo info = POInfo.getPOInfo(getCtx(), getAD_Table_ID()); + if (info == null) return null; + StringBuffer sqlBuffer = info.buildSelect(); + sqlBuffer.append(" WHERE ").append(whereClause); + String sql = sqlBuffer.toString(); PreparedStatement pstmt = null; try { pstmt = DB.prepareStatement (sql, trxName); + if (params != null && params.length > 0) + { + for (int i = 0; i < params.length; i++) + { + pstmt.setObject(i+1, params[i]); + } + } ResultSet rs = pstmt.executeQuery (); if (rs.next ()) + { po = getPO(rs, trxName); + } rs.close (); pstmt.close (); pstmt = null; @@ -561,11 +586,9 @@ public class MTable extends X_AD_Table { pstmt = null; } - if (po == null) - return getPO(0, trxName); + return po; - } // getPO - + } /** * Before Save diff --git a/base/src/org/compiere/model/POInfo.java b/base/src/org/compiere/model/POInfo.java index d9ac5b2c9c..2608b761f5 100644 --- a/base/src/org/compiere/model/POInfo.java +++ b/base/src/org/compiere/model/POInfo.java @@ -624,5 +624,23 @@ public class POInfo implements Serializable } return null; } // validate + + /** + * Build select clause + * @return stringbuffer + */ + public StringBuffer buildSelect() + { + StringBuffer sql = new StringBuffer("SELECT "); + int size = getColumnCount(); + for (int i = 0; i < size; i++) + { + if (i != 0) + sql.append(","); + sql.append(getColumnSQL(i)); // Normal and Virtual Column + } + sql.append(" FROM ").append(getTableName()); + return sql; + } } // POInfo