[Libreoffice-commits] core.git: 4 commits - connectivity/source include/connectivity reportbuilder/java

Lionel Elie Mamane lionel at mamane.lu
Fri Sep 13 03:09:26 PDT 2013


 connectivity/source/parse/sqliterator.cxx                            |   29 +-
 include/connectivity/sqliterator.hxx                                 |    5 
 reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java |   98 ++++------
 3 files changed, 63 insertions(+), 69 deletions(-)

New commits:
commit be3e037b38be4c6bd821bc5261dcd85f18196214
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Fri Sep 13 07:36:50 2013 +0200

    setting a table name on an expression/function call makes no sense
    
    Change-Id: Id30805f09bc359c6f66d87f050427c0e586ec93d

diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 3bb5efb..ecd9f74 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -1008,17 +1008,11 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele
                     // check if the column is also a parameter
                     traverseSearchCondition(pColumnRef); // num_value_exp
 
-                    // Do all involved columns of the function belong to one table?
-                    if (m_pImpl->m_pTables->size() == 1)
-                    {
-                        aTableRange = m_pImpl->m_pTables->begin()->first;
-                    }
-                    else
-                    {
-                        getColumnTableRange(pColumnRef,aTableRange);
-                    }
                     if ( pColumnRef->isRule() )
                     {
+                        // LEM FIXME: the if condition is not quite right
+                        //            many expressions are rules, e.g. "5+3"
+                        //            or even: "colName + 1"
                         bFkt = sal_True;
                         nType = getFunctionReturnType(pColumnRef);
                     }
@@ -1807,6 +1801,8 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns>& _
                 pColumn->setFunction(sal_True);
                 pColumn->setAggregateFunction(bAggFkt);
                 pColumn->setRealName(rColumnName);
+                SAL_WARN("connectivity.parse", "Trying to construct a column with Function==true and a TableName; this makes no sense.");
+                assert(false);
                 pColumn->setTableName(aFind->first);
 
                 Reference< XPropertySet> xCol = pColumn;
commit 974d73d219e344350522f8c3da8c38cda6ddbd4d
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Fri Sep 13 07:35:15 2013 +0200

    remove an arbitrary level of nested parentheses
    
    not only one.
    
    Change-Id: I1f611dda6a98fb6244409c0cd1fc87fc9dfaa8c3

diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 4cd8c65..3bb5efb 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -985,7 +985,7 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele
                 sal_Int32 nType = DataType::VARCHAR;
                 sal_Bool bFkt(sal_False);
                 pColumnRef = pColumnRef->getChild(0);
-                if (
+                while (
                         pColumnRef->getKnownRuleID() != OSQLParseNode::subquery &&
                         pColumnRef->count() == 3 &&
                         SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
commit 7b4b3ad8c6f84177247f4e88c10b5473b8a9c39a
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Fri Sep 13 07:19:37 2013 +0200

    Don't clobber argument on failure
    
    Change-Id: I709305d4ec3c37d3fc1c2c911551174f8cfbb883

diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index a19f593..4cd8c65 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -803,7 +803,18 @@ void OSQLParseTreeIterator::getColumnRange( const OSQLParseNode* _pColumnRef,
 }
 
 //-----------------------------------------------------------------------------
-sal_Bool OSQLParseTreeIterator::getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const
+bool OSQLParseTreeIterator::getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const
+{
+    OUString tmp;
+    if(impl_getColumnTableRange(pNode, tmp))
+    {
+        rTableRange = tmp;
+        return true;
+    }
+    else
+        return false;
+}
+bool OSQLParseTreeIterator::impl_getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const
 {
     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen at sun.com OSQLParseTreeIterator::getColumnTableRange" );
     // See if all columns belong to one table
diff --git a/include/connectivity/sqliterator.hxx b/include/connectivity/sqliterator.hxx
index b9a1b6c..03b12de 100644
--- a/include/connectivity/sqliterator.hxx
+++ b/include/connectivity/sqliterator.hxx
@@ -272,7 +272,7 @@ namespace connectivity
                                     OUString& _rTableRange);
 
         // empty if ambiguous
-        sal_Bool getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const;
+        bool getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const;
 
         // return true when the tableNode is a rule like catalog_name, schema_name or table_name
         sal_Bool isTableNode(const OSQLParseNode* _pTableNode) const;
@@ -284,6 +284,9 @@ namespace connectivity
         ::std::vector< TNodePair >& getJoinConditions() const;
 
     private:
+        // helper to implement getColumnTableRange
+        bool impl_getColumnTableRange(const OSQLParseNode* pNode, OUString &rTableRange) const;
+
         /** traverses the list of table names, and filles _rTables
         */
         bool traverseTableNames( OSQLTables& _rTables );
commit 6a1ad344a8100b7fe807383356128aa8ee82b6d5
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Fri Sep 13 06:38:04 2013 +0200

    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

diff --git a/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java b/reportbuilder/java/org/libreoffice/report/SDBCReportDataFactory.java
index 20709e8..86ba838 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();


More information about the Libreoffice-commits mailing list