1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "queryfilter.hxx"
31 #include "moduledbu.hxx"
32 #include <com/sun/star/sdbc/DataType.hpp>
33 #include <com/sun/star/util/Date.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <com/sun/star/util/Time.hpp>
36 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
37 #include <com/sun/star/sdbc/ColumnSearch.hpp>
38 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
39 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
40 #include <com/sun/star/sdbc/XRow.hpp>
41 #include <com/sun/star/sdbc/XResultSet.hpp>
42 #include <com/sun/star/container/XNameAccess.hpp>
43 #include <comphelper/string.hxx>
44 #include <tools/diagnose_ex.h>
45 #include <osl/diagnose.h>
46 #include <connectivity/sqliterator.hxx>
47 #include <connectivity/dbtools.hxx>
48 #include "queryfilter.hrc"
49 #include "dbustrings.hrc"
50 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
52 using namespace dbaui
;
53 using namespace connectivity
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::container
;
57 using namespace ::com::sun::star::util
;
58 using namespace ::com::sun::star::sdb
;
59 using namespace ::com::sun::star::sdbc
;
60 using namespace ::com::sun::star::sdbcx
;
61 using namespace ::com::sun::star::sdb
;
62 using namespace ::com::sun::star::beans
;
64 //------------------------------------------------------------------------------
65 void Replace_OS_PlaceHolder(String
& aString
)
67 while (aString
.SearchAndReplace( '*', '%' ) != STRING_NOTFOUND
) ;
68 while (aString
.SearchAndReplace( '?', '_' ) != STRING_NOTFOUND
) ;
71 //------------------------------------------------------------------------------
72 void Replace_SQL_PlaceHolder(String
& aString
)
74 while (aString
.SearchAndReplace( '%', '*' ) != STRING_NOTFOUND
) ;
75 while (aString
.SearchAndReplace( '_', '?' ) != STRING_NOTFOUND
) ;
78 DBG_NAME(DlgFilterCrit
);
79 //------------------------------------------------------------------------------
80 DlgFilterCrit::DlgFilterCrit(Window
* pParent
,
81 const Reference
< XMultiServiceFactory
>& _rxORB
,
82 const Reference
< XConnection
>& _rxConnection
,
83 const Reference
< XSingleSelectQueryComposer
>& _rxComposer
,
84 const Reference
< XNameAccess
>& _rxCols
86 :ModalDialog( pParent
, ModuleRes( DLG_FILTERCRIT
) )
87 ,aLB_WHEREFIELD1 ( this, ModuleRes( LB_WHEREFIELD1
) )
88 ,aLB_WHERECOMP1 ( this, ModuleRes( LB_WHERECOMP1
) )
89 ,aET_WHEREVALUE1 ( this, ModuleRes( ET_WHEREVALUE1
) )
90 ,aLB_WHERECOND2 ( this, ModuleRes( LB_WHERECOND2
) )
91 ,aLB_WHEREFIELD2 ( this, ModuleRes( LB_WHEREFIELD2
) )
92 ,aLB_WHERECOMP2 ( this, ModuleRes( LB_WHERECOMP2
) )
93 ,aET_WHEREVALUE2 ( this, ModuleRes( ET_WHEREVALUE2
) )
94 ,aLB_WHERECOND3 ( this, ModuleRes( LB_WHERECOND3
) )
95 ,aLB_WHEREFIELD3 ( this, ModuleRes( LB_WHEREFIELD3
) )
96 ,aLB_WHERECOMP3 ( this, ModuleRes( LB_WHERECOMP3
) )
97 ,aET_WHEREVALUE3 ( this, ModuleRes( ET_WHEREVALUE3
) )
98 ,aFT_WHEREFIELD ( this, ModuleRes( FT_WHEREFIELD
) )
99 ,aFT_WHERECOMP ( this, ModuleRes( FT_WHERECOMP
) )
100 ,aFT_WHEREVALUE ( this, ModuleRes( FT_WHEREVALUE
) )
101 ,aFT_WHEREOPER ( this, ModuleRes( FT_WHEREOPER
) )
102 ,aFL_FIELDS ( this, ModuleRes( FL_FIELDS
) )
103 ,aBT_OK ( this, ModuleRes( BT_OK
) )
104 ,aBT_CANCEL ( this, ModuleRes( BT_CANCEL
) )
105 ,aBT_HELP ( this, ModuleRes( BT_HELP
) )
106 ,aSTR_NOENTRY ( ModuleRes( STR_NOENTRY
) )
107 ,aSTR_COMPARE_OPERATORS( ModuleRes( STR_COMPARE_OPERATORS
) )
108 ,m_xQueryComposer(_rxComposer
)
109 ,m_xColumns( _rxCols
)
110 ,m_xConnection( _rxConnection
)
111 ,m_xMetaData( _rxConnection
->getMetaData() )
112 ,m_aPredicateInput( _rxORB
, _rxConnection
, getParseContext() )
114 DBG_CTOR(DlgFilterCrit
,NULL
);
115 // Den String fuer noEntry in die ListBoxen der Feldnamen schreiben
116 aLB_WHEREFIELD1
.InsertEntry( aSTR_NOENTRY
);
117 aLB_WHEREFIELD2
.InsertEntry( aSTR_NOENTRY
);
118 aLB_WHEREFIELD3
.InsertEntry( aSTR_NOENTRY
);
122 // ... sowie auch die restlichen Felder
123 Sequence
< ::rtl::OUString
> aNames
= m_xColumns
->getElementNames();
124 const ::rtl::OUString
* pIter
= aNames
.getConstArray();
125 const ::rtl::OUString
* pEnd
= pIter
+ aNames
.getLength();
126 Reference
<XPropertySet
> xColumn
;
127 for(;pIter
!= pEnd
;++pIter
)
131 xColumn
.set( m_xColumns
->getByName( *pIter
), UNO_QUERY_THROW
);
133 sal_Int32
nDataType( 0 );
134 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_TYPE
) >>= nDataType
);
135 sal_Int32 eColumnSearch
= ::dbtools::getSearchColumnFlag( m_xConnection
, nDataType
);
136 if ( eColumnSearch
== ColumnSearch::NONE
)
139 sal_Bool
bIsSearchable( sal_True
);
140 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_ISSEARCHABLE
) >>= bIsSearchable
);
141 if ( !bIsSearchable
)
144 catch( const Exception
& )
146 DBG_UNHANDLED_EXCEPTION();
148 aLB_WHEREFIELD1
.InsertEntry( *pIter
);
149 aLB_WHEREFIELD2
.InsertEntry( *pIter
);
150 aLB_WHEREFIELD3
.InsertEntry( *pIter
);
153 Reference
<XNameAccess
> xSelectColumns
= Reference
<XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
154 aNames
= xSelectColumns
->getElementNames();
155 pIter
= aNames
.getConstArray();
156 pEnd
= pIter
+ aNames
.getLength();
157 for(;pIter
!= pEnd
;++pIter
)
159 // don't insert a column name twice
160 if ( !m_xColumns
->hasByName(*pIter
) )
162 xColumn
.set(xSelectColumns
->getByName(*pIter
),UNO_QUERY
);
163 OSL_ENSURE(xColumn
.is(),"DlgFilterCrit::DlgFilterCrit: Column is null!");
164 sal_Int32
nDataType(0);
165 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
166 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
168 // !pColumn->IsFunction()
169 if(eColumnSearch
!= ColumnSearch::NONE
)
171 aLB_WHEREFIELD1
.InsertEntry( *pIter
);
172 aLB_WHEREFIELD2
.InsertEntry( *pIter
);
173 aLB_WHEREFIELD3
.InsertEntry( *pIter
);
177 // initialize the listboxes with noEntry
178 aLB_WHEREFIELD1
.SelectEntryPos(0);
179 aLB_WHEREFIELD2
.SelectEntryPos(0);
180 aLB_WHEREFIELD3
.SelectEntryPos(0);
182 // insert the criteria into the dialog
183 Sequence
<Sequence
<PropertyValue
> > aValues
= m_xQueryComposer
->getStructuredFilter();
185 aValues
= m_xQueryComposer
->getStructuredHavingClause();
189 catch(const Exception
&)
197 aLB_WHEREFIELD1
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
198 aLB_WHEREFIELD2
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
199 aLB_WHEREFIELD3
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
201 aLB_WHERECOMP1
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
202 aLB_WHERECOMP2
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
203 aLB_WHERECOMP3
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
205 aET_WHEREVALUE1
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
206 aET_WHEREVALUE2
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
207 aET_WHEREVALUE3
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
209 if ( aET_WHEREVALUE1
.IsEnabled() )
210 aET_WHEREVALUE1
.GrabFocus();
214 //------------------------------------------------------------------------------
215 DlgFilterCrit::~DlgFilterCrit()
217 DBG_DTOR(DlgFilterCrit
,NULL
);
220 #define LbText(x) ((x).GetSelectEntry())
221 #define LbPos(x) ((x).GetSelectEntryPos())
223 //------------------------------------------------------------------------------
224 sal_Int32
DlgFilterCrit::GetOSQLPredicateType( const String
& _rSelectedPredicate
) const
226 sal_Int32 nPredicateIndex
= -1;
227 for ( xub_StrLen i
=0; i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';'); ++i
)
228 if ( aSTR_COMPARE_OPERATORS
.GetToken(i
) == _rSelectedPredicate
)
234 sal_Int32 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
235 switch ( nPredicateIndex
)
238 nPredicateType
= SQLFilterOperator::EQUAL
;
241 nPredicateType
= SQLFilterOperator::NOT_EQUAL
;
244 nPredicateType
= SQLFilterOperator::LESS
;
247 nPredicateType
= SQLFilterOperator::LESS_EQUAL
;
250 nPredicateType
= SQLFilterOperator::GREATER
;
253 nPredicateType
= SQLFilterOperator::GREATER_EQUAL
;
256 nPredicateType
= SQLFilterOperator::LIKE
;
259 nPredicateType
= SQLFilterOperator::NOT_LIKE
;
262 nPredicateType
= SQLFilterOperator::SQLNULL
;
265 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
268 OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
272 return nPredicateType
;
274 //------------------------------------------------------------------------------
275 sal_uInt16
DlgFilterCrit::GetSelectionPos(sal_Int32 eType
,const ListBox
& rListBox
) const
280 case SQLFilterOperator::EQUAL
:
283 case SQLFilterOperator::NOT_EQUAL
:
286 case SQLFilterOperator::LESS
:
289 case SQLFilterOperator::LESS_EQUAL
:
292 case SQLFilterOperator::GREATER
:
295 case SQLFilterOperator::GREATER_EQUAL
:
298 case SQLFilterOperator::NOT_LIKE
:
299 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-3 : 0;
301 case SQLFilterOperator::LIKE
:
302 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-4 : 1;
304 case SQLFilterOperator::SQLNULL
:
305 nPos
= rListBox
.GetEntryCount()-2;
307 case SQLFilterOperator::NOT_SQLNULL
:
308 nPos
= rListBox
.GetEntryCount()-1;
311 // TODO What value should this be?
317 // -----------------------------------------------------------------------------
318 sal_Bool
DlgFilterCrit::getCondition(const ListBox
& _rField
,const ListBox
& _rComp
,const Edit
& _rValue
,PropertyValue
& _rFilter
) const
320 sal_Bool bHaving
= sal_False
;
323 ::rtl::OUString sTableName
;
324 sal_Bool bFunction
= sal_False
;
325 _rFilter
.Name
= _rField
.GetSelectEntry();
326 Reference
< XPropertySet
> xColumn
= getQueryColumn(_rFilter
.Name
);
329 Reference
< XPropertySetInfo
> xInfo
= xColumn
->getPropertySetInfo();
330 if ( xInfo
->hasPropertyByName(PROPERTY_REALNAME
) )
332 if ( xInfo
->hasPropertyByName(PROPERTY_TABLENAME
) )
334 xColumn
->getPropertyValue(PROPERTY_TABLENAME
) >>= sTableName
;
335 if ( !sTableName
.isEmpty() )
337 // properly quote all parts of the table name, so e.g. <schema>.<table> becomes "<schema>"."<table>"
338 ::rtl::OUString aCatlog
,aSchema
,aTable
;
339 ::dbtools::qualifiedNameComponents( m_xMetaData
, sTableName
, aCatlog
, aSchema
, aTable
, ::dbtools::eInDataManipulation
);
340 sTableName
= ::dbtools::composeTableName( m_xMetaData
, aCatlog
, aSchema
, aTable
, sal_True
, ::dbtools::eInDataManipulation
);
343 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= _rFilter
.Name
;
344 static ::rtl::OUString
sAgg(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction"));
345 if ( xInfo
->hasPropertyByName(sAgg
) )
346 xColumn
->getPropertyValue(sAgg
) >>= bHaving
;
347 static ::rtl::OUString
sFunction(RTL_CONSTASCII_USTRINGPARAM("Function"));
348 if ( xInfo
->hasPropertyByName(sFunction
) )
349 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
353 const ::rtl::OUString aQuote
= m_xMetaData
.is() ? m_xMetaData
->getIdentifierQuoteString() : ::rtl::OUString();
354 _rFilter
.Name
= ::dbtools::quoteName(aQuote
,_rFilter
.Name
);
355 if ( !sTableName
.isEmpty() )
357 static ::rtl::OUString
sSep(RTL_CONSTASCII_USTRINGPARAM("."));
359 sTableName
+= _rFilter
.Name
;
360 _rFilter
.Name
= sTableName
;
365 catch(const Exception
&)
369 _rFilter
.Handle
= GetOSQLPredicateType( _rComp
.GetSelectEntry() );
370 if ( SQLFilterOperator::SQLNULL
!= _rFilter
.Handle
&& _rFilter
.Handle
!= SQLFilterOperator::NOT_SQLNULL
)
372 String sPredicateValue
= m_aPredicateInput
.getPredicateValue( _rValue
.GetText(), getMatchingColumn( _rValue
), sal_True
);
373 ::Replace_OS_PlaceHolder( sPredicateValue
);
374 _rFilter
.Value
<<= ::rtl::OUString(sPredicateValue
);
379 //------------------------------------------------------------------------------
380 Reference
< XPropertySet
> DlgFilterCrit::getColumn( const ::rtl::OUString
& _rFieldName
) const
382 Reference
< XPropertySet
> xColumn
;
385 if ( m_xColumns
.is() && m_xColumns
->hasByName( _rFieldName
) )
386 m_xColumns
->getByName( _rFieldName
) >>= xColumn
;
388 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
389 if ( xColumns
.is() && !xColumn
.is() )
391 Sequence
< ::rtl::OUString
> aSeq
= xColumns
->getElementNames();
392 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
393 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
394 for(;pIter
!= pEnd
;++pIter
)
396 Reference
<XPropertySet
> xProp(xColumns
->getByName(*pIter
),UNO_QUERY
);
397 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
399 ::rtl::OUString sRealName
;
400 xProp
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
401 if ( sRealName
== _rFieldName
)
403 if ( m_xColumns
.is() && m_xColumns
->hasByName( *pIter
) )
404 m_xColumns
->getByName( *pIter
) >>= xColumn
;
411 catch( const Exception
& )
413 DBG_UNHANDLED_EXCEPTION();
418 //------------------------------------------------------------------------------
419 Reference
< XPropertySet
> DlgFilterCrit::getQueryColumn( const ::rtl::OUString
& _rFieldName
) const
421 Reference
< XPropertySet
> xColumn
;
424 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
425 if ( xColumns
.is() && xColumns
->hasByName( _rFieldName
) )
426 xColumns
->getByName( _rFieldName
) >>= xColumn
;
428 catch( const Exception
& )
430 DBG_UNHANDLED_EXCEPTION();
436 //------------------------------------------------------------------------------
437 Reference
< XPropertySet
> DlgFilterCrit::getMatchingColumn( const Edit
& _rValueInput
) const
440 ::rtl::OUString sField
;
441 if ( &_rValueInput
== &aET_WHEREVALUE1
)
443 sField
= aLB_WHEREFIELD1
.GetSelectEntry();
445 else if ( &_rValueInput
== &aET_WHEREVALUE2
)
447 sField
= aLB_WHEREFIELD2
.GetSelectEntry();
449 else if ( &_rValueInput
== &aET_WHEREVALUE3
)
451 sField
= aLB_WHEREFIELD3
.GetSelectEntry();
454 OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
458 return getColumn( sField
);
461 //------------------------------------------------------------------------------
462 IMPL_LINK( DlgFilterCrit
, PredicateLoseFocus
, Edit
*, _pField
)
464 OSL_ENSURE( _pField
, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
467 // retrieve the field affected
468 Reference
< XPropertySet
> xColumn( getMatchingColumn( *_pField
) );
469 // and normalize it's content
472 ::rtl::OUString
sText( _pField
->GetText() );
473 m_aPredicateInput
.normalizePredicateString( sText
, xColumn
);
474 _pField
->SetText( sText
);
481 //------------------------------------------------------------------------------
482 //------------------------------------------------------------------------------
483 void DlgFilterCrit::SetLine( sal_uInt16 nIdx
,const PropertyValue
& _rItem
,sal_Bool _bOr
)
485 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
486 ::rtl::OUString aCondition
;
487 _rItem
.Value
>>= aCondition
;
488 String aStr
= aCondition
.getStr();
489 ::Replace_SQL_PlaceHolder(aStr
);
490 aStr
.EraseTrailingChars();
492 Reference
< XPropertySet
> xColumn
= getColumn( _rItem
.Name
);
494 // remove the predicate from the condition
495 switch(_rItem
.Handle
)
497 case SQLFilterOperator::EQUAL
:
500 case SQLFilterOperator::NOT_EQUAL
:
503 case SQLFilterOperator::LESS
:
506 case SQLFilterOperator::LESS_EQUAL
:
509 case SQLFilterOperator::GREATER
:
512 case SQLFilterOperator::GREATER_EQUAL
:
515 case SQLFilterOperator::NOT_LIKE
:
518 case SQLFilterOperator::LIKE
:
521 case SQLFilterOperator::SQLNULL
:
524 case SQLFilterOperator::NOT_SQLNULL
:
528 aStr
.EraseLeadingChars();
530 // to make sure that we only set first three
531 ListBox
* pColumnListControl
= NULL
;
532 ListBox
* pPredicateListControl
= NULL
;
533 Edit
* pPredicateValueControl
= NULL
;
537 pColumnListControl
= &aLB_WHEREFIELD1
;
538 pPredicateListControl
= &aLB_WHERECOMP1
;
539 pPredicateValueControl
= &aET_WHEREVALUE1
;
543 aLB_WHERECOND2
.SelectEntryPos( _bOr
? 1 : 0 );
545 pColumnListControl
= &aLB_WHEREFIELD2
;
546 pPredicateListControl
= &aLB_WHERECOMP2
;
547 pPredicateValueControl
= &aET_WHEREVALUE2
;
551 aLB_WHERECOND3
.SelectEntryPos( _bOr
? 1 : 0 );
553 pColumnListControl
= &aLB_WHEREFIELD3
;
554 pPredicateListControl
= &aLB_WHERECOMP3
;
555 pPredicateValueControl
= &aET_WHEREVALUE3
;
559 if ( pColumnListControl
&& pPredicateListControl
&& pPredicateValueControl
)
561 ::rtl::OUString sName
;
563 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
566 // select the appropriate field name
567 SelectField( *pColumnListControl
, sName
);
568 ListSelectHdl( pColumnListControl
);
570 // select the appropriate condition
571 pPredicateListControl
->SelectEntryPos( GetSelectionPos( (sal_Int32
)_rItem
.Handle
, *pPredicateListControl
) );
573 // initially normalize this value
574 ::rtl::OUString
aString( aStr
);
575 m_aPredicateInput
.normalizePredicateString( aString
, xColumn
);
576 pPredicateValueControl
->SetText( aString
);
580 //------------------------------------------------------------------------------
581 void DlgFilterCrit::SelectField( ListBox
& rBox
, const String
& rField
)
583 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
584 sal_uInt16 nCnt
= rBox
.GetEntryCount();
586 for( sal_uInt16 i
=0 ; i
<nCnt
; i
++ )
588 if(rBox
.GetEntry(i
) == rField
)
590 rBox
.SelectEntryPos(i
);
595 rBox
.SelectEntryPos(0);
598 //------------------------------------------------------------------------------
599 void DlgFilterCrit::EnableLines()
601 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
602 // Enablen/Disablen ganzer Zeilen
603 if( LbPos(aLB_WHEREFIELD1
) == 0 )
605 aLB_WHEREFIELD2
.Disable();
606 aLB_WHERECOND2
.Disable();
607 aLB_WHERECOMP2
.Disable();
608 aET_WHEREVALUE2
.Disable();
610 aLB_WHEREFIELD3
.Disable();
611 aLB_WHERECOND3
.Disable();
612 aLB_WHERECOMP3
.Disable();
613 aET_WHEREVALUE3
.Disable();
617 aLB_WHEREFIELD2
.Enable();
618 aLB_WHERECOND2
.Enable();
619 aLB_WHERECOMP2
.Enable();
620 aET_WHEREVALUE2
.Enable();
622 aLB_WHEREFIELD3
.Enable();
623 aLB_WHERECOND3
.Enable();
624 aLB_WHERECOMP3
.Enable();
625 aET_WHEREVALUE3
.Enable();
628 if( LbPos(aLB_WHEREFIELD2
) == 0 )
630 aLB_WHEREFIELD3
.Disable();
631 aLB_WHERECOND3
.Disable();
632 aLB_WHERECOMP3
.Disable();
633 aET_WHEREVALUE3
.Disable();
637 aLB_WHEREFIELD3
.Enable();
638 aLB_WHERECOND3
.Enable();
639 aLB_WHERECOMP3
.Enable();
640 aET_WHEREVALUE3
.Enable();
643 // Vergleichsfeld gleich NOENTRY
644 if( LbPos(aLB_WHEREFIELD1
) == 0 )
646 aLB_WHERECOMP1
.Disable();
647 aET_WHEREVALUE1
.Disable();
651 aLB_WHEREFIELD1
.Enable();
652 aLB_WHERECOMP1
.Enable();
653 aET_WHEREVALUE1
.Enable();
656 if( LbPos(aLB_WHEREFIELD2
) == 0 )
658 aLB_WHERECOND2
.Disable();
659 aLB_WHERECOMP2
.Disable();
660 aET_WHEREVALUE2
.Disable();
664 aLB_WHERECOND2
.Enable();
665 aLB_WHEREFIELD2
.Enable();
666 aLB_WHERECOMP2
.Enable();
667 aET_WHEREVALUE2
.Enable();
670 if( LbPos(aLB_WHEREFIELD3
) == 0 )
672 aLB_WHERECOND3
.Disable();
673 aLB_WHERECOMP3
.Disable();
674 aET_WHEREVALUE3
.Disable();
678 aLB_WHERECOND3
.Enable();
679 aLB_WHERECOND3
.Enable();
680 aLB_WHEREFIELD3
.Enable();
681 aLB_WHERECOMP3
.Enable();
682 aET_WHEREVALUE3
.Enable();
685 // Vergleichsoperator gleich ISNULL oder ISNOTNULL
686 if(aLB_WHERECOMP1
.GetEntryCount() > 2 &&
687 ((LbPos(aLB_WHERECOMP1
) == aLB_WHERECOMP1
.GetEntryCount()-1) ||
688 (LbPos(aLB_WHERECOMP1
) == aLB_WHERECOMP1
.GetEntryCount()-2)) )
689 aET_WHEREVALUE1
.Disable();
691 if(aLB_WHERECOMP2
.GetEntryCount() > 2 &&
692 ((LbPos(aLB_WHERECOMP2
) == aLB_WHERECOMP2
.GetEntryCount()-1) ||
693 (LbPos(aLB_WHERECOMP2
) == aLB_WHERECOMP2
.GetEntryCount()-2)) )
694 aET_WHEREVALUE2
.Disable();
696 if(aLB_WHERECOMP3
.GetEntryCount() > 2 &&
697 ((LbPos(aLB_WHERECOMP3
) == aLB_WHERECOMP3
.GetEntryCount()-1) ||
698 (LbPos(aLB_WHERECOMP3
) == aLB_WHERECOMP3
.GetEntryCount()-2)) )
699 aET_WHEREVALUE3
.Disable();
703 //------------------------------------------------------------------------------
704 IMPL_LINK( DlgFilterCrit
, ListSelectHdl
, ListBox
*, pListBox
)
708 if(pListBox
== &aLB_WHEREFIELD1
)
710 aName
= LbText(aLB_WHEREFIELD1
);
711 pComp
= &aLB_WHERECOMP1
;
713 else if(pListBox
== &aLB_WHEREFIELD2
)
715 aName
= LbText(aLB_WHEREFIELD2
);
716 pComp
= &aLB_WHERECOMP2
;
720 aName
= LbText(aLB_WHEREFIELD3
);
721 pComp
= &aLB_WHERECOMP3
;
726 Reference
<XPropertySet
> xColumn
= getColumn(aName
);
729 sal_Int32 nDataType
= 0;
730 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
731 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
733 if(eColumnSearch
== ColumnSearch::FULL
)
735 for(xub_StrLen i
=0;i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';');i
++)
736 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
738 else if(eColumnSearch
== ColumnSearch::CHAR
)
740 for(xub_StrLen i
=6;i
<10;i
++)
741 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
743 else if(eColumnSearch
== ColumnSearch::BASIC
)
746 for( i
= 0; i
< 6; i
++ )
747 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
748 for(i
=8; i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';'); ++i
)
749 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
753 OSL_FAIL("DlgFilterCrit::ListSelectHdl: Diese Column d�rfte garnicht vorhanden sein!");
756 pComp
->SelectEntryPos(0);
764 //------------------------------------------------------------------------------
765 IMPL_LINK_INLINE_START( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, /*pListBox*/ )
770 IMPL_LINK_INLINE_END( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, pListBox
)
771 //------------------------------------------------------------------------------
772 void DlgFilterCrit::BuildWherePart()
774 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
775 Sequence
<Sequence
<PropertyValue
> > aFilter
,aHaving
;
779 if( LbPos(aLB_WHEREFIELD1
) != 0 )
781 PropertyValue aValue
;
782 if ( getCondition(aLB_WHEREFIELD1
,aLB_WHERECOMP1
,aET_WHEREVALUE1
,aValue
) )
784 aHaving
[0].realloc(1);
785 aHaving
[0][0] = aValue
;
789 aFilter
[0].realloc(1);
790 aFilter
[0][0] = aValue
;
794 if( LbPos(aLB_WHEREFIELD2
) != 0 )
796 PropertyValue aValue
;
797 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
798 if ( getCondition(aLB_WHEREFIELD2
,aLB_WHERECOMP2
,aET_WHEREVALUE2
,aValue
) )
800 PropertyValue
* pPos
= NULL
;
801 if ( aLB_WHERECOND2
.GetSelectEntryPos() )
803 sal_Int32 nPos
= _rValues
.getLength();
804 _rValues
.realloc( nPos
+ 1);
805 _rValues
[nPos
].realloc( 1);
806 pPos
= &_rValues
[nPos
][0];
810 sal_Int32 nPos
= _rValues
.getLength() - 1;
811 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
812 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
813 pPos
= &_rValues
[nPos
][nAndPos
];
818 if( LbPos(aLB_WHEREFIELD3
) != 0 )
820 PropertyValue aValue
;
821 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
822 if ( getCondition(aLB_WHEREFIELD3
,aLB_WHERECOMP3
,aET_WHEREVALUE3
,aValue
) )
824 PropertyValue
* pPos
= NULL
;
825 if ( aLB_WHERECOND3
.GetSelectEntryPos() )
827 sal_Int32 nPos
= _rValues
.getLength();
828 _rValues
.realloc( nPos
+ 1);
829 _rValues
[nPos
].realloc( 1);
830 pPos
= &_rValues
[nPos
][0];
834 sal_Int32 nPos
= _rValues
.getLength() - 1;
835 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
836 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
837 pPos
= &_rValues
[nPos
][nAndPos
];
843 m_xQueryComposer
->setStructuredFilter(aFilter
);
844 m_xQueryComposer
->setStructuredHavingClause(aHaving
);
846 catch(const Exception
&)
848 DBG_UNHANDLED_EXCEPTION();
851 // -----------------------------------------------------------------------------
852 void DlgFilterCrit::fillLines(const Sequence
<Sequence
<PropertyValue
> >& _aValues
)
854 const Sequence
<PropertyValue
>* pOrIter
= _aValues
.getConstArray();
855 const Sequence
<PropertyValue
>* pOrEnd
= pOrIter
+ _aValues
.getLength();
856 sal_Bool bOr
= sal_True
;
857 for(sal_uInt16 i
=0;pOrIter
!= pOrEnd
; ++pOrIter
)
860 const PropertyValue
* pAndIter
= pOrIter
->getConstArray();
861 const PropertyValue
* pAndEnd
= pAndIter
+ pOrIter
->getLength();
862 for(;pAndIter
!= pAndEnd
; ++pAndIter
)
864 SetLine( i
++,*pAndIter
,bOr
);
870 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */