wizards/com/sun/star/wizards/db/SQLQueryComposer.java | 33 +++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-)
New commits: commit 6a7c0710cc063912d912cc95b10415bc717a241f Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Thu Jul 12 23:23:03 2012 +0200 fdo#50800 populate composedCommandNames ASAP, not at call of getFromClause In particular com/sun/star/wizards/ui/FilterComponent calls getSelectClause before calling getFromClause, and then all hell breaks loose: composedCommandNames is empty, thus cannot find the proper Alias column name, thus the column names in the select list were not properly escaped, ... We have just made getFromClause quadratic instead of linear, but: 1) I do not think this would be a problem (small datastructures) 2) If it is, rather use a hashmap or something like that, wich will also make getSelectClause faster Also make the fallback case of "unknown table" more robust: escape the table name (if any) and column name! Change-Id: I474adc51fc6378d836bd5865d9eb9505983dcbc5 Signed-off-by: Miklos Vajna <vmik...@suse.cz> diff --git a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java index 8469a2b..3a2d0b6 100644 --- a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java +++ b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java @@ -68,7 +68,7 @@ public class SQLQueryComposer { try { - this.CurDBMetaData = _CurDBMetaData; + setDBMetaData(_CurDBMetaData); xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, CurDBMetaData.DBConnection); final Object oQueryComposer = xMSF.createInstance("com.sun.star.sdb.SingleSelectQueryComposer"); m_xQueryAnalyzer = UnoRuntime.queryInterface(XSingleSelectQueryAnalyzer.class, oQueryComposer); @@ -231,6 +231,7 @@ public class SQLQueryComposer public void setDBMetaData(QueryMetaData _oDBMetaData) { this.CurDBMetaData = _oDBMetaData; + updateComposedCommandNames(); } private PropertyValue[][] replaceConditionsByAlias(PropertyValue _filterconditions[][]) @@ -255,22 +256,30 @@ public class SQLQueryComposer return m_xQueryAnalyzer.getQuery(); } - public StringBuilder getFromClause() + private void updateComposedCommandNames() { - StringBuilder sFromClause = new StringBuilder("FROM"); composedCommandNames.clear(); String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); for (int i = 0; i < sCommandNames.length; i++) { - CommandName curCommandName = new CommandName(CurDBMetaData, sCommandNames[i]); //(setComposedCommandName) + CommandName curCommandName = new CommandName(CurDBMetaData, sCommandNames[i]); curCommandName.setAliasName(getuniqueAliasName(curCommandName.getTableName())); + composedCommandNames.add(curCommandName); + } + } + + public StringBuilder getFromClause() + { + StringBuilder sFromClause = new StringBuilder("FROM"); + String[] sCommandNames = CurDBMetaData.getIncludedCommandNames(); + for (int i = 0; i < sCommandNames.length; i++) + { + CommandName curCommandName = getComposedCommandByDisplayName(sCommandNames[i]); sFromClause.append(" ").append(curCommandName.getComposedName()).append(" ").append(quoteName(curCommandName.getAliasName())); if (i < sCommandNames.length - 1) { sFromClause.append(", "); } - // fill composedCommandNames - composedCommandNames.add(curCommandName); } return sFromClause; } @@ -320,13 +329,19 @@ public class SQLQueryComposer private String getComposedAliasFieldName(String _fieldname) { FieldColumn CurFieldColumn = CurDBMetaData.getFieldColumnByDisplayName(_fieldname); - CommandName curComposedCommandName = getComposedCommandByDisplayName(CurFieldColumn.getCommandName()); + final String curCommandName = CurFieldColumn.getCommandName(); + final String curFieldName = CurFieldColumn.getFieldName(); + CommandName curComposedCommandName = getComposedCommandByDisplayName(curCommandName); if (curComposedCommandName == null) { - return _fieldname; + //return _fieldname; + if ( curCommandName.length() > 0 ) + return quoteName(curCommandName) + "." + quoteName(curFieldName); + else + return quoteName(CurFieldColumn.getFieldName()); } String curAliasName = curComposedCommandName.getAliasName(); - return quoteName(curAliasName) + "." + quoteName(CurFieldColumn.getFieldName()); + return quoteName(curAliasName) + "." + quoteName(curFieldName); } private CommandName getComposedCommandByAliasName(String _AliasName) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits