LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - queryorder.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 364 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "queryorder.hrc"
      21                 :            : #include "queryorder.hxx"
      22                 :            : #include "dbustrings.hrc"
      23                 :            : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      24                 :            : #include <com/sun/star/sdbc/ColumnSearch.hpp>
      25                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      26                 :            : #include <tools/debug.hxx>
      27                 :            : #include "moduledbu.hxx"
      28                 :            : #include <connectivity/sqliterator.hxx>
      29                 :            : #include <connectivity/dbtools.hxx>
      30                 :            : #include <comphelper/extract.hxx>
      31                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      32                 :            : #include <tools/diagnose_ex.h>
      33                 :            : #include <algorithm>
      34                 :            : 
      35                 :            : using namespace dbaui;
      36                 :            : using namespace connectivity;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::container;
      39                 :            : using namespace ::com::sun::star::util;
      40                 :            : using namespace ::com::sun::star::sdb;
      41                 :            : using namespace ::com::sun::star::sdbc;
      42                 :            : using namespace ::com::sun::star::sdbcx;
      43                 :            : using namespace ::com::sun::star::beans;
      44                 :            : 
      45                 :            : DBG_NAME(DlgOrderCrit)
      46                 :            : 
      47                 :          0 : DlgOrderCrit::DlgOrderCrit( Window * pParent,
      48                 :            :                             const Reference< XConnection>& _rxConnection,
      49                 :            :                             const Reference< XSingleSelectQueryComposer >& _rxComposer,
      50                 :            :                             const Reference< XNameAccess>& _rxCols)
      51                 :            :              :ModalDialog( pParent, ModuleRes(DLG_ORDERCRIT) )
      52                 :            :             ,aLB_ORDERFIELD1(   this, ModuleRes( LB_ORDERFIELD1 ) )
      53                 :            :             ,aLB_ORDERVALUE1(   this, ModuleRes( LB_ORDERVALUE1 ) )
      54                 :            :             ,aLB_ORDERFIELD2(   this, ModuleRes( LB_ORDERFIELD2 ) )
      55                 :            :             ,aLB_ORDERVALUE2(   this, ModuleRes( LB_ORDERVALUE2 ) )
      56                 :            :             ,aLB_ORDERFIELD3(   this, ModuleRes( LB_ORDERFIELD3 ) )
      57                 :            :             ,aLB_ORDERVALUE3(   this, ModuleRes( LB_ORDERVALUE3 ) )
      58                 :            :             ,aFT_ORDERFIELD(    this, ModuleRes( FT_ORDERFIELD ) )
      59                 :            :             ,aFT_ORDERAFTER1(   this, ModuleRes( FT_ORDERAFTER1 ) )
      60                 :            :             ,aFT_ORDERAFTER2(   this, ModuleRes( FT_ORDERAFTER2 ) )
      61                 :            :             ,aFT_ORDEROPER(     this, ModuleRes( FT_ORDEROPER ) )
      62                 :            :             ,aFT_ORDERDIR(      this, ModuleRes( FT_ORDERDIR ) )
      63                 :            :             ,aBT_OK(            this, ModuleRes( BT_OK ) )
      64                 :            :             ,aBT_CANCEL(        this, ModuleRes( BT_CANCEL ) )
      65                 :            :             ,aBT_HELP(          this, ModuleRes( BT_HELP ) )
      66                 :            :             ,aFL_ORDER(         this, ModuleRes( FL_ORDER ) )
      67                 :            :             ,aSTR_NOENTRY(      ModuleRes( STR_NOENTRY ) )
      68                 :            :             ,m_xQueryComposer( _rxComposer )
      69                 :            :             ,m_xColumns(_rxCols)
      70 [ #  # ][ #  # ]:          0 :             ,m_xConnection(_rxConnection)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      71                 :            : {
      72                 :            :     DBG_CTOR(DlgOrderCrit,NULL);
      73                 :            : 
      74         [ #  # ]:          0 :     AllSettings aSettings( GetSettings() );
      75         [ #  # ]:          0 :     StyleSettings aStyle( aSettings.GetStyleSettings() );
      76         [ #  # ]:          0 :     aStyle.SetAutoMnemonic( sal_False );
      77         [ #  # ]:          0 :     aSettings.SetStyleSettings( aStyle );
      78         [ #  # ]:          0 :     SetSettings( aSettings );
      79                 :            : 
      80                 :          0 :     m_aColumnList[0] = &aLB_ORDERFIELD1;
      81                 :          0 :     m_aColumnList[1] = &aLB_ORDERFIELD2;
      82                 :          0 :     m_aColumnList[2] = &aLB_ORDERFIELD3;
      83                 :            : 
      84                 :          0 :     m_aValueList[0] = &aLB_ORDERVALUE1;
      85                 :          0 :     m_aValueList[1] = &aLB_ORDERVALUE2;
      86                 :          0 :     m_aValueList[2] = &aLB_ORDERVALUE3;
      87                 :            : 
      88                 :            :     xub_StrLen j;
      89         [ #  # ]:          0 :     for(j=0 ; j < DOG_ROWS ; j++ )
      90                 :            :     {
      91         [ #  # ]:          0 :         m_aColumnList[j]->InsertEntry( aSTR_NOENTRY );
      92                 :            :     }
      93                 :            : 
      94         [ #  # ]:          0 :     for( j=0 ; j < DOG_ROWS ; j++ )
      95                 :            :     {
      96         [ #  # ]:          0 :         m_aColumnList[j]->SelectEntryPos(0);
      97         [ #  # ]:          0 :         m_aValueList[j]->SelectEntryPos(0);
      98                 :            :     }
      99                 :            :     try
     100                 :            :     {
     101                 :            :         // ... also the remaining fields
     102 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString> aNames = m_xColumns->getElementNames();
     103                 :          0 :         const ::rtl::OUString* pIter = aNames.getConstArray();
     104                 :          0 :         const ::rtl::OUString* pEnd   = pIter + aNames.getLength();
     105                 :          0 :         Reference<XPropertySet> xColumn;
     106         [ #  # ]:          0 :         for(;pIter != pEnd;++pIter)
     107                 :            :         {
     108 [ #  # ][ #  # ]:          0 :             xColumn.set(m_xColumns->getByName(*pIter),UNO_QUERY);
                 [ #  # ]
     109                 :            :             OSL_ENSURE(xColumn.is(),"Column is null!");
     110         [ #  # ]:          0 :             if ( xColumn.is() )
     111                 :            :             {
     112                 :          0 :                 sal_Int32 nDataType = 0;
     113 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
                 [ #  # ]
     114         [ #  # ]:          0 :                 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
     115         [ #  # ]:          0 :                 if(eColumnSearch != ColumnSearch::NONE)
     116                 :            :                 {
     117         [ #  # ]:          0 :                     for( j=0 ; j < DOG_ROWS ; j++ )
     118                 :            :                     {
     119 [ #  # ][ #  # ]:          0 :                         m_aColumnList[j]->InsertEntry(*pIter);
                 [ #  # ]
     120                 :            :                     }
     121                 :            :                 }
     122                 :            :             }
     123                 :            :         }
     124                 :            : 
     125 [ #  # ][ #  # ]:          0 :         m_sOrgOrder = m_xQueryComposer->getOrder();
     126 [ #  # ][ #  # ]:          0 :         impl_initializeOrderList_nothrow();
                 [ #  # ]
     127                 :            :     }
     128         [ #  # ]:          0 :     catch(const Exception&)
     129                 :            :     {
     130                 :            :         DBG_UNHANDLED_EXCEPTION();
     131                 :            :     }
     132         [ #  # ]:          0 :     EnableLines();
     133                 :            : 
     134         [ #  # ]:          0 :     aLB_ORDERFIELD1.SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
     135         [ #  # ]:          0 :     aLB_ORDERFIELD2.SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :     FreeResource();
                 [ #  # ]
     138                 :          0 : }
     139                 :            : 
     140 [ #  # ][ #  # ]:          0 : DlgOrderCrit::~DlgOrderCrit()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     141                 :            : {
     142                 :            :     DBG_DTOR(DlgOrderCrit,NULL);
     143         [ #  # ]:          0 : }
     144                 :            : 
     145                 :          0 : IMPL_LINK_INLINE_START( DlgOrderCrit, FieldListSelectHdl, ListBox *, /*pListBox*/ )
     146                 :            : {
     147                 :            :     DBG_CHKTHIS(DlgOrderCrit,NULL);
     148                 :          0 :     EnableLines();
     149                 :          0 :     return 0;
     150                 :            : }
     151                 :          0 : IMPL_LINK_INLINE_END( DlgOrderCrit, FieldListSelectHdl, ListBox *, pListBox )
     152                 :            : 
     153                 :          0 : void DlgOrderCrit::impl_initializeOrderList_nothrow()
     154                 :            : {
     155                 :            :     try
     156                 :            :     {
     157         [ #  # ]:          0 :         const ::rtl::OUString sNameProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
     158         [ #  # ]:          0 :         const ::rtl::OUString sAscendingProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAscending" ) );
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xOrderColumns( m_xQueryComposer->getOrderColumns(), UNO_QUERY_THROW );
                 [ #  # ]
     161 [ #  # ][ #  # ]:          0 :         sal_Int32 nColumns = xOrderColumns->getCount();
     162         [ #  # ]:          0 :         if ( nColumns > DOG_ROWS )
     163                 :          0 :             nColumns = DOG_ROWS;
     164                 :            : 
     165         [ #  # ]:          0 :         for ( sal_Int32 i = 0; i < nColumns; ++i )
     166                 :            :         {
     167 [ #  # ][ #  # ]:          0 :             Reference< XPropertySet > xColumn( xOrderColumns->getByIndex( i ), UNO_QUERY_THROW );
                 [ #  # ]
     168                 :            : 
     169                 :          0 :             ::rtl::OUString sColumnName;
     170                 :          0 :             sal_Bool        bIsAscending( sal_True );
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue( sNameProperty ) >>= sColumnName;
     173 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue( sAscendingProperty ) >>= bIsAscending;
     174                 :            : 
     175 [ #  # ][ #  # ]:          0 :             m_aColumnList[i]->SelectEntry( sColumnName );
                 [ #  # ]
     176         [ #  # ]:          0 :             m_aValueList[i]->SelectEntryPos( bIsAscending ? 0 : 1 );
     177         [ #  # ]:          0 :         }
     178                 :            :     }
     179                 :          0 :     catch( const Exception& )
     180                 :            :     {
     181                 :            :         DBG_UNHANDLED_EXCEPTION();
     182                 :            :     }
     183                 :          0 : }
     184                 :            : 
     185                 :          0 : void DlgOrderCrit::EnableLines()
     186                 :            : {
     187                 :            :     DBG_CHKTHIS(DlgOrderCrit,NULL);
     188                 :            : 
     189         [ #  # ]:          0 :     if ( aLB_ORDERFIELD1.GetSelectEntryPos() == 0 )
     190                 :            :     {
     191                 :          0 :         aLB_ORDERFIELD2.Disable();
     192                 :          0 :         aLB_ORDERVALUE2.Disable();
     193                 :            : 
     194                 :          0 :         aLB_ORDERFIELD2.SelectEntryPos( 0 );
     195                 :          0 :         aLB_ORDERVALUE2.SelectEntryPos( 0 );
     196                 :            :     }
     197                 :            :     else
     198                 :            :     {
     199                 :          0 :         aLB_ORDERFIELD2.Enable();
     200                 :          0 :         aLB_ORDERVALUE2.Enable();
     201                 :            :     }
     202                 :            : 
     203         [ #  # ]:          0 :     if ( aLB_ORDERFIELD2.GetSelectEntryPos() == 0 )
     204                 :            :     {
     205                 :          0 :         aLB_ORDERFIELD3.Disable();
     206                 :          0 :         aLB_ORDERVALUE3.Disable();
     207                 :            : 
     208                 :          0 :         aLB_ORDERFIELD3.SelectEntryPos( 0 );
     209                 :          0 :         aLB_ORDERVALUE3.SelectEntryPos( 0 );
     210                 :            :     }
     211                 :            :     else
     212                 :            :     {
     213                 :          0 :         aLB_ORDERFIELD3.Enable();
     214                 :          0 :         aLB_ORDERVALUE3.Enable();
     215                 :            :     }
     216                 :          0 : }
     217                 :            : 
     218                 :          0 : ::rtl::OUString DlgOrderCrit::GetOrderList( ) const
     219                 :            : {
     220                 :            :     DBG_CHKTHIS(DlgOrderCrit,NULL);
     221 [ #  # ][ #  # ]:          0 :     Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
     222 [ #  # ][ #  # ]:          0 :     ::rtl::OUString sQuote  = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : ::rtl::OUString();
                 [ #  # ]
     223 [ #  # ][ #  # ]:          0 :     static const ::rtl::OUString sDESC(RTL_CONSTASCII_USTRINGPARAM(" DESC "));
         [ #  # ][ #  # ]
     224 [ #  # ][ #  # ]:          0 :     static const ::rtl::OUString sASC(RTL_CONSTASCII_USTRINGPARAM(" ASC "));
         [ #  # ][ #  # ]
     225                 :            : 
     226 [ #  # ][ #  # ]:          0 :     Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
                 [ #  # ]
     227                 :            : 
     228                 :          0 :     ::rtl::OUString sOrder;
     229         [ #  # ]:          0 :     for( sal_uInt16 i=0 ; i<DOG_ROWS; i++ )
     230                 :            :     {
     231 [ #  # ][ #  # ]:          0 :         if(m_aColumnList[i]->GetSelectEntryPos() != 0)
     232                 :            :         {
     233         [ #  # ]:          0 :             if(!sOrder.isEmpty())
     234         [ #  # ]:          0 :                 sOrder += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
     235                 :            : 
     236         [ #  # ]:          0 :             String sName = m_aColumnList[i]->GetSelectEntry();
     237                 :            :             try
     238                 :            :             {
     239                 :          0 :                 sal_Bool bFunction = sal_False;
     240                 :          0 :                 Reference< XPropertySet > xColumn;
     241 [ #  # ][ #  # ]:          0 :                 if ( xColumns.is() && xColumns->hasByName( sName ) && (xColumns->getByName( sName ) >>= xColumn) && xColumn.is() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
          #  #  #  #  #  
              # ][ #  # ]
     242                 :            :                 {
     243 [ #  # ][ #  # ]:          0 :                     if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     244                 :            :                     {
     245                 :          0 :                         ::rtl::OUString sRealName;
     246 [ #  # ][ #  # ]:          0 :                         xColumn->getPropertyValue(PROPERTY_REALNAME)    >>= sRealName;
                 [ #  # ]
     247         [ #  # ]:          0 :                         sName = sRealName;
     248 [ #  # ][ #  # ]:          0 :                         static ::rtl::OUString sFunction(RTL_CONSTASCII_USTRINGPARAM("Function"));
         [ #  # ][ #  # ]
     249 [ #  # ][ #  # ]:          0 :                         if ( xColumn->getPropertySetInfo()->hasPropertyByName(sFunction) )
         [ #  # ][ #  # ]
                 [ #  # ]
     250 [ #  # ][ #  # ]:          0 :                             xColumn->getPropertyValue(sFunction) >>= bFunction;
     251                 :            :                     }
     252                 :            :                 }
     253         [ #  # ]:          0 :                 if ( bFunction )
     254         [ #  # ]:          0 :                     sOrder += sName;
     255                 :            :                 else
     256 [ #  # ][ #  # ]:          0 :                     sOrder += ::dbtools::quoteName(sQuote,sName);
                 [ #  # ]
     257                 :            :             }
     258         [ #  # ]:          0 :             catch(const Exception&)
     259                 :            :             {
     260                 :            :             }
     261 [ #  # ][ #  # ]:          0 :             if(m_aValueList[i]->GetSelectEntryPos())
     262                 :          0 :                 sOrder += sDESC;
     263                 :            :             else
     264         [ #  # ]:          0 :                 sOrder += sASC;
     265                 :            :         }
     266                 :            :     }
     267                 :          0 :     return sOrder;
     268                 :            : }
     269                 :            : 
     270                 :          0 : void DlgOrderCrit::BuildOrderPart()
     271                 :            : {
     272                 :            :     DBG_CHKTHIS(DlgOrderCrit,NULL);
     273         [ #  # ]:          0 :     m_xQueryComposer->setOrder(GetOrderList());
     274                 :          0 : }
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10