Tag: cws_src680_kaddrbook
User: ebischoff
Date: 05/11/28 02:59:34

Added:
 /dba/connectivity/source/drivers/kab/
  korder.cxx, korder.hxx

Modified:
 /dba/connectivity/source/drivers/kab/
  makefile.mk, KStatement.cxx, KStatement.hxx, KResultSet.cxx, KResultSet.hxx

Log:
 Handling ORDER BY clauses

File Changes:

Directory: /dba/connectivity/source/drivers/kab/
================================================

File [added]: korder.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/korder.cxx?rev=1.1.2.1&content-type=text/vnd.viewcvs-markup
Added lines: 0
--------------

File [added]: korder.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/korder.hxx?rev=1.1.2.1&content-type=text/vnd.viewcvs-markup
Added lines: 0
--------------

File [changed]: makefile.mk
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/makefile.mk?r1=1.1.2.5&r2=1.1.2.6
Delta lines:  +3 -2
-------------------
--- makefile.mk 13 Sep 2005 18:20:42 -0000      1.1.2.5
+++ makefile.mk 28 Nov 2005 10:59:30 -0000      1.1.2.6
@@ -2,9 +2,9 @@
 #
 #   $RCSfile: makefile.mk,v $
 #
-#   $Revision: 1.1.2.5 $
+#   $Revision: 1.1.2.6 $
 #
-#   last change: $Author: ebischoff $ $Date: 2005/09/13 18:20:42 $
+#   last change: $Author: ebischoff $ $Date: 2005/11/28 10:59:30 $
 #
 #   The Contents of this file are made available subject to the terms of
 #   either of the following licenses
@@ -91,6 +91,7 @@
        $(SLO)$/KResultSetMetaData.obj  \
        $(SLO)$/KDriver.obj                             \
        $(SLO)$/kcondition.obj                  \
+       $(SLO)$/korder.obj                              \
        $(SLO)$/kfields.obj                             \
  
 CFLAGS+=$(KDE_CFLAGS)

File [changed]: KStatement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KStatement.cxx?r1=1.1.2.9&r2=1.1.2.10
Delta lines:  +73 -6
--------------------
--- KStatement.cxx      22 Nov 2005 14:38:54 -0000      1.1.2.9
+++ KStatement.cxx      28 Nov 2005 10:59:31 -0000      1.1.2.10
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: KStatement.cxx,v $
  *
- *  $Revision: 1.1.2.9 $
+ *  $Revision: 1.1.2.10 $
  *
- *  last change: $Author: ebischoff $ $Date: 2005/11/22 14:38:54 $
+ *  last change: $Author: ebischoff $ $Date: 2005/11/28 10:59:31 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -75,6 +75,9 @@
 #ifndef _CONNECTIVITY_KAB_CONDITION_HXX_
 #include "kcondition.hxx"
 #endif
+#ifndef _CONNECTIVITY_KAB_ORDER_HXX_
+#include "korder.hxx"
+#endif
 
 #ifndef CONNECTIVITY_CONNECTION_HXX
 #include "TConnection.hxx"
@@ -238,6 +241,52 @@
                ::rtl::OUString::createFromAscii("Syntax error or keyword not 
recognized."),
                NULL);
 }
