summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2012-07-12 23:23:03 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2012-07-23 16:06:41 +0200
commitc5b6a945e898ded83613afefbedef71372665b13 (patch)
tree1b693f32673735c36f3b9404047bbbde17de2b24
parentbb406ff1ce016c96cc735e0c20ae51f7dac235b5 (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 Sgined-off-by: Miklos Vajna <vmiklos@suse.cz>
-rw-r--r--wizards/com/sun/star/wizards/db/SQLQueryComposer.java33
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 8469a2bc7179..3a2d0b6be8c2 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)