LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - queryfilter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 469 0.2 %
Date: 2015-06-13 12:38:46 Functions: 2 25 8.0 %
Legend: Lines: hit not hit

          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 "queryfilter.hxx"
      21             : #include "moduledbu.hxx"
      22             : #include <com/sun/star/sdbc/DataType.hpp>
      23             : #include <com/sun/star/util/Date.hpp>
      24             : #include <com/sun/star/util/DateTime.hpp>
      25             : #include <com/sun/star/util/Time.hpp>
      26             : #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
      27             : #include <com/sun/star/sdbc/ColumnSearch.hpp>
      28             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      29             : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
      30             : #include <com/sun/star/sdbc/XRow.hpp>
      31             : #include <com/sun/star/sdbc/XResultSet.hpp>
      32             : #include <com/sun/star/container/XNameAccess.hpp>
      33             : #include <comphelper/string.hxx>
      34             : #include <tools/diagnose_ex.h>
      35             : #include <osl/diagnose.h>
      36             : #include <connectivity/sqliterator.hxx>
      37             : #include <connectivity/dbtools.hxx>
      38             : #include "dbustrings.hrc"
      39             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      40             : 
      41             : using namespace dbaui;
      42             : using namespace connectivity;
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::lang;
      45             : using namespace ::com::sun::star::container;
      46             : using namespace ::com::sun::star::util;
      47             : using namespace ::com::sun::star::sdb;
      48             : using namespace ::com::sun::star::sdbc;
      49             : using namespace ::com::sun::star::sdbcx;
      50             : using namespace ::com::sun::star::beans;
      51             : 
      52           0 : void Replace_OS_PlaceHolder(OUString& aString)
      53             : {
      54           0 :     aString = aString.replaceAll( "*", "%" );
      55           0 :     aString = aString.replaceAll( "?", "_" );
      56           0 : }
      57             : 
      58           0 : void Replace_SQL_PlaceHolder(OUString& aString)
      59             : {
      60           0 :     aString = aString.replaceAll( "%", "*" );
      61           0 :     aString = aString.replaceAll( "_", "?" );
      62           0 : }
      63             : 
      64             : 
      65           0 : DlgFilterCrit::DlgFilterCrit(vcl::Window * pParent,
      66             :                              const Reference< XComponentContext >& rxContext,
      67             :                              const Reference< XConnection>& _rxConnection,
      68             :                              const Reference< XSingleSelectQueryComposer >& _rxComposer,
      69             :                              const Reference< XNameAccess>& _rxCols
      70             :                              )
      71             :     : ModalDialog(pParent, "QueryFilterDialog",
      72             :         "dbaccess/ui/queryfilterdialog.ui")
      73             : 
      74             :     ,m_xQueryComposer(_rxComposer)
      75             :     ,m_xColumns( _rxCols )
      76             :     ,m_xConnection( _rxConnection )
      77           0 :     ,m_xMetaData( _rxConnection->getMetaData() )
      78           0 :     ,m_aPredicateInput( rxContext, _rxConnection, getParseContext() )
      79             : {
      80           0 :     get(m_pLB_WHEREFIELD1, "field1");
      81           0 :     get(m_pLB_WHERECOMP1, "cond1");
      82           0 :     get(m_pET_WHEREVALUE1, "value1");
      83             : 
      84           0 :     get(m_pLB_WHERECOND2, "op2");
      85           0 :     get(m_pLB_WHEREFIELD2, "field2");
      86           0 :     get(m_pLB_WHERECOMP2, "cond2");
      87           0 :     get(m_pET_WHEREVALUE2, "value2");
      88             : 
      89           0 :     get(m_pLB_WHERECOND3, "op3");
      90           0 :     get(m_pLB_WHEREFIELD3, "field3");
      91           0 :     get(m_pLB_WHERECOMP3, "cond3");
      92           0 :     get(m_pET_WHEREVALUE3, "value3");
      93             : 
      94             :     //set all condition preferred width to max width
      95             :     //if all entries exist
      96           0 :     Size aSize(m_pLB_WHERECOMP1->get_preferred_size());
      97           0 :     m_pLB_WHERECOMP1->set_width_request(aSize.Width());
      98           0 :     m_pLB_WHERECOMP2->set_width_request(aSize.Width());
      99           0 :     m_pLB_WHERECOMP3->set_width_request(aSize.Width());
     100           0 :     sal_uInt16 nEntryCount =  m_pLB_WHERECOMP1->GetEntryCount();
     101           0 :     for (sal_uInt16 i = 0; i < nEntryCount; ++i)
     102             :     {
     103           0 :         if (i > 0)
     104           0 :             m_aSTR_COMPARE_OPERATORS += ";";
     105           0 :         m_aSTR_COMPARE_OPERATORS += m_pLB_WHERECOMP1->GetEntry(i);
     106             :     }
     107           0 :     m_pLB_WHERECOMP1->Clear();
     108             : 
     109             :     // ... also write it into the remaining fields
     110           0 :     Sequence< OUString> aNames = m_xColumns->getElementNames();
     111           0 :     const OUString* pIter = aNames.getConstArray();
     112           0 :     const OUString* pEnd   = pIter + aNames.getLength();
     113           0 :     Reference<XPropertySet> xColumn;
     114           0 :     for(;pIter != pEnd;++pIter)
     115             :     {
     116             :         try
     117             :         {
     118           0 :             xColumn.set( m_xColumns->getByName( *pIter ), UNO_QUERY_THROW );
     119             : 
     120           0 :             sal_Int32 nDataType( 0 );
     121           0 :             OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_TYPE ) >>= nDataType );
     122           0 :             sal_Int32 eColumnSearch = ::dbtools::getSearchColumnFlag( m_xConnection, nDataType );
     123           0 :             if ( eColumnSearch == ColumnSearch::NONE )
     124           0 :                 continue;
     125             : 
     126           0 :             bool bIsSearchable( true );
     127           0 :             OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISSEARCHABLE ) >>= bIsSearchable );
     128           0 :             if ( !bIsSearchable )
     129           0 :                 continue;
     130             :         }
     131           0 :         catch( const Exception& )
     132             :         {
     133             :             DBG_UNHANDLED_EXCEPTION();
     134             :         }
     135           0 :         m_pLB_WHEREFIELD1->InsertEntry( *pIter );
     136           0 :         m_pLB_WHEREFIELD2->InsertEntry( *pIter );
     137           0 :         m_pLB_WHEREFIELD3->InsertEntry( *pIter );
     138             :     }
     139             : 
     140           0 :     Reference<XNameAccess> xSelectColumns = Reference<XColumnsSupplier>(m_xQueryComposer,UNO_QUERY)->getColumns();
     141           0 :     aNames = xSelectColumns->getElementNames();
     142           0 :     pIter = aNames.getConstArray();
     143           0 :     pEnd   = pIter + aNames.getLength();
     144           0 :     for(;pIter != pEnd;++pIter)
     145             :     {
     146             :         // don't insert a column name twice
     147           0 :         if ( !m_xColumns->hasByName(*pIter) )
     148             :         {
     149           0 :             xColumn.set(xSelectColumns->getByName(*pIter),UNO_QUERY);
     150             :             OSL_ENSURE(xColumn.is(),"DlgFilterCrit::DlgFilterCrit: Column is null!");
     151           0 :             sal_Int32 nDataType(0);
     152           0 :             xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
     153           0 :             sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
     154             :             // TODO
     155             :             // !pColumn->IsFunction()
     156           0 :             if(eColumnSearch != ColumnSearch::NONE)
     157             :             {
     158           0 :                 m_pLB_WHEREFIELD1->InsertEntry( *pIter );
     159           0 :                 m_pLB_WHEREFIELD2->InsertEntry( *pIter );
     160           0 :                 m_pLB_WHEREFIELD3->InsertEntry( *pIter );
     161             :             }
     162             :         }
     163             :     }
     164             :     // initialize the listboxes with noEntry
     165           0 :     m_pLB_WHEREFIELD1->SelectEntryPos(0);
     166           0 :     m_pLB_WHEREFIELD2->SelectEntryPos(0);
     167           0 :     m_pLB_WHEREFIELD3->SelectEntryPos(0);
     168             : 
     169             :     // insert the criteria into the dialog
     170           0 :     Sequence<Sequence<PropertyValue > > aValues = m_xQueryComposer->getStructuredFilter();
     171           0 :     fillLines(aValues);
     172           0 :     aValues = m_xQueryComposer->getStructuredHavingClause();
     173           0 :     fillLines(aValues);
     174             : 
     175           0 :     EnableLines();
     176             : 
     177           0 :     m_pLB_WHEREFIELD1->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
     178           0 :     m_pLB_WHEREFIELD2->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
     179           0 :     m_pLB_WHEREFIELD3->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
     180             : 
     181           0 :     m_pLB_WHERECOMP1->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
     182           0 :     m_pLB_WHERECOMP2->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
     183           0 :     m_pLB_WHERECOMP3->SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
     184             : 
     185           0 :     m_pET_WHEREVALUE1->SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
     186           0 :     m_pET_WHEREVALUE2->SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
     187           0 :     m_pET_WHEREVALUE3->SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
     188             : 
     189           0 :     if ( m_pET_WHEREVALUE1->IsEnabled() )
     190           0 :         m_pET_WHEREVALUE1->GrabFocus();
     191           0 : }
     192             : 
     193           0 : DlgFilterCrit::~DlgFilterCrit()
     194             : {
     195           0 :     disposeOnce();
     196           0 : }
     197             : 
     198           0 : void DlgFilterCrit::dispose()
     199             : {
     200           0 :     m_pLB_WHEREFIELD1.clear();
     201           0 :     m_pLB_WHERECOMP1.clear();
     202           0 :     m_pET_WHEREVALUE1.clear();
     203           0 :     m_pLB_WHERECOND2.clear();
     204           0 :     m_pLB_WHEREFIELD2.clear();
     205           0 :     m_pLB_WHERECOMP2.clear();
     206           0 :     m_pET_WHEREVALUE2.clear();
     207           0 :     m_pLB_WHERECOND3.clear();
     208           0 :     m_pLB_WHEREFIELD3.clear();
     209           0 :     m_pLB_WHERECOMP3.clear();
     210           0 :     m_pET_WHEREVALUE3.clear();
     211           0 :     ModalDialog::dispose();
     212           0 : }
     213             : 
     214             : #define LbText(x)       ((x).GetSelectEntry())
     215             : #define LbPos(x)        ((x).GetSelectEntryPos())
     216             : 
     217           0 : sal_Int32 DlgFilterCrit::GetOSQLPredicateType( const OUString& _rSelectedPredicate ) const
     218             : {
     219           0 :     sal_Int32 nPredicateIndex = -1;
     220           0 :     for ( sal_Int32 i=0; i < comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS, ';'); ++i)
     221           0 :         if ( m_aSTR_COMPARE_OPERATORS.getToken(i, ';') == _rSelectedPredicate )
     222             :         {
     223           0 :             nPredicateIndex = i;
     224           0 :             break;
     225             :         }
     226             : 
     227           0 :     sal_Int32 nPredicateType = SQLFilterOperator::NOT_SQLNULL;
     228           0 :     switch ( nPredicateIndex )
     229             :     {
     230             :     case 0:
     231           0 :         nPredicateType = SQLFilterOperator::EQUAL;
     232           0 :         break;
     233             :     case 1:
     234           0 :         nPredicateType = SQLFilterOperator::NOT_EQUAL;
     235           0 :         break;
     236             :     case 2:
     237           0 :         nPredicateType = SQLFilterOperator::LESS;
     238           0 :         break;
     239             :     case 3:
     240           0 :         nPredicateType = SQLFilterOperator::LESS_EQUAL;
     241           0 :         break;
     242             :     case 4:
     243           0 :         nPredicateType = SQLFilterOperator::GREATER;
     244           0 :         break;
     245             :     case 5:
     246           0 :         nPredicateType = SQLFilterOperator::GREATER_EQUAL;
     247           0 :         break;
     248             :     case 6:
     249           0 :         nPredicateType = SQLFilterOperator::LIKE;
     250           0 :         break;
     251             :     case 7:
     252           0 :         nPredicateType = SQLFilterOperator::NOT_LIKE;
     253           0 :         break;
     254             :     case 8:
     255           0 :         nPredicateType = SQLFilterOperator::SQLNULL;
     256           0 :         break;
     257             :     case 9:
     258           0 :         nPredicateType = SQLFilterOperator::NOT_SQLNULL;
     259           0 :         break;
     260             :     default:
     261             :         OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
     262           0 :         break;
     263             :     }
     264             : 
     265           0 :     return nPredicateType;
     266             : }
     267             : 
     268           0 : sal_uInt16 DlgFilterCrit::GetSelectionPos(sal_Int32 eType,const ListBox& rListBox)
     269             : {
     270             :     sal_uInt16 nPos;
     271           0 :     switch(eType)
     272             :     {
     273             :         case SQLFilterOperator::EQUAL:
     274           0 :             nPos = 0;
     275           0 :             break;
     276             :         case SQLFilterOperator::NOT_EQUAL:
     277           0 :             nPos = 1;
     278           0 :             break;
     279             :         case SQLFilterOperator::LESS:
     280           0 :             nPos = 2;
     281           0 :             break;
     282             :         case SQLFilterOperator::LESS_EQUAL:
     283           0 :             nPos = 3;
     284           0 :             break;
     285             :         case SQLFilterOperator::GREATER:
     286           0 :             nPos = 4;
     287           0 :             break;
     288             :         case SQLFilterOperator::GREATER_EQUAL:
     289           0 :             nPos = 5;
     290           0 :             break;
     291             :         case SQLFilterOperator::NOT_LIKE:
     292           0 :             nPos = rListBox.GetEntryCount() > 2 ? rListBox.GetEntryCount()-3 : 0;
     293           0 :             break;
     294             :         case SQLFilterOperator::LIKE:
     295           0 :             nPos = rListBox.GetEntryCount() > 2 ? rListBox.GetEntryCount()-4 : 1;
     296           0 :             break;
     297             :         case SQLFilterOperator::SQLNULL:
     298           0 :             nPos = rListBox.GetEntryCount()-2;
     299           0 :             break;
     300             :         case SQLFilterOperator::NOT_SQLNULL:
     301           0 :             nPos = rListBox.GetEntryCount()-1;
     302           0 :             break;
     303             :         default:
     304             :             //  TODO  What value should this be?
     305           0 :             nPos = 0;
     306           0 :             break;
     307             :     }
     308           0 :     return nPos;
     309             : }
     310             : 
     311           0 : bool DlgFilterCrit::getCondition(const ListBox& _rField,const ListBox& _rComp,const Edit& _rValue,PropertyValue& _rFilter) const
     312             : {
     313           0 :     bool bHaving = false;
     314             :     try
     315             :     {
     316           0 :         OUString sTableName;
     317           0 :         _rFilter.Name = _rField.GetSelectEntry();
     318           0 :         Reference< XPropertySet > xColumn = getQueryColumn(_rFilter.Name);
     319           0 :         if ( xColumn.is() )
     320             :         {
     321           0 :             bool bFunction = false;
     322           0 :             Reference< XPropertySetInfo > xInfo = xColumn->getPropertySetInfo();
     323           0 :             if ( xInfo->hasPropertyByName(PROPERTY_REALNAME) )
     324             :             {
     325           0 :                 if ( xInfo->hasPropertyByName(PROPERTY_TABLENAME) )
     326             :                 {
     327           0 :                     xColumn->getPropertyValue(PROPERTY_TABLENAME)   >>= sTableName;
     328           0 :                     if ( !sTableName.isEmpty() )
     329             :                     {
     330             :                         // properly quote all parts of the table name, so
     331             :                         // e.g. <schema>.<table> becomes "<schema>"."<table>"
     332           0 :                         OUString aCatlog,aSchema,aTable;
     333           0 :                         ::dbtools::qualifiedNameComponents( m_xMetaData, sTableName, aCatlog, aSchema, aTable, ::dbtools::eInDataManipulation );
     334           0 :                         sTableName = ::dbtools::composeTableName( m_xMetaData, aCatlog, aSchema, aTable, true, ::dbtools::eInDataManipulation );
     335             :                     }
     336             :                 }
     337           0 :                 xColumn->getPropertyValue(PROPERTY_REALNAME)    >>= _rFilter.Name;
     338             :                 static const char sAgg[] = "AggregateFunction";
     339           0 :                 if ( xInfo->hasPropertyByName(sAgg) )
     340           0 :                     xColumn->getPropertyValue(sAgg) >>= bHaving;
     341             :                 static const char sFunction[] = "Function";
     342           0 :                 if ( xInfo->hasPropertyByName(sFunction) )
     343           0 :                     xColumn->getPropertyValue(sFunction) >>= bFunction;
     344             :             }
     345           0 :             if ( !bFunction )
     346             :             {
     347           0 :                 const OUString aQuote    = m_xMetaData.is() ? m_xMetaData->getIdentifierQuoteString() : OUString();
     348           0 :                 _rFilter.Name = ::dbtools::quoteName(aQuote,_rFilter.Name);
     349           0 :                 if ( !sTableName.isEmpty() )
     350             :                 {
     351             :                     static const char sSep[] = ".";
     352           0 :                     sTableName += sSep;
     353           0 :                     sTableName += _rFilter.Name;
     354           0 :                     _rFilter.Name = sTableName;
     355           0 :                 }
     356           0 :             }
     357           0 :         }
     358             :     }
     359           0 :     catch(const Exception&)
     360             :     {
     361             :     }
     362             : 
     363           0 :     _rFilter.Handle = GetOSQLPredicateType( _rComp.GetSelectEntry() );
     364           0 :     if ( SQLFilterOperator::SQLNULL != _rFilter.Handle && _rFilter.Handle != SQLFilterOperator::NOT_SQLNULL )
     365             :     {
     366           0 :         OUString sPredicateValue;
     367           0 :         m_aPredicateInput.getPredicateValue( _rValue.GetText(), getMatchingColumn( _rValue ) ) >>= sPredicateValue;
     368           0 :         if ( _rFilter.Handle == SQLFilterOperator::LIKE ||
     369           0 :              _rFilter.Handle == SQLFilterOperator::NOT_LIKE )
     370           0 :             ::Replace_OS_PlaceHolder( sPredicateValue );
     371           0 :         _rFilter.Value <<= OUString(sPredicateValue);
     372             :     }
     373           0 :     return bHaving;
     374             : }
     375             : 
     376           0 : Reference< XPropertySet > DlgFilterCrit::getColumn( const OUString& _rFieldName ) const
     377             : {
     378           0 :     Reference< XPropertySet > xColumn;
     379             :     try
     380             :     {
     381           0 :         if ( m_xColumns.is() && m_xColumns->hasByName( _rFieldName ) )
     382           0 :             m_xColumns->getByName( _rFieldName ) >>= xColumn;
     383             : 
     384           0 :         Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
     385           0 :         if ( xColumns.is() && !xColumn.is() )
     386             :         {
     387           0 :             Sequence< OUString> aSeq = xColumns->getElementNames();
     388           0 :             const OUString* pIter = aSeq.getConstArray();
     389           0 :             const OUString* pEnd   = pIter + aSeq.getLength();
     390           0 :             for(;pIter != pEnd;++pIter)
     391             :             {
     392           0 :                 Reference<XPropertySet> xProp(xColumns->getByName(*pIter),UNO_QUERY);
     393           0 :                 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME) )
     394             :                 {
     395           0 :                     OUString sRealName;
     396           0 :                     xProp->getPropertyValue(PROPERTY_REALNAME)  >>= sRealName;
     397           0 :                     if ( sRealName == _rFieldName )
     398             :                     {
     399           0 :                         if ( m_xColumns.is() && m_xColumns->hasByName( *pIter ) )
     400           0 :                             m_xColumns->getByName( *pIter ) >>= xColumn;
     401           0 :                         break;
     402           0 :                     }
     403             :                 }
     404           0 :             }
     405           0 :         }
     406             :     }
     407           0 :     catch( const Exception& )
     408             :     {
     409             :         DBG_UNHANDLED_EXCEPTION();
     410             :     }
     411             : 
     412           0 :     return xColumn;
     413             : }
     414             : 
     415           0 : Reference< XPropertySet > DlgFilterCrit::getQueryColumn( const OUString& _rFieldName ) const
     416             : {
     417           0 :     Reference< XPropertySet > xColumn;
     418             :     try
     419             :     {
     420           0 :         Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
     421           0 :         if ( xColumns.is() && xColumns->hasByName( _rFieldName ) )
     422           0 :             xColumns->getByName( _rFieldName ) >>= xColumn;
     423             :     }
     424           0 :     catch( const Exception& )
     425             :     {
     426             :         DBG_UNHANDLED_EXCEPTION();
     427             :     }
     428             : 
     429           0 :     return xColumn;
     430             : }
     431             : 
     432           0 : Reference< XPropertySet > DlgFilterCrit::getMatchingColumn( const Edit& _rValueInput ) const
     433             : {
     434             :     // the name
     435           0 :     OUString sField;
     436           0 :     if ( &_rValueInput == m_pET_WHEREVALUE1 )
     437             :     {
     438           0 :         sField = m_pLB_WHEREFIELD1->GetSelectEntry();
     439             :     }
     440           0 :     else if ( &_rValueInput == m_pET_WHEREVALUE2 )
     441             :     {
     442           0 :         sField = m_pLB_WHEREFIELD2->GetSelectEntry();
     443             :     }
     444           0 :     else if ( &_rValueInput == m_pET_WHEREVALUE3 )
     445             :     {
     446           0 :         sField = m_pLB_WHEREFIELD3->GetSelectEntry();
     447             :     }
     448             :     else {
     449             :         OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
     450             :     }
     451             : 
     452             :     // the field itself
     453           0 :     return getColumn( sField );
     454             : }
     455             : 
     456           0 : IMPL_LINK( DlgFilterCrit, PredicateLoseFocus, Edit*, _pField )
     457             : {
     458             :     OSL_ENSURE( _pField, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
     459           0 :     if ( _pField )
     460             :     {
     461             :         // retrieve the field affected
     462           0 :         Reference< XPropertySet> xColumn( getMatchingColumn( *_pField ) );
     463             :         // and normalize it's content
     464           0 :         if ( xColumn.is() )
     465             :         {
     466           0 :             OUString sText( _pField->GetText() );
     467           0 :             m_aPredicateInput.normalizePredicateString( sText, xColumn );
     468           0 :             _pField->SetText( sText );
     469           0 :         }
     470             :     }
     471             : 
     472           0 :     return 0L;
     473             : }
     474             : 
     475           0 : void DlgFilterCrit::SetLine( sal_uInt16 nIdx,const PropertyValue& _rItem,bool _bOr  )
     476             : {
     477           0 :     OUString aCondition;
     478           0 :     _rItem.Value >>= aCondition;
     479           0 :     OUString aStr = aCondition;
     480           0 :     if ( _rItem.Handle == SQLFilterOperator::LIKE ||
     481           0 :          _rItem.Handle == SQLFilterOperator::NOT_LIKE )
     482           0 :         ::Replace_SQL_PlaceHolder(aStr);
     483           0 :     aStr = comphelper::string::stripEnd(aStr, ' ');
     484             : 
     485           0 :     Reference< XPropertySet > xColumn = getColumn( _rItem.Name );
     486             : 
     487             :     // remove the predicate from the condition
     488           0 :     switch(_rItem.Handle)
     489             :     {
     490             :         case SQLFilterOperator::EQUAL:
     491             :             //  aStr.Erase(0,1);
     492           0 :             break;
     493             :         case SQLFilterOperator::NOT_EQUAL:
     494           0 :             aStr = aStr.copy(2);
     495           0 :             break;
     496             :         case SQLFilterOperator::LESS:
     497           0 :             aStr = aStr.copy(1);
     498           0 :             break;
     499             :         case SQLFilterOperator::LESS_EQUAL:
     500           0 :             aStr = aStr.copy(2);
     501           0 :             break;
     502             :         case SQLFilterOperator::GREATER:
     503           0 :             aStr = aStr.copy(1);
     504           0 :             break;
     505             :         case SQLFilterOperator::GREATER_EQUAL:
     506           0 :             aStr = aStr.copy(2);
     507           0 :             break;
     508             :         case SQLFilterOperator::NOT_LIKE:
     509           0 :             aStr = aStr.copy(8);
     510           0 :             break;
     511             :         case SQLFilterOperator::LIKE:
     512           0 :             aStr = aStr.copy(4);
     513           0 :             break;
     514             :         case SQLFilterOperator::SQLNULL:
     515           0 :             aStr = aStr.copy(7);
     516           0 :             break;
     517             :         case SQLFilterOperator::NOT_SQLNULL:
     518           0 :             aStr = aStr.copy(11);
     519           0 :             break;
     520             :     }
     521           0 :     aStr = comphelper::string::stripStart(aStr, ' ');
     522             : 
     523             :     // to make sure that we only set first three
     524           0 :     ListBox* pColumnListControl =  NULL;
     525           0 :     ListBox* pPredicateListControl = NULL;
     526           0 :     Edit* pPredicateValueControl = NULL;
     527           0 :     switch( nIdx )
     528             :     {
     529             :         case 0:
     530           0 :             pColumnListControl = m_pLB_WHEREFIELD1;
     531           0 :             pPredicateListControl = m_pLB_WHERECOMP1;
     532           0 :             pPredicateValueControl = m_pET_WHEREVALUE1;
     533           0 :             break;
     534             :         case 1:
     535           0 :             m_pLB_WHERECOND2->SelectEntryPos( _bOr ? 1 : 0 );
     536             : 
     537           0 :             pColumnListControl = m_pLB_WHEREFIELD2;
     538           0 :             pPredicateListControl = m_pLB_WHERECOMP2;
     539           0 :             pPredicateValueControl = m_pET_WHEREVALUE2;
     540           0 :             break;
     541             :         case 2:
     542           0 :             m_pLB_WHERECOND3->SelectEntryPos( _bOr ? 1 : 0 );
     543             : 
     544           0 :             pColumnListControl = m_pLB_WHEREFIELD3;
     545           0 :             pPredicateListControl = m_pLB_WHERECOMP3;
     546           0 :             pPredicateValueControl = m_pET_WHEREVALUE3;
     547           0 :             break;
     548             :     }
     549             : 
     550           0 :     if ( pColumnListControl && pPredicateListControl && pPredicateValueControl )
     551             :     {
     552           0 :         OUString sName;
     553           0 :         if ( xColumn.is() )
     554           0 :             xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
     555             :         else
     556           0 :             sName = _rItem.Name;
     557             :         // select the appropriate field name
     558           0 :         SelectField( *pColumnListControl, sName );
     559           0 :         ListSelectHdl( pColumnListControl );
     560             : 
     561             :         // select the appropriate condition
     562           0 :         pPredicateListControl->SelectEntryPos( GetSelectionPos( (sal_Int32)_rItem.Handle, *pPredicateListControl ) );
     563             : 
     564             :         // initially normalize this value
     565           0 :         OUString aString( aStr );
     566           0 :         m_aPredicateInput.normalizePredicateString( aString, xColumn );
     567           0 :         pPredicateValueControl->SetText( aString );
     568           0 :     }
     569           0 : }
     570             : 
     571           0 : void DlgFilterCrit::SelectField( ListBox& rBox, const OUString& rField )
     572             : {
     573           0 :     sal_uInt16 nCnt = rBox.GetEntryCount();
     574             : 
     575           0 :     for( sal_uInt16 i=0 ; i<nCnt ; i++ )
     576             :     {
     577           0 :         if(rBox.GetEntry(i) == rField)
     578             :         {
     579           0 :             rBox.SelectEntryPos(i);
     580           0 :             return;
     581             :         }
     582             :     }
     583             : 
     584           0 :     rBox.SelectEntryPos(0);
     585             : }
     586             : 
     587           0 : void DlgFilterCrit::EnableLines()
     588             : {
     589             :     // enabling/disabling of whole lines
     590           0 :     if( LbPos(*m_pLB_WHEREFIELD1) == 0 )
     591             :     {
     592           0 :         m_pLB_WHEREFIELD2->Disable();
     593           0 :         m_pLB_WHERECOND2->Disable();
     594           0 :         m_pLB_WHERECOMP2->Disable();
     595           0 :         m_pET_WHEREVALUE2->Disable();
     596             : 
     597           0 :         m_pLB_WHEREFIELD3->Disable();
     598           0 :         m_pLB_WHERECOND3->Disable();
     599           0 :         m_pLB_WHERECOMP3->Disable();
     600           0 :         m_pET_WHEREVALUE3->Disable();
     601             :     }
     602             :     else
     603             :     {
     604           0 :         m_pLB_WHEREFIELD2->Enable();
     605           0 :         m_pLB_WHERECOND2->Enable();
     606           0 :         m_pLB_WHERECOMP2->Enable();
     607           0 :         m_pET_WHEREVALUE2->Enable();
     608             : 
     609           0 :         m_pLB_WHEREFIELD3->Enable();
     610           0 :         m_pLB_WHERECOND3->Enable();
     611           0 :         m_pLB_WHERECOMP3->Enable();
     612           0 :         m_pET_WHEREVALUE3->Enable();
     613             :     }
     614             : 
     615           0 :     if( LbPos(*m_pLB_WHEREFIELD2) == 0 )
     616             :     {
     617           0 :         m_pLB_WHEREFIELD3->Disable();
     618           0 :         m_pLB_WHERECOND3->Disable();
     619           0 :         m_pLB_WHERECOMP3->Disable();
     620           0 :         m_pET_WHEREVALUE3->Disable();
     621             :     }
     622             :     else
     623             :     {
     624           0 :         m_pLB_WHEREFIELD3->Enable();
     625           0 :         m_pLB_WHERECOND3->Enable();
     626           0 :         m_pLB_WHERECOMP3->Enable();
     627           0 :         m_pET_WHEREVALUE3->Enable();
     628             :     }
     629             : 
     630             :     // comparison field equal to NOENTRY
     631           0 :     if( LbPos(*m_pLB_WHEREFIELD1) == 0 )
     632             :     {
     633           0 :         m_pLB_WHERECOMP1->Disable();
     634           0 :         m_pET_WHEREVALUE1->Disable();
     635             :     }
     636             :     else
     637             :     {
     638           0 :         m_pLB_WHEREFIELD1->Enable();
     639           0 :         m_pLB_WHERECOMP1->Enable();
     640           0 :         m_pET_WHEREVALUE1->Enable();
     641             :     }
     642             : 
     643           0 :     if( LbPos(*m_pLB_WHEREFIELD2) == 0 )
     644             :     {
     645           0 :         m_pLB_WHERECOND2->Disable();
     646           0 :         m_pLB_WHERECOMP2->Disable();
     647           0 :         m_pET_WHEREVALUE2->Disable();
     648             :     }
     649             :     else
     650             :     {
     651           0 :         m_pLB_WHERECOND2->Enable();
     652           0 :         m_pLB_WHEREFIELD2->Enable();
     653           0 :         m_pLB_WHERECOMP2->Enable();
     654           0 :         m_pET_WHEREVALUE2->Enable();
     655             :     }
     656             : 
     657           0 :     if( LbPos(*m_pLB_WHEREFIELD3) == 0 )
     658             :     {
     659           0 :         m_pLB_WHERECOND3->Disable();
     660           0 :         m_pLB_WHERECOMP3->Disable();
     661           0 :         m_pET_WHEREVALUE3->Disable();
     662             :     }
     663             :     else
     664             :     {
     665           0 :         m_pLB_WHERECOND3->Enable();
     666           0 :         m_pLB_WHERECOND3->Enable();
     667           0 :         m_pLB_WHEREFIELD3->Enable();
     668           0 :         m_pLB_WHERECOMP3->Enable();
     669           0 :         m_pET_WHEREVALUE3->Enable();
     670             :     }
     671             : 
     672             :     // comparison operator equal to ISNULL or ISNOTNULL
     673           0 :     if(m_pLB_WHERECOMP1->GetEntryCount() > 2 &&
     674           0 :         ((LbPos(*m_pLB_WHERECOMP1) == m_pLB_WHERECOMP1->GetEntryCount()-1) ||
     675           0 :          (LbPos(*m_pLB_WHERECOMP1) == m_pLB_WHERECOMP1->GetEntryCount()-2)) )
     676           0 :         m_pET_WHEREVALUE1->Disable();
     677             : 
     678           0 :     if(m_pLB_WHERECOMP2->GetEntryCount() > 2 &&
     679           0 :         ((LbPos(*m_pLB_WHERECOMP2) == m_pLB_WHERECOMP2->GetEntryCount()-1) ||
     680           0 :          (LbPos(*m_pLB_WHERECOMP2) == m_pLB_WHERECOMP2->GetEntryCount()-2)) )
     681           0 :         m_pET_WHEREVALUE2->Disable();
     682             : 
     683           0 :     if(m_pLB_WHERECOMP3->GetEntryCount() > 2 &&
     684           0 :         ((LbPos(*m_pLB_WHERECOMP3) == m_pLB_WHERECOMP3->GetEntryCount()-1) ||
     685           0 :          (LbPos(*m_pLB_WHERECOMP3) == m_pLB_WHERECOMP3->GetEntryCount()-2)) )
     686           0 :         m_pET_WHEREVALUE3->Disable();
     687           0 : }
     688             : 
     689           0 : IMPL_LINK( DlgFilterCrit, ListSelectHdl, ListBox *, pListBox )
     690             : {
     691           0 :     OUString aName;
     692             :     ListBox* pComp;
     693           0 :     if(pListBox == m_pLB_WHEREFIELD1)
     694             :     {
     695           0 :         aName = LbText(*m_pLB_WHEREFIELD1);
     696           0 :         pComp = m_pLB_WHERECOMP1;
     697             :     }
     698           0 :     else if(pListBox == m_pLB_WHEREFIELD2)
     699             :     {
     700           0 :         aName = LbText(*m_pLB_WHEREFIELD2);
     701           0 :         pComp = m_pLB_WHERECOMP2;
     702             :     }
     703             :     else
     704             :     {
     705           0 :         aName = LbText(*m_pLB_WHEREFIELD3);
     706           0 :         pComp = m_pLB_WHERECOMP3;
     707             :     }
     708             : 
     709           0 :     pComp->Clear();
     710             : 
     711           0 :     Reference<XPropertySet> xColumn = getColumn(aName);
     712           0 :     if ( xColumn.is() )
     713             :     {
     714           0 :         sal_Int32 nDataType = 0;
     715           0 :         xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
     716           0 :         sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
     717             : 
     718           0 :         if(eColumnSearch  == ColumnSearch::FULL)
     719             :         {
     720           0 :             for(sal_Int32 i=0;i < comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS, ';');i++)
     721           0 :                 pComp->InsertEntry(m_aSTR_COMPARE_OPERATORS.getToken(i, ';'));
     722             :         }
     723           0 :         else if(eColumnSearch == ColumnSearch::CHAR)
     724             :         {
     725           0 :             for(sal_Int32 i=6; i<10; i++)
     726           0 :                 pComp->InsertEntry(m_aSTR_COMPARE_OPERATORS.getToken(i, ';'));
     727             :         }
     728           0 :         else if(eColumnSearch == ColumnSearch::BASIC)
     729             :         {
     730             :             sal_Int32 i;
     731           0 :             for( i = 0; i < 6; i++ )
     732           0 :                 pComp->InsertEntry(m_aSTR_COMPARE_OPERATORS.getToken(i, ';'));
     733           0 :             for(i=8; i < comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS, ';'); ++i)
     734           0 :                 pComp->InsertEntry(m_aSTR_COMPARE_OPERATORS.getToken(i, ';'));
     735             :         }
     736             :         else
     737             :         {
     738             :             OSL_FAIL("DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
     739             :         }
     740             :     }
     741           0 :     pComp->SelectEntryPos(0);
     742             : 
     743           0 :     EnableLines();
     744           0 :     return 0;
     745             : }
     746             : 
     747           0 : IMPL_LINK( DlgFilterCrit, ListSelectCompHdl, ListBox *, /*pListBox*/ )
     748             : {
     749           0 :     EnableLines();
     750           0 :     return 0;
     751             : }
     752             : 
     753           0 : void DlgFilterCrit::BuildWherePart()
     754             : {
     755           0 :     Sequence<Sequence<PropertyValue> > aFilter,aHaving;
     756           0 :     aFilter.realloc(1);
     757           0 :     aHaving.realloc(1);
     758             : 
     759           0 :     if( LbPos(*m_pLB_WHEREFIELD1) != 0 )
     760             :     {
     761           0 :         PropertyValue aValue;
     762           0 :         if ( getCondition(*m_pLB_WHEREFIELD1,*m_pLB_WHERECOMP1,*m_pET_WHEREVALUE1,aValue) )
     763             :         {
     764           0 :             aHaving[0].realloc(1);
     765           0 :             aHaving[0][0] = aValue;
     766             :         }
     767             :         else
     768             :         {
     769           0 :             aFilter[0].realloc(1);
     770           0 :             aFilter[0][0] = aValue;
     771           0 :         }
     772             :     }
     773             : 
     774           0 :     if( LbPos(*m_pLB_WHEREFIELD2) != 0 )
     775             :     {
     776           0 :         PropertyValue aValue;
     777           0 :         Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
     778           0 :         if ( getCondition(*m_pLB_WHEREFIELD2,*m_pLB_WHERECOMP2,*m_pET_WHEREVALUE2,aValue) )
     779           0 :             _rValues = aHaving;
     780           0 :         PropertyValue* pPos = NULL;
     781           0 :         if ( m_pLB_WHERECOND2->GetSelectEntryPos() )
     782             :         {
     783           0 :             sal_Int32 nPos = _rValues.getLength();
     784           0 :             _rValues.realloc( nPos + 1);
     785           0 :             _rValues[nPos].realloc( 1);
     786           0 :             pPos = &_rValues[nPos][0];
     787             :         }
     788             :         else
     789             :         {
     790           0 :             sal_Int32 nPos = _rValues.getLength() - 1;
     791           0 :             sal_Int32 nAndPos = _rValues[nPos].getLength();
     792           0 :             _rValues[nPos].realloc( _rValues[nPos].getLength() + 1);
     793           0 :             pPos = &_rValues[nPos][nAndPos];
     794             :         }
     795           0 :         *pPos = aValue;
     796             :     }
     797             : 
     798           0 :     if( LbPos(*m_pLB_WHEREFIELD3) != 0 )
     799             :     {
     800           0 :         PropertyValue aValue;
     801           0 :         Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
     802           0 :         if ( getCondition(*m_pLB_WHEREFIELD3,*m_pLB_WHERECOMP3,*m_pET_WHEREVALUE3,aValue) )
     803           0 :             _rValues = aHaving;
     804           0 :         PropertyValue* pPos = NULL;
     805           0 :         if ( m_pLB_WHERECOND3->GetSelectEntryPos() )
     806             :         {
     807           0 :             sal_Int32 nPos = _rValues.getLength();
     808           0 :             _rValues.realloc( nPos + 1);
     809           0 :             _rValues[nPos].realloc( 1);
     810           0 :             pPos = &_rValues[nPos][0];
     811             :         }
     812             :         else
     813             :         {
     814           0 :             sal_Int32 nPos = _rValues.getLength() - 1;
     815           0 :             sal_Int32 nAndPos = _rValues[nPos].getLength();
     816           0 :             _rValues[nPos].realloc( _rValues[nPos].getLength() + 1);
     817           0 :             pPos = &_rValues[nPos][nAndPos];
     818             :         }
     819           0 :         *pPos = aValue;
     820             :     }
     821             :     try
     822             :     {
     823           0 :         m_xQueryComposer->setStructuredFilter(aFilter);
     824           0 :         m_xQueryComposer->setStructuredHavingClause(aHaving);
     825             :     }
     826           0 :     catch(const Exception&)
     827             :     {
     828             :         DBG_UNHANDLED_EXCEPTION();
     829           0 :     }
     830           0 : }
     831             : 
     832           0 : void DlgFilterCrit::fillLines(const Sequence<Sequence<PropertyValue > >& _aValues)
     833             : {
     834           0 :     const Sequence<PropertyValue >* pOrIter = _aValues.getConstArray();
     835           0 :     const Sequence<PropertyValue >* pOrEnd   = pOrIter + _aValues.getLength();
     836           0 :     for(sal_uInt16 i=0;pOrIter != pOrEnd; ++pOrIter)
     837             :     {
     838           0 :         bool bOr = true;
     839           0 :         const PropertyValue* pAndIter   = pOrIter->getConstArray();
     840           0 :         const PropertyValue* pAndEnd    = pAndIter + pOrIter->getLength();
     841           0 :         for(;pAndIter != pAndEnd; ++pAndIter)
     842             :         {
     843           0 :             SetLine( i++,*pAndIter,bOr);
     844           0 :             bOr = false;
     845             :         }
     846             :     }
     847          36 : }
     848             : 
     849             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11