1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 "queryfilter.hrc"
39 #include "dbustrings.hrc"
40 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
42 using namespace dbaui
;
43 using namespace connectivity
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::container
;
47 using namespace ::com::sun::star::util
;
48 using namespace ::com::sun::star::sdb
;
49 using namespace ::com::sun::star::sdbc
;
50 using namespace ::com::sun::star::sdbcx
;
51 using namespace ::com::sun::star::beans
;
53 void Replace_OS_PlaceHolder(String
& aString
)
55 while (aString
.SearchAndReplace( '*', '%' ) != STRING_NOTFOUND
) ;
56 while (aString
.SearchAndReplace( '?', '_' ) != STRING_NOTFOUND
) ;
59 void Replace_SQL_PlaceHolder(String
& aString
)
61 while (aString
.SearchAndReplace( '%', '*' ) != STRING_NOTFOUND
) ;
62 while (aString
.SearchAndReplace( '_', '?' ) != STRING_NOTFOUND
) ;
65 DBG_NAME(DlgFilterCrit
);
67 DlgFilterCrit::DlgFilterCrit(Window
* pParent
,
68 const Reference
< XComponentContext
>& rxContext
,
69 const Reference
< XConnection
>& _rxConnection
,
70 const Reference
< XSingleSelectQueryComposer
>& _rxComposer
,
71 const Reference
< XNameAccess
>& _rxCols
73 :ModalDialog( pParent
, ModuleRes( DLG_FILTERCRIT
) )
74 ,aLB_WHEREFIELD1 ( this, ModuleRes( LB_WHEREFIELD1
) )
75 ,aLB_WHERECOMP1 ( this, ModuleRes( LB_WHERECOMP1
) )
76 ,aET_WHEREVALUE1 ( this, ModuleRes( ET_WHEREVALUE1
) )
77 ,aLB_WHERECOND2 ( this, ModuleRes( LB_WHERECOND2
) )
78 ,aLB_WHEREFIELD2 ( this, ModuleRes( LB_WHEREFIELD2
) )
79 ,aLB_WHERECOMP2 ( this, ModuleRes( LB_WHERECOMP2
) )
80 ,aET_WHEREVALUE2 ( this, ModuleRes( ET_WHEREVALUE2
) )
81 ,aLB_WHERECOND3 ( this, ModuleRes( LB_WHERECOND3
) )
82 ,aLB_WHEREFIELD3 ( this, ModuleRes( LB_WHEREFIELD3
) )
83 ,aLB_WHERECOMP3 ( this, ModuleRes( LB_WHERECOMP3
) )
84 ,aET_WHEREVALUE3 ( this, ModuleRes( ET_WHEREVALUE3
) )
85 ,aFT_WHEREFIELD ( this, ModuleRes( FT_WHEREFIELD
) )
86 ,aFT_WHERECOMP ( this, ModuleRes( FT_WHERECOMP
) )
87 ,aFT_WHEREVALUE ( this, ModuleRes( FT_WHEREVALUE
) )
88 ,aFT_WHEREOPER ( this, ModuleRes( FT_WHEREOPER
) )
89 ,aFL_FIELDS ( this, ModuleRes( FL_FIELDS
) )
90 ,aBT_OK ( this, ModuleRes( BT_OK
) )
91 ,aBT_CANCEL ( this, ModuleRes( BT_CANCEL
) )
92 ,aBT_HELP ( this, ModuleRes( BT_HELP
) )
93 ,aSTR_NOENTRY ( ModuleRes( STR_NOENTRY
) )
94 ,aSTR_COMPARE_OPERATORS( ModuleRes( STR_COMPARE_OPERATORS
) )
95 ,m_xQueryComposer(_rxComposer
)
96 ,m_xColumns( _rxCols
)
97 ,m_xConnection( _rxConnection
)
98 ,m_xMetaData( _rxConnection
->getMetaData() )
99 ,m_aPredicateInput( rxContext
, _rxConnection
, getParseContext() )
101 DBG_CTOR(DlgFilterCrit
,NULL
);
102 // Write the String for noEntry into the ListBoxes of the field names
103 aLB_WHEREFIELD1
.InsertEntry( aSTR_NOENTRY
);
104 aLB_WHEREFIELD2
.InsertEntry( aSTR_NOENTRY
);
105 aLB_WHEREFIELD3
.InsertEntry( aSTR_NOENTRY
);
109 // ... also write it into the remaining fields
110 Sequence
< OUString
> aNames
= m_xColumns
->getElementNames();
111 const OUString
* pIter
= aNames
.getConstArray();
112 const OUString
* pEnd
= pIter
+ aNames
.getLength();
113 Reference
<XPropertySet
> xColumn
;
114 for(;pIter
!= pEnd
;++pIter
)
118 xColumn
.set( m_xColumns
->getByName( *pIter
), UNO_QUERY_THROW
);
120 sal_Int32
nDataType( 0 );
121 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_TYPE
) >>= nDataType
);
122 sal_Int32 eColumnSearch
= ::dbtools::getSearchColumnFlag( m_xConnection
, nDataType
);
123 if ( eColumnSearch
== ColumnSearch::NONE
)
126 sal_Bool
bIsSearchable( sal_True
);
127 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_ISSEARCHABLE
) >>= bIsSearchable
);
128 if ( !bIsSearchable
)
131 catch( const Exception
& )
133 DBG_UNHANDLED_EXCEPTION();
135 aLB_WHEREFIELD1
.InsertEntry( *pIter
);
136 aLB_WHEREFIELD2
.InsertEntry( *pIter
);
137 aLB_WHEREFIELD3
.InsertEntry( *pIter
);
140 Reference
<XNameAccess
> xSelectColumns
= Reference
<XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
141 aNames
= xSelectColumns
->getElementNames();
142 pIter
= aNames
.getConstArray();
143 pEnd
= pIter
+ aNames
.getLength();
144 for(;pIter
!= pEnd
;++pIter
)
146 // don't insert a column name twice
147 if ( !m_xColumns
->hasByName(*pIter
) )
149 xColumn
.set(xSelectColumns
->getByName(*pIter
),UNO_QUERY
);
150 OSL_ENSURE(xColumn
.is(),"DlgFilterCrit::DlgFilterCrit: Column is null!");
151 sal_Int32
nDataType(0);
152 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
153 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
155 // !pColumn->IsFunction()
156 if(eColumnSearch
!= ColumnSearch::NONE
)
158 aLB_WHEREFIELD1
.InsertEntry( *pIter
);
159 aLB_WHEREFIELD2
.InsertEntry( *pIter
);
160 aLB_WHEREFIELD3
.InsertEntry( *pIter
);
164 // initialize the listboxes with noEntry
165 aLB_WHEREFIELD1
.SelectEntryPos(0);
166 aLB_WHEREFIELD2
.SelectEntryPos(0);
167 aLB_WHEREFIELD3
.SelectEntryPos(0);
169 // insert the criteria into the dialog
170 Sequence
<Sequence
<PropertyValue
> > aValues
= m_xQueryComposer
->getStructuredFilter();
172 aValues
= m_xQueryComposer
->getStructuredHavingClause();
176 catch(const Exception
&)
184 aLB_WHEREFIELD1
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
185 aLB_WHEREFIELD2
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
186 aLB_WHEREFIELD3
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
188 aLB_WHERECOMP1
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
189 aLB_WHERECOMP2
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
190 aLB_WHERECOMP3
.SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
192 aET_WHEREVALUE1
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
193 aET_WHEREVALUE2
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
194 aET_WHEREVALUE3
.SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
196 if ( aET_WHEREVALUE1
.IsEnabled() )
197 aET_WHEREVALUE1
.GrabFocus();
202 DlgFilterCrit::~DlgFilterCrit()
204 DBG_DTOR(DlgFilterCrit
,NULL
);
207 #define LbText(x) ((x).GetSelectEntry())
208 #define LbPos(x) ((x).GetSelectEntryPos())
210 sal_Int32
DlgFilterCrit::GetOSQLPredicateType( const String
& _rSelectedPredicate
) const
212 sal_Int32 nPredicateIndex
= -1;
213 for ( xub_StrLen i
=0; i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';'); ++i
)
214 if ( aSTR_COMPARE_OPERATORS
.GetToken(i
) == _rSelectedPredicate
)
220 sal_Int32 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
221 switch ( nPredicateIndex
)
224 nPredicateType
= SQLFilterOperator::EQUAL
;
227 nPredicateType
= SQLFilterOperator::NOT_EQUAL
;
230 nPredicateType
= SQLFilterOperator::LESS
;
233 nPredicateType
= SQLFilterOperator::LESS_EQUAL
;
236 nPredicateType
= SQLFilterOperator::GREATER
;
239 nPredicateType
= SQLFilterOperator::GREATER_EQUAL
;
242 nPredicateType
= SQLFilterOperator::LIKE
;
245 nPredicateType
= SQLFilterOperator::NOT_LIKE
;
248 nPredicateType
= SQLFilterOperator::SQLNULL
;
251 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
254 OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
258 return nPredicateType
;
261 sal_uInt16
DlgFilterCrit::GetSelectionPos(sal_Int32 eType
,const ListBox
& rListBox
) const
266 case SQLFilterOperator::EQUAL
:
269 case SQLFilterOperator::NOT_EQUAL
:
272 case SQLFilterOperator::LESS
:
275 case SQLFilterOperator::LESS_EQUAL
:
278 case SQLFilterOperator::GREATER
:
281 case SQLFilterOperator::GREATER_EQUAL
:
284 case SQLFilterOperator::NOT_LIKE
:
285 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-3 : 0;
287 case SQLFilterOperator::LIKE
:
288 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-4 : 1;
290 case SQLFilterOperator::SQLNULL
:
291 nPos
= rListBox
.GetEntryCount()-2;
293 case SQLFilterOperator::NOT_SQLNULL
:
294 nPos
= rListBox
.GetEntryCount()-1;
297 // TODO What value should this be?
304 sal_Bool
DlgFilterCrit::getCondition(const ListBox
& _rField
,const ListBox
& _rComp
,const Edit
& _rValue
,PropertyValue
& _rFilter
) const
306 sal_Bool bHaving
= sal_False
;
310 sal_Bool bFunction
= sal_False
;
311 _rFilter
.Name
= _rField
.GetSelectEntry();
312 Reference
< XPropertySet
> xColumn
= getQueryColumn(_rFilter
.Name
);
315 Reference
< XPropertySetInfo
> xInfo
= xColumn
->getPropertySetInfo();
316 if ( xInfo
->hasPropertyByName(PROPERTY_REALNAME
) )
318 if ( xInfo
->hasPropertyByName(PROPERTY_TABLENAME
) )
320 xColumn
->getPropertyValue(PROPERTY_TABLENAME
) >>= sTableName
;
321 if ( !sTableName
.isEmpty() )
323 // properly quote all parts of the table name, so
324 // e.g. <schema>.<table> becomes "<schema>"."<table>"
325 OUString aCatlog
,aSchema
,aTable
;
326 ::dbtools::qualifiedNameComponents( m_xMetaData
, sTableName
, aCatlog
, aSchema
, aTable
, ::dbtools::eInDataManipulation
);
327 sTableName
= ::dbtools::composeTableName( m_xMetaData
, aCatlog
, aSchema
, aTable
, sal_True
, ::dbtools::eInDataManipulation
);
330 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= _rFilter
.Name
;
331 static OUString
sAgg("AggregateFunction");
332 if ( xInfo
->hasPropertyByName(sAgg
) )
333 xColumn
->getPropertyValue(sAgg
) >>= bHaving
;
334 static OUString
sFunction("Function");
335 if ( xInfo
->hasPropertyByName(sFunction
) )
336 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
340 const OUString aQuote
= m_xMetaData
.is() ? m_xMetaData
->getIdentifierQuoteString() : OUString();
341 _rFilter
.Name
= ::dbtools::quoteName(aQuote
,_rFilter
.Name
);
342 if ( !sTableName
.isEmpty() )
344 static OUString
sSep(".");
346 sTableName
+= _rFilter
.Name
;
347 _rFilter
.Name
= sTableName
;
352 catch(const Exception
&)
356 _rFilter
.Handle
= GetOSQLPredicateType( _rComp
.GetSelectEntry() );
357 if ( SQLFilterOperator::SQLNULL
!= _rFilter
.Handle
&& _rFilter
.Handle
!= SQLFilterOperator::NOT_SQLNULL
)
359 String sPredicateValue
= m_aPredicateInput
.getPredicateValue( _rValue
.GetText(), getMatchingColumn( _rValue
), sal_False
);
360 if ( _rFilter
.Handle
== SQLFilterOperator::LIKE
||
361 _rFilter
.Handle
== SQLFilterOperator::NOT_LIKE
)
362 ::Replace_OS_PlaceHolder( sPredicateValue
);
363 _rFilter
.Value
<<= OUString(sPredicateValue
);
368 Reference
< XPropertySet
> DlgFilterCrit::getColumn( const OUString
& _rFieldName
) const
370 Reference
< XPropertySet
> xColumn
;
373 if ( m_xColumns
.is() && m_xColumns
->hasByName( _rFieldName
) )
374 m_xColumns
->getByName( _rFieldName
) >>= xColumn
;
376 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
377 if ( xColumns
.is() && !xColumn
.is() )
379 Sequence
< OUString
> aSeq
= xColumns
->getElementNames();
380 const OUString
* pIter
= aSeq
.getConstArray();
381 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
382 for(;pIter
!= pEnd
;++pIter
)
384 Reference
<XPropertySet
> xProp(xColumns
->getByName(*pIter
),UNO_QUERY
);
385 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
388 xProp
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
389 if ( sRealName
== _rFieldName
)
391 if ( m_xColumns
.is() && m_xColumns
->hasByName( *pIter
) )
392 m_xColumns
->getByName( *pIter
) >>= xColumn
;
399 catch( const Exception
& )
401 DBG_UNHANDLED_EXCEPTION();
407 Reference
< XPropertySet
> DlgFilterCrit::getQueryColumn( const OUString
& _rFieldName
) const
409 Reference
< XPropertySet
> xColumn
;
412 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
413 if ( xColumns
.is() && xColumns
->hasByName( _rFieldName
) )
414 xColumns
->getByName( _rFieldName
) >>= xColumn
;
416 catch( const Exception
& )
418 DBG_UNHANDLED_EXCEPTION();
424 Reference
< XPropertySet
> DlgFilterCrit::getMatchingColumn( const Edit
& _rValueInput
) const
428 if ( &_rValueInput
== &aET_WHEREVALUE1
)
430 sField
= aLB_WHEREFIELD1
.GetSelectEntry();
432 else if ( &_rValueInput
== &aET_WHEREVALUE2
)
434 sField
= aLB_WHEREFIELD2
.GetSelectEntry();
436 else if ( &_rValueInput
== &aET_WHEREVALUE3
)
438 sField
= aLB_WHEREFIELD3
.GetSelectEntry();
441 OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
445 return getColumn( sField
);
448 IMPL_LINK( DlgFilterCrit
, PredicateLoseFocus
, Edit
*, _pField
)
450 OSL_ENSURE( _pField
, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
453 // retrieve the field affected
454 Reference
< XPropertySet
> xColumn( getMatchingColumn( *_pField
) );
455 // and normalize it's content
458 OUString
sText( _pField
->GetText() );
459 m_aPredicateInput
.normalizePredicateString( sText
, xColumn
);
460 _pField
->SetText( sText
);
467 void DlgFilterCrit::SetLine( sal_uInt16 nIdx
,const PropertyValue
& _rItem
,sal_Bool _bOr
)
469 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
471 _rItem
.Value
>>= aCondition
;
472 String aStr
= aCondition
;
473 if ( _rItem
.Handle
== SQLFilterOperator::LIKE
||
474 _rItem
.Handle
== SQLFilterOperator::NOT_LIKE
)
475 ::Replace_SQL_PlaceHolder(aStr
);
476 aStr
= comphelper::string::stripEnd(aStr
, ' ');
478 Reference
< XPropertySet
> xColumn
= getColumn( _rItem
.Name
);
480 // remove the predicate from the condition
481 switch(_rItem
.Handle
)
483 case SQLFilterOperator::EQUAL
:
486 case SQLFilterOperator::NOT_EQUAL
:
489 case SQLFilterOperator::LESS
:
492 case SQLFilterOperator::LESS_EQUAL
:
495 case SQLFilterOperator::GREATER
:
498 case SQLFilterOperator::GREATER_EQUAL
:
501 case SQLFilterOperator::NOT_LIKE
:
504 case SQLFilterOperator::LIKE
:
507 case SQLFilterOperator::SQLNULL
:
510 case SQLFilterOperator::NOT_SQLNULL
:
514 aStr
= comphelper::string::stripStart(aStr
, ' ');
516 // to make sure that we only set first three
517 ListBox
* pColumnListControl
= NULL
;
518 ListBox
* pPredicateListControl
= NULL
;
519 Edit
* pPredicateValueControl
= NULL
;
523 pColumnListControl
= &aLB_WHEREFIELD1
;
524 pPredicateListControl
= &aLB_WHERECOMP1
;
525 pPredicateValueControl
= &aET_WHEREVALUE1
;
528 aLB_WHERECOND2
.SelectEntryPos( _bOr
? 1 : 0 );
530 pColumnListControl
= &aLB_WHEREFIELD2
;
531 pPredicateListControl
= &aLB_WHERECOMP2
;
532 pPredicateValueControl
= &aET_WHEREVALUE2
;
535 aLB_WHERECOND3
.SelectEntryPos( _bOr
? 1 : 0 );
537 pColumnListControl
= &aLB_WHEREFIELD3
;
538 pPredicateListControl
= &aLB_WHERECOMP3
;
539 pPredicateValueControl
= &aET_WHEREVALUE3
;
543 if ( pColumnListControl
&& pPredicateListControl
&& pPredicateValueControl
)
547 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
550 // select the appropriate field name
551 SelectField( *pColumnListControl
, sName
);
552 ListSelectHdl( pColumnListControl
);
554 // select the appropriate condition
555 pPredicateListControl
->SelectEntryPos( GetSelectionPos( (sal_Int32
)_rItem
.Handle
, *pPredicateListControl
) );
557 // initially normalize this value
558 OUString
aString( aStr
);
559 m_aPredicateInput
.normalizePredicateString( aString
, xColumn
);
560 pPredicateValueControl
->SetText( aString
);
564 void DlgFilterCrit::SelectField( ListBox
& rBox
, const String
& rField
)
566 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
567 sal_uInt16 nCnt
= rBox
.GetEntryCount();
569 for( sal_uInt16 i
=0 ; i
<nCnt
; i
++ )
571 if(rBox
.GetEntry(i
) == rField
)
573 rBox
.SelectEntryPos(i
);
578 rBox
.SelectEntryPos(0);
581 void DlgFilterCrit::EnableLines()
583 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
584 // enabling/disabling of whole lines
585 if( LbPos(aLB_WHEREFIELD1
) == 0 )
587 aLB_WHEREFIELD2
.Disable();
588 aLB_WHERECOND2
.Disable();
589 aLB_WHERECOMP2
.Disable();
590 aET_WHEREVALUE2
.Disable();
592 aLB_WHEREFIELD3
.Disable();
593 aLB_WHERECOND3
.Disable();
594 aLB_WHERECOMP3
.Disable();
595 aET_WHEREVALUE3
.Disable();
599 aLB_WHEREFIELD2
.Enable();
600 aLB_WHERECOND2
.Enable();
601 aLB_WHERECOMP2
.Enable();
602 aET_WHEREVALUE2
.Enable();
604 aLB_WHEREFIELD3
.Enable();
605 aLB_WHERECOND3
.Enable();
606 aLB_WHERECOMP3
.Enable();
607 aET_WHEREVALUE3
.Enable();
610 if( LbPos(aLB_WHEREFIELD2
) == 0 )
612 aLB_WHEREFIELD3
.Disable();
613 aLB_WHERECOND3
.Disable();
614 aLB_WHERECOMP3
.Disable();
615 aET_WHEREVALUE3
.Disable();
619 aLB_WHEREFIELD3
.Enable();
620 aLB_WHERECOND3
.Enable();
621 aLB_WHERECOMP3
.Enable();
622 aET_WHEREVALUE3
.Enable();
625 // comparison field equal to NOENTRY
626 if( LbPos(aLB_WHEREFIELD1
) == 0 )
628 aLB_WHERECOMP1
.Disable();
629 aET_WHEREVALUE1
.Disable();
633 aLB_WHEREFIELD1
.Enable();
634 aLB_WHERECOMP1
.Enable();
635 aET_WHEREVALUE1
.Enable();
638 if( LbPos(aLB_WHEREFIELD2
) == 0 )
640 aLB_WHERECOND2
.Disable();
641 aLB_WHERECOMP2
.Disable();
642 aET_WHEREVALUE2
.Disable();
646 aLB_WHERECOND2
.Enable();
647 aLB_WHEREFIELD2
.Enable();
648 aLB_WHERECOMP2
.Enable();
649 aET_WHEREVALUE2
.Enable();
652 if( LbPos(aLB_WHEREFIELD3
) == 0 )
654 aLB_WHERECOND3
.Disable();
655 aLB_WHERECOMP3
.Disable();
656 aET_WHEREVALUE3
.Disable();
660 aLB_WHERECOND3
.Enable();
661 aLB_WHERECOND3
.Enable();
662 aLB_WHEREFIELD3
.Enable();
663 aLB_WHERECOMP3
.Enable();
664 aET_WHEREVALUE3
.Enable();
667 // comparison operator equal to ISNULL or ISNOTNULL
668 if(aLB_WHERECOMP1
.GetEntryCount() > 2 &&
669 ((LbPos(aLB_WHERECOMP1
) == aLB_WHERECOMP1
.GetEntryCount()-1) ||
670 (LbPos(aLB_WHERECOMP1
) == aLB_WHERECOMP1
.GetEntryCount()-2)) )
671 aET_WHEREVALUE1
.Disable();
673 if(aLB_WHERECOMP2
.GetEntryCount() > 2 &&
674 ((LbPos(aLB_WHERECOMP2
) == aLB_WHERECOMP2
.GetEntryCount()-1) ||
675 (LbPos(aLB_WHERECOMP2
) == aLB_WHERECOMP2
.GetEntryCount()-2)) )
676 aET_WHEREVALUE2
.Disable();
678 if(aLB_WHERECOMP3
.GetEntryCount() > 2 &&
679 ((LbPos(aLB_WHERECOMP3
) == aLB_WHERECOMP3
.GetEntryCount()-1) ||
680 (LbPos(aLB_WHERECOMP3
) == aLB_WHERECOMP3
.GetEntryCount()-2)) )
681 aET_WHEREVALUE3
.Disable();
684 IMPL_LINK( DlgFilterCrit
, ListSelectHdl
, ListBox
*, pListBox
)
688 if(pListBox
== &aLB_WHEREFIELD1
)
690 aName
= LbText(aLB_WHEREFIELD1
);
691 pComp
= &aLB_WHERECOMP1
;
693 else if(pListBox
== &aLB_WHEREFIELD2
)
695 aName
= LbText(aLB_WHEREFIELD2
);
696 pComp
= &aLB_WHERECOMP2
;
700 aName
= LbText(aLB_WHEREFIELD3
);
701 pComp
= &aLB_WHERECOMP3
;
706 Reference
<XPropertySet
> xColumn
= getColumn(aName
);
709 sal_Int32 nDataType
= 0;
710 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
711 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
713 if(eColumnSearch
== ColumnSearch::FULL
)
715 for(xub_StrLen i
=0;i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';');i
++)
716 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
718 else if(eColumnSearch
== ColumnSearch::CHAR
)
720 for(xub_StrLen i
=6;i
<10;i
++)
721 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
723 else if(eColumnSearch
== ColumnSearch::BASIC
)
726 for( i
= 0; i
< 6; i
++ )
727 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
728 for(i
=8; i
< comphelper::string::getTokenCount(aSTR_COMPARE_OPERATORS
, ';'); ++i
)
729 pComp
->InsertEntry(aSTR_COMPARE_OPERATORS
.GetToken(i
));
733 OSL_FAIL("DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
736 pComp
->SelectEntryPos(0);
742 IMPL_LINK_INLINE_START( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, /*pListBox*/ )
747 IMPL_LINK_INLINE_END( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, pListBox
)
749 void DlgFilterCrit::BuildWherePart()
751 DBG_CHKTHIS(DlgFilterCrit
,NULL
);
752 Sequence
<Sequence
<PropertyValue
> > aFilter
,aHaving
;
756 if( LbPos(aLB_WHEREFIELD1
) != 0 )
758 PropertyValue aValue
;
759 if ( getCondition(aLB_WHEREFIELD1
,aLB_WHERECOMP1
,aET_WHEREVALUE1
,aValue
) )
761 aHaving
[0].realloc(1);
762 aHaving
[0][0] = aValue
;
766 aFilter
[0].realloc(1);
767 aFilter
[0][0] = aValue
;
771 if( LbPos(aLB_WHEREFIELD2
) != 0 )
773 PropertyValue aValue
;
774 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
775 if ( getCondition(aLB_WHEREFIELD2
,aLB_WHERECOMP2
,aET_WHEREVALUE2
,aValue
) )
777 PropertyValue
* pPos
= NULL
;
778 if ( aLB_WHERECOND2
.GetSelectEntryPos() )
780 sal_Int32 nPos
= _rValues
.getLength();
781 _rValues
.realloc( nPos
+ 1);
782 _rValues
[nPos
].realloc( 1);
783 pPos
= &_rValues
[nPos
][0];
787 sal_Int32 nPos
= _rValues
.getLength() - 1;
788 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
789 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
790 pPos
= &_rValues
[nPos
][nAndPos
];
795 if( LbPos(aLB_WHEREFIELD3
) != 0 )
797 PropertyValue aValue
;
798 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
799 if ( getCondition(aLB_WHEREFIELD3
,aLB_WHERECOMP3
,aET_WHEREVALUE3
,aValue
) )
801 PropertyValue
* pPos
= NULL
;
802 if ( aLB_WHERECOND3
.GetSelectEntryPos() )
804 sal_Int32 nPos
= _rValues
.getLength();
805 _rValues
.realloc( nPos
+ 1);
806 _rValues
[nPos
].realloc( 1);
807 pPos
= &_rValues
[nPos
][0];
811 sal_Int32 nPos
= _rValues
.getLength() - 1;
812 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
813 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
814 pPos
= &_rValues
[nPos
][nAndPos
];
820 m_xQueryComposer
->setStructuredFilter(aFilter
);
821 m_xQueryComposer
->setStructuredHavingClause(aHaving
);
823 catch(const Exception
&)
825 DBG_UNHANDLED_EXCEPTION();
829 void DlgFilterCrit::fillLines(const Sequence
<Sequence
<PropertyValue
> >& _aValues
)
831 const Sequence
<PropertyValue
>* pOrIter
= _aValues
.getConstArray();
832 const Sequence
<PropertyValue
>* pOrEnd
= pOrIter
+ _aValues
.getLength();
833 sal_Bool bOr
= sal_True
;
834 for(sal_uInt16 i
=0;pOrIter
!= pOrEnd
; ++pOrIter
)
837 const PropertyValue
* pAndIter
= pOrIter
->getConstArray();
838 const PropertyValue
* pAndEnd
= pAndIter
+ pOrIter
->getLength();
839 for(;pAndIter
!= pAndEnd
; ++pAndIter
)
841 SetLine( i
++,*pAndIter
,bOr
);
847 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */