connectivity/source/parse/sqlnode.cxx              |    5 +++--
 dbaccess/source/ui/querydesign/QueryDesignView.cxx |   15 ++++++++++++++-
 include/connectivity/sqlparse.hxx                  |    5 ++++-
 3 files changed, 21 insertions(+), 4 deletions(-)

New commits:
commit 3b09ae20a3ed526cd80fe27be785e8bc9ff2ce5e
Author: Lionel Elie Mamane <lio...@mamane.lu>
Date:   Wed Jan 28 18:24:40 2015 +0100

    Query Design: use correct name for columns that come from another query.
    
    Change-Id: I25b4ccdc2f50ba89687e1f4c871f286251a28e21
    Reviewed-on: https://gerrit.libreoffice.org/14232
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/connectivity/source/parse/sqlnode.cxx 
b/connectivity/source/parse/sqlnode.cxx
index 37bfbde..08e089d 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -1158,7 +1158,8 @@ OUString OSQLParser::stringToDouble(const OUString& 
_rValue,sal_Int16 _nScale)
 
 OSQLParseNode* OSQLParser::predicateTree(OUString& rErrorMessage, const 
OUString& rStatement,
                                           const Reference< 
::com::sun::star::util::XNumberFormatter > & xFormatter,
-                                         const Reference< XPropertySet > & 
xField)
+                                         const Reference< XPropertySet > & 
xField,
+                                         bool bUseRealName)
 {
     // Guard the parsing
     ::osl::MutexGuard aGuard(getMutex());
@@ -1182,7 +1183,7 @@ OSQLParseNode* OSQLParser::predicateTree(OUString& 
rErrorMessage, const OUString
             // #75243# use the RealName of the column if there is any 
otherwise the name which could be the alias
             // of the field
             Reference< XPropertySetInfo> xInfo = 
m_xField->getPropertySetInfo();
-            if ( 
xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
+            if ( bUseRealName && 
xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
                 
m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))
 >>= aString;
             else
                 
m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))
 >>= aString;
diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx 
b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index e21cfe7..312395d 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -3080,10 +3080,23 @@ OSQLParseNode* 
OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef pE
     }
 
     OUString sTest(_sCriteria);
+    // _rxColumn, if it is a "lookup" column, not a computed column,
+    // is guaranteed to be the column taken from the *source* of the column,
+    // that is either a table or another query.
+    // _rxColumn is *not* taken from the columns of the query we are 
constructing
+    // (and rightfully so, since it may not be part of these columns; SELECT A 
FROM t WHERE B = foo)
+    // If it is a computed column, we just constructed it above, with same 
Name and RealName.
+    // In all cases, we should use the "external" name of the column, not the 
"RealName";
+    // the latter is the name that the column had in the source of the source 
query.
+    // An example: we are designing "SELECT A, B FROM q WHERE C='foo'"
+    // q itself is query "SELECT aye AS A, bee as B, cee as C FROM t"
+    // We are currently treating the entry "C='foo'"
+    // Then _rxColumn has Name "C" and RealName "cee". We should *obviously* 
use "C", not "cee".
     OSQLParseNode* pParseNode = rParser.predicateTree(  _rsErrorMessage,
                                                         sTest,
                                                         
static_cast<OQueryController&>(getController()).getNumberFormatter(),
-                                                        _rxColumn);
+                                                        _rxColumn,
+                                                        false);
     return pParseNode;
 }
 
diff --git a/include/connectivity/sqlparse.hxx 
b/include/connectivity/sqlparse.hxx
index 8240be5..398e69f 100644
--- a/include/connectivity/sqlparse.hxx
+++ b/include/connectivity/sqlparse.hxx
@@ -191,9 +191,12 @@ namespace connectivity
                        bool bInternational = false);
 
         // Check a Predicate
+        // set bUseRealName to false if you pass a xField that comes from 
where you got that field,
+        // as opposed from to from yourself.
         OSQLParseNode* predicateTree(OUString& rErrorMessage, const OUString& 
rStatement,
                        const ::com::sun::star::uno::Reference< 
::com::sun::star::util::XNumberFormatter > & xFormatter,
-                       const ::com::sun::star::uno::Reference< 
::com::sun::star::beans::XPropertySet > & xField);
+                       const ::com::sun::star::uno::Reference< 
::com::sun::star::beans::XPropertySet > & xField,
+                       bool bUseRealName = true);
 
         // Access to the context
         const IParseContext& getContext() const {return *m_pContext;}
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to