diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2012-07-12 23:23:03 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2012-07-12 23:39:07 +0200 |
commit | ede56437f9641cad698b97b2dd14b0c1c37dfcce (patch) | |
tree | cee935c5a2df2def9c8863cc52377dcb9dd69f12 /wizards/com | |
parent | 607e4857bf5c3a1a11092cf6c1aabb96d54852ef (diff) |
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
Diffstat (limited to 'wizards/com')
-rw-r--r-- | wizards/com/sun/star/wizards/db/SQLQueryComposer.java | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java index 973fe7f43c59..c191dc45b806 100644 --- a/wizards/com/sun/star/wizards/db/SQLQueryComposer.java +++ b/wizards/com/sun/star/wizards/db/SQLQueryComposer.java @@ -59,7 +59,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); @@ -227,6 +227,7 @@ public class SQLQueryComposer public void setDBMetaData(QueryMetaData _oDBMetaData) { this.CurDBMetaData = _oDBMetaData; + updateComposedCommandNames(); } private PropertyValue[][] replaceConditionsByAlias(PropertyValue _filterconditions[][]) @@ -250,22 +251,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; } @@ -327,13 +336,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) |