+// 
-----------------------------------------------------------------------------
+KabOrder *KabCommonStatement::analyseOrderByClause(const OSQLParseNode 
*pParseNode) const throw(SQLException)
+{
+       if (SQL_ISRULE(pParseNode, ordering_spec_commalist))
+       {
+               KabComplexOrder *list = new KabComplexOrder();
+               sal_uInt32 n = pParseNode->count();
+
+               // Iterate through the ordering columns
+               for (sal_uInt32 i = 0; i < n; i++)
+               {
+                       list->addOrder
+                               (analyseOrderByClause(pParseNode->getChild(i)));
+               }
+
+               return list;
+       }
+       else if (SQL_ISRULE(pParseNode, ordering_spec))
+       {
+               if (pParseNode->count() == 2)
+               {
+                       OSQLParseNode* pColumnRef = pParseNode->getChild(0);
+                       OSQLParseNode* pAscendingDescending = 
pParseNode->getChild(1);
+
+                       if (SQL_ISRULE(pColumnRef, column_ref))
+                       {
+                               if (pColumnRef->count() == 1)
+                               // According to Mozilla driver, case '3' is 
possible as well,
+                               // although it has not possible to reproduce it 
so far
+                               {
+                                       ::rtl::OUString sColumnName =
+                                               
pColumnRef->getChild(0)->getTokenValue();
+                                       sal_Bool bAscending =
+                                               
SQL_ISTOKEN(pAscendingDescending, DESC)?
+                                               sal_False:
+                                               sal_True;
+
+                                       return new KabSimpleOrder(sColumnName, 
bAscending);
+                               }
+                       }
+               }
+       }
+       ::dbtools::throwGenericSQLException(
+               ::rtl::OUString::createFromAscii("Syntax error or keyword not 
recognized."),
+               NULL);
+}
 
//------------------------------------------------------------------------------
 sal_Bool KabCommonStatement::isTableKnown(KabResultSet *pResult) const
 {
@@ -292,6 +341,24 @@
        // no WHERE clause: get all rows
        pResult->allKabAddressees();
 }
+// -------------------------------------------------------------------------
+void KabCommonStatement::sortAddressees(KabResultSet *pResult) const 
throw(SQLException)
+{
+       const OSQLParseNode *pParseNode;
+       KabOrder *pOrder;
+
+       pParseNode = m_aSQLIterator.getOrderTree();
+       if (pParseNode != NULL)
+       {
+               if (SQL_ISRULE(pParseNode, opt_order_by_clause))
+               {
+                       pParseNode = pParseNode->getChild(2);
+                       pOrder = analyseOrderByClause(pParseNode);
+                       pResult->sortKabAddressees(pOrder);
+                       delete pOrder;
+               }
+       }
+}
 //-----------------------------------------------------------------------------
 Any SAL_CALL KabCommonStatement::queryInterface( const Type & rType ) 
throw(RuntimeException)
 {
@@ -364,8 +431,8 @@
                        {
                                setKabFields(pResult);          // SELECT which 
columns ?
                                selectAddressees(pResult);      // WHERE which 
condition ?
-// To be continued: ORDER BY "Name",
-//                  DISTINCT
+                               sortAddressees(pResult);        // ORDER BY 
which columns ?
+// To be continued: DISTINCT
 //                                 etc...
                        }
                        break;

File [changed]: KStatement.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KStatement.hxx?r1=1.1.2.3&r2=1.1.2.4
Delta lines:  +5 -2
-------------------
--- KStatement.hxx      1 Sep 2005 17:11:30 -0000       1.1.2.3
+++ KStatement.hxx      28 Nov 2005 10:59:31 -0000      1.1.2.4
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: KStatement.hxx,v $
  *
- *  $Revision: 1.1.2.3 $
+ *  $Revision: 1.1.2.4 $
  *
- *  last change: $Author: ebischoff $ $Date: 2005/09/01 17:11:30 $
+ *  last change: $Author: ebischoff $ $Date: 2005/11/28 10:59:31 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -120,9 +120,12 @@
                protected:
                        class KabCondition *analyseWhereClause(
                                const OSQLParseNode *pParseNode) const 
throw(::com::sun::star::sdbc::SQLException);
+                       class KabOrder *analyseOrderByClause(
+                               const OSQLParseNode *pParseNode) const 
throw(::com::sun::star::sdbc::SQLException);
                        sal_Bool isTableKnown(class KabResultSet *pResult) 
const;
                        void setKabFields(class KabResultSet *pResult) const 
throw(::com::sun::star::sdbc::SQLException);
                        void selectAddressees(KabResultSet *pResult) const 
throw(::com::sun::star::sdbc::SQLException);
+                       void sortAddressees(KabResultSet *pResult) const 
throw(::com::sun::star::sdbc::SQLException);
 
                        // OPropertyArrayUsageHelper
                        virtual ::cppu::IPropertyArrayHelper* 
createArrayHelper() const;

File [changed]: KResultSet.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KResultSet.cxx?r1=1.1.2.9&r2=1.1.2.10
Delta lines:  +36 -11
---------------------
--- KResultSet.cxx      24 Nov 2005 12:46:34 -0000      1.1.2.9
+++ KResultSet.cxx      28 Nov 2005 10:59:31 -0000      1.1.2.10
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: KResultSet.cxx,v $
  *
- *  $Revision: 1.1.2.9 $
+ *  $Revision: 1.1.2.10 $
  *
- *  last change: $Author: ebischoff $ $Date: 2005/11/24 12:46:34 $
+ *  last change: $Author: ebischoff $ $Date: 2005/11/28 10:59:31 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -69,6 +69,9 @@
 #ifndef _CONNECTIVITY_KAB_CONDITION_HXX_
 #include "kcondition.hxx"
 #endif
+#ifndef _CONNECTIVITY_KAB_ORDER_HXX_
+#include "korder.hxx"
+#endif
 #ifndef _CONNECTIVITY_KAB_FIELDS_HXX_
 #include "kfields.hxx"
 #endif
@@ -117,8 +120,7 @@
 // -------------------------------------------------------------------------
 void KabResultSet::allKabAddressees()
 {
-       KabCommonStatement* pStatement = m_xStatement.get();
-       KabConnection* pConnection = static_cast<KabConnection 
*>(pStatement->getConnection().get());
+       KabConnection* pConnection = static_cast< KabConnection 
*>(m_xStatement->getConnection().get());
        KABC::AddressBook* pAddressBook = pConnection->getAddressBook();
 
        m_aKabAddressees = pAddressBook->allAddressees();
@@ -126,8 +128,7 @@
 // -------------------------------------------------------------------------
 void KabResultSet::someKabAddressees(const KabCondition *pCondition)
 {
-       KabCommonStatement* pStatement = m_xStatement.get();
-       KabConnection* pConnection = static_cast<KabConnection 
*>(pStatement->getConnection().get());
+       KabConnection* pConnection = static_cast< KabConnection 
*>(m_xStatement->getConnection().get());
        KABC::AddressBook* pAddressBook = pConnection->getAddressBook();
 
        KABC::AddressBook::Iterator iterator;
@@ -141,6 +142,29 @@
        }
 }
 // -------------------------------------------------------------------------
+void KabResultSet::sortKabAddressees(const KabOrder *pOrder)
+{
+       // We do not use class KAddresseeList, which has a sorting algorithm in 
it, because
+       // it uses templates. It would expand to more or less the same code as 
the one
+       // which follows, but it would need not be called in a much less 
convenient way.
+
+       KABC::Addressee::List::Iterator
+               begin = m_aKabAddressees.begin(),
+               end = m_aKabAddressees.end(),
+               iterator;
+
+       // Bubble sort. Feel free to implement a better algorithm.
+       while (begin != end)
+       {
+               end--;
+               for (iterator = begin; iterator != end; ++iterator)
+               {
+                       if (pOrder->compare(*iterator, *end) > 0)
+                               qSwap(*iterator, *end);
+               }
+       }
+}
+// -------------------------------------------------------------------------
 void KabResultSet::disposing()
 {
        OPropertySetHelper::disposing();
@@ -216,8 +240,7 @@
 
        if (m_nRowPos != -1 && m_nRowPos != nAddressees && m_xMetaData.is())
        {
-               KabResultSetMetaData *pMeta = static_cast<KabResultSetMetaData 
*>(m_xMetaData.get());
-               sal_Int32 nFieldNumber = pMeta->fieldAtColumn(columnIndex);
+               sal_Int32 nFieldNumber = 
m_xMetaData->fieldAtColumn(columnIndex);
                QString aQtName;
 
                switch (nFieldNumber)
@@ -468,9 +491,10 @@
        checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
 
        if (!m_xMetaData.is())
-               m_xMetaData = new 
KabResultSetMetaData(m_xStatement.get()->getOwnConnection());
+               m_xMetaData = new 
KabResultSetMetaData(m_xStatement->getOwnConnection());
 
-       return m_xMetaData;
+       Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
+       return xMetaData;
 }
 // -------------------------------------------------------------------------
 sal_Bool SAL_CALL KabResultSet::isBeforeFirst() throw(SQLException, 
RuntimeException)
@@ -624,7 +648,8 @@
        ::osl::MutexGuard aGuard( m_aMutex );
        checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
 
-       return m_xStatement;
+       Reference< XStatement > xStatement = m_xStatement.get();
+       return xStatement;
 }
 // -------------------------------------------------------------------------
 sal_Bool SAL_CALL KabResultSet::rowDeleted() throw(SQLException, 
RuntimeException)

File [changed]: KResultSet.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KResultSet.hxx?r1=1.1.2.4&r2=1.1.2.5
Delta lines:  +8 -6
-------------------
--- KResultSet.hxx      22 Nov 2005 10:52:46 -0000      1.1.2.4
+++ KResultSet.hxx      28 Nov 2005 10:59:31 -0000      1.1.2.5
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: KResultSet.hxx,v $
  *
- *  $Revision: 1.1.2.4 $
+ *  $Revision: 1.1.2.5 $
  *
- *  last change: $Author: ebischoff $ $Date: 2005/11/22 10:52:46 $
+ *  last change: $Author: ebischoff $ $Date: 2005/11/28 10:59:31 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -65,6 +65,9 @@
 #ifndef _CONNECTIVITY_KAB_STATEMENT_HXX_
 #include "KStatement.hxx"
 #endif
+#ifndef _CONNECTIVITY_KAB_RESULTSETMETADATA_HXX_
+#include "KResultSetMetaData.hxx"
+#endif
 #include <kabc/addressee.h>
 
 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
@@ -118,10 +121,8 @@
                                                         public 
comphelper::OPropertyArrayUsageHelper<KabResultSet>
                {
                protected:
-                       ::com::sun::star::uno::Reference< KabCommonStatement >
-                                                                               
                                m_xStatement;           // the statement that 
has created this result set
-                       ::com::sun::star::uno::Reference< 
::com::sun::star::sdbc::XResultSetMetaData >
-                                                                               
                                m_xMetaData;            // the description of 
the columns in this result set
+                       ::rtl::Reference< KabCommonStatement >          
m_xStatement;           // the statement that has created this result set
+                       ::rtl::Reference< KabResultSetMetaData >        
m_xMetaData;            // the description of the columns in this result set
                        ::KABC::Addressee::List                                 
        m_aKabAddressees;       // address book entries matching the query
                        sal_Int32                                               
                        m_nRowPos;                      // the current row 
within the result set
                        sal_Bool                                                
                        m_bWasNull;                     // last entry retrieved 
from this result set was NULL
@@ -161,6 +162,7 @@
 
                        void allKabAddressees();
                        void someKabAddressees(const class KabCondition 
*pCondition);
+                       void sortKabAddressees(const class KabOrder *pOrder);
 
                        // ::cppu::OComponentHelper
                        virtual void SAL_CALL disposing(void);




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to