summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2012-07-12 23:23:03 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-07-16 15:59:11 +0200
commit6a7c0710cc063912d912cc95b10415bc717a241f (patch)
tree039cb37fb6ffdbe04db130d9e10d759837f36191 /wizards
parent287e9723486ab306444a9f4f396f1df01a307993 (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 Signed-off-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'wizards')
-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)