diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2013-09-13 06:38:04 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2013-09-13 12:08:02 +0200 |
commit | 6a1ad344a8100b7fe807383356128aa8ee82b6d5 (patch) | |
tree | ab101e489ad3f6e8726718b1949c208d0817a788 | |
parent | 2defeda9f061e7b1b8e94191e48b17e112761bb5 (diff) |
fdo#69147 report sort columns are RESULT columns
as opposed to table columns or other expressions.
So it makes no sense to slap a table name on them.
Notwithstanding HSQLDB 1.8 (our embedded database) bugs.
Change-Id: Ib5d0b1479e29b9efeafca9ebc2eb7ed8e0f42b79
-rw-r--r-- | reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java | 98 |
1 files changed, 41 insertions, 57 deletions
diff --git a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java index 20709e8eca69..86ba838e4fd3 100644 --- a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java +++ b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java @@ -234,67 +234,51 @@ public class SDBCReportDataFactory implements DataSourceFactory { final StringBuffer order = new StringBuffer(); final int count = sortExpressions.size(); - if (count != 0) + String quote; + try + { + quote = connection.getMetaData().getIdentifierQuoteString(); + } + catch (SQLException ex) + { + LOGGER.error("ReportProcessing failed / getOrderStatement could not get quote character", ex); + // fall back to the SQL standard + quote=""; + } + for (int i = 0; i < count; i++) { - try + final Object[] pair = (Object[]) sortExpressions.get(i); + String expression = (String) pair[0]; + + // LEM FIXME: ${EXPLETIVE}! Either the values we get are *always* already quoted + // (and then this whole work is not useful) + // or they are *never* quoted + // (and then just quote them unconditionally) + // The current mess gives an ambiguity when the column name starts with a quote character. + // It *seems* they are never quoted, but this needs further testing. + if (!expression.startsWith(quote)) { - final String quote = connection.getMetaData().getIdentifierQuoteString(); - final XComponent[] hold = new XComponent[1]; - final XNameAccess columns = getFieldsByCommandDescriptor(commandType, command, hold); - if (columns != null) - { - for (int i = 0; i < count; i++) - { - final Object[] pair = (Object[]) sortExpressions.get(i); - String expression = (String) pair[0]; - - if (!expression.startsWith(quote) && columns.hasByName(expression)) - { - XPropertySet column; - try - { - column = UnoRuntime.queryInterface(XPropertySet.class, columns.getByName(expression)); - String prefix; - prefix = (String)column.getPropertyValue("TableName"); - if (prefix == null) - prefix = ""; - if (prefix.length() != 0) - { - prefix = quote + prefix + quote + "."; - } - expression = prefix + quote + expression + quote; - } - catch (Exception ex) - { - Logger.getLogger(SDBCReportDataFactory.class.getName()).log(Level.SEVERE, null, ex); - expression = quote + expression + quote; - } - } - expression = expression.trim(); // Trim away white spaces - - if (expression.length() > 0) - { - order.append(expression); - if (order.length() > 0) - { - order.append(' '); - } - final String sorting = (String) pair[1]; - if (sorting == null || sorting.equals(OfficeToken.FALSE)) - { - order.append("DESC"); - } - if ((i + 1) < count) - { - order.append(", "); - } - } - } - } + expression = quote + expression + quote; + // LEM TODO: we should escape quotes in expression? } - catch (SQLException ex) + expression = expression.trim(); // Trim away white spaces + + if (expression.length() > 0) { - LOGGER.error("ReportProcessing failed", ex); + order.append(expression); + if (order.length() > 0) + { + order.append(' '); + } + final String sorting = (String) pair[1]; + if (sorting == null || sorting.equals(OfficeToken.FALSE)) + { + order.append("DESC"); + } + if ((i + 1) < count) + { + order.append(", "); + } } } return order.toString(); |