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 "dbustrings.hrc"
39 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
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
;
52 void Replace_OS_PlaceHolder(OUString
& aString
)
54 aString
= aString
.replaceAll( "*", "%" );
55 aString
= aString
.replaceAll( "?", "_" );
58 void Replace_SQL_PlaceHolder(OUString
& aString
)
60 aString
= aString
.replaceAll( "%", "*" );
61 aString
= aString
.replaceAll( "_", "?" );
65 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
71 : ModalDialog(pParent
, "QueryFilterDialog",
72 "dbaccess/ui/queryfilterdialog.ui")
74 ,m_xQueryComposer(_rxComposer
)
75 ,m_xColumns( _rxCols
)
76 ,m_xConnection( _rxConnection
)
77 ,m_xMetaData( _rxConnection
->getMetaData() )
78 ,m_aPredicateInput( rxContext
, _rxConnection
, getParseContext() )
80 get(m_pLB_WHEREFIELD1
, "field1");
81 get(m_pLB_WHERECOMP1
, "cond1");
82 get(m_pET_WHEREVALUE1
, "value1");
84 get(m_pLB_WHERECOND2
, "op2");
85 get(m_pLB_WHEREFIELD2
, "field2");
86 get(m_pLB_WHERECOMP2
, "cond2");
87 get(m_pET_WHEREVALUE2
, "value2");
89 get(m_pLB_WHERECOND3
, "op3");
90 get(m_pLB_WHEREFIELD3
, "field3");
91 get(m_pLB_WHERECOMP3
, "cond3");
92 get(m_pET_WHEREVALUE3
, "value3");
94 //set all condition preferred width to max width
95 //if all entries exist
96 Size
aSize(m_pLB_WHERECOMP1
->get_preferred_size());
97 m_pLB_WHERECOMP1
->set_width_request(aSize
.Width());
98 m_pLB_WHERECOMP2
->set_width_request(aSize
.Width());
99 m_pLB_WHERECOMP3
->set_width_request(aSize
.Width());
100 sal_uInt16 nEntryCount
= m_pLB_WHERECOMP1
->GetEntryCount();
101 for (sal_uInt16 i
= 0; i
< nEntryCount
; ++i
)
104 m_aSTR_COMPARE_OPERATORS
+= ";";
105 m_aSTR_COMPARE_OPERATORS
+= m_pLB_WHERECOMP1
->GetEntry(i
);
107 m_pLB_WHERECOMP1
->Clear();
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 bool bIsSearchable( true );
127 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_ISSEARCHABLE
) >>= bIsSearchable
);
128 if ( !bIsSearchable
)
131 catch( const Exception
& )
133 DBG_UNHANDLED_EXCEPTION();
135 m_pLB_WHEREFIELD1
->InsertEntry( *pIter
);
136 m_pLB_WHEREFIELD2
->InsertEntry( *pIter
);
137 m_pLB_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 m_pLB_WHEREFIELD1
->InsertEntry( *pIter
);
159 m_pLB_WHEREFIELD2
->InsertEntry( *pIter
);
160 m_pLB_WHEREFIELD3
->InsertEntry( *pIter
);
164 // initialize the listboxes with noEntry
165 m_pLB_WHEREFIELD1
->SelectEntryPos(0);
166 m_pLB_WHEREFIELD2
->SelectEntryPos(0);
167 m_pLB_WHEREFIELD3
->SelectEntryPos(0);
169 // insert the criteria into the dialog
170 Sequence
<Sequence
<PropertyValue
> > aValues
= m_xQueryComposer
->getStructuredFilter();
172 aValues
= m_xQueryComposer
->getStructuredHavingClause();
177 m_pLB_WHEREFIELD1
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
178 m_pLB_WHEREFIELD2
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
179 m_pLB_WHEREFIELD3
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectHdl
));
181 m_pLB_WHERECOMP1
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
182 m_pLB_WHERECOMP2
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
183 m_pLB_WHERECOMP3
->SetSelectHdl(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
185 m_pET_WHEREVALUE1
->SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
186 m_pET_WHEREVALUE2
->SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
187 m_pET_WHEREVALUE3
->SetLoseFocusHdl( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
189 if ( m_pET_WHEREVALUE1
->IsEnabled() )
190 m_pET_WHEREVALUE1
->GrabFocus();
193 DlgFilterCrit::~DlgFilterCrit()
198 void DlgFilterCrit::dispose()
200 m_pLB_WHEREFIELD1
.clear();
201 m_pLB_WHERECOMP1
.clear();
202 m_pET_WHEREVALUE1
.clear();
203 m_pLB_WHERECOND2
.clear();
204 m_pLB_WHEREFIELD2
.clear();
205 m_pLB_WHERECOMP2
.clear();
206 m_pET_WHEREVALUE2
.clear();
207 m_pLB_WHERECOND3
.clear();
208 m_pLB_WHEREFIELD3
.clear();
209 m_pLB_WHERECOMP3
.clear();
210 m_pET_WHEREVALUE3
.clear();
211 ModalDialog::dispose();
214 #define LbText(x) ((x).GetSelectEntry())
215 #define LbPos(x) ((x).GetSelectEntryPos())
217 sal_Int32
DlgFilterCrit::GetOSQLPredicateType( const OUString
& _rSelectedPredicate
) const
219 sal_Int32 nPredicateIndex
= -1;
220 for ( sal_Int32 i
=0; i
< comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS
, ';'); ++i
)
221 if ( m_aSTR_COMPARE_OPERATORS
.getToken(i
, ';') == _rSelectedPredicate
)
227 sal_Int32 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
228 switch ( nPredicateIndex
)
231 nPredicateType
= SQLFilterOperator::EQUAL
;
234 nPredicateType
= SQLFilterOperator::NOT_EQUAL
;
237 nPredicateType
= SQLFilterOperator::LESS
;
240 nPredicateType
= SQLFilterOperator::LESS_EQUAL
;
243 nPredicateType
= SQLFilterOperator::GREATER
;
246 nPredicateType
= SQLFilterOperator::GREATER_EQUAL
;
249 nPredicateType
= SQLFilterOperator::LIKE
;
252 nPredicateType
= SQLFilterOperator::NOT_LIKE
;
255 nPredicateType
= SQLFilterOperator::SQLNULL
;
258 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
261 OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
265 return nPredicateType
;
268 sal_uInt16
DlgFilterCrit::GetSelectionPos(sal_Int32 eType
,const ListBox
& rListBox
)
273 case SQLFilterOperator::EQUAL
:
276 case SQLFilterOperator::NOT_EQUAL
:
279 case SQLFilterOperator::LESS
:
282 case SQLFilterOperator::LESS_EQUAL
:
285 case SQLFilterOperator::GREATER
:
288 case SQLFilterOperator::GREATER_EQUAL
:
291 case SQLFilterOperator::NOT_LIKE
:
292 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-3 : 0;
294 case SQLFilterOperator::LIKE
:
295 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-4 : 1;
297 case SQLFilterOperator::SQLNULL
:
298 nPos
= rListBox
.GetEntryCount()-2;
300 case SQLFilterOperator::NOT_SQLNULL
:
301 nPos
= rListBox
.GetEntryCount()-1;
304 // TODO What value should this be?
311 bool DlgFilterCrit::getCondition(const ListBox
& _rField
,const ListBox
& _rComp
,const Edit
& _rValue
,PropertyValue
& _rFilter
) const
313 bool bHaving
= false;
317 _rFilter
.Name
= _rField
.GetSelectEntry();
318 Reference
< XPropertySet
> xColumn
= getQueryColumn(_rFilter
.Name
);
321 bool bFunction
= false;
322 Reference
< XPropertySetInfo
> xInfo
= xColumn
->getPropertySetInfo();
323 if ( xInfo
->hasPropertyByName(PROPERTY_REALNAME
) )
325 if ( xInfo
->hasPropertyByName(PROPERTY_TABLENAME
) )
327 xColumn
->getPropertyValue(PROPERTY_TABLENAME
) >>= sTableName
;
328 if ( !sTableName
.isEmpty() )
330 // properly quote all parts of the table name, so
331 // e.g. <schema>.<table> becomes "<schema>"."<table>"
332 OUString aCatlog
,aSchema
,aTable
;
333 ::dbtools::qualifiedNameComponents( m_xMetaData
, sTableName
, aCatlog
, aSchema
, aTable
, ::dbtools::eInDataManipulation
);
334 sTableName
= ::dbtools::composeTableName( m_xMetaData
, aCatlog
, aSchema
, aTable
, true, ::dbtools::eInDataManipulation
);
337 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= _rFilter
.Name
;
338 static const char sAgg
[] = "AggregateFunction";
339 if ( xInfo
->hasPropertyByName(sAgg
) )
340 xColumn
->getPropertyValue(sAgg
) >>= bHaving
;
341 static const char sFunction
[] = "Function";
342 if ( xInfo
->hasPropertyByName(sFunction
) )
343 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
347 const OUString aQuote
= m_xMetaData
.is() ? m_xMetaData
->getIdentifierQuoteString() : OUString();
348 _rFilter
.Name
= ::dbtools::quoteName(aQuote
,_rFilter
.Name
);
349 if ( !sTableName
.isEmpty() )
351 static const char sSep
[] = ".";
353 sTableName
+= _rFilter
.Name
;
354 _rFilter
.Name
= sTableName
;
359 catch(const Exception
&)
363 _rFilter
.Handle
= GetOSQLPredicateType( _rComp
.GetSelectEntry() );
364 if ( SQLFilterOperator::SQLNULL
!= _rFilter
.Handle
&& _rFilter
.Handle
!= SQLFilterOperator::NOT_SQLNULL
)
366 OUString sPredicateValue
;
367 m_aPredicateInput
.getPredicateValue( _rValue
.GetText(), getMatchingColumn( _rValue
) ) >>= sPredicateValue
;
368 if ( _rFilter
.Handle
== SQLFilterOperator::LIKE
||
369 _rFilter
.Handle
== SQLFilterOperator::NOT_LIKE
)
370 ::Replace_OS_PlaceHolder( sPredicateValue
);
371 _rFilter
.Value
<<= OUString(sPredicateValue
);
376 Reference
< XPropertySet
> DlgFilterCrit::getColumn( const OUString
& _rFieldName
) const
378 Reference
< XPropertySet
> xColumn
;
381 if ( m_xColumns
.is() && m_xColumns
->hasByName( _rFieldName
) )
382 m_xColumns
->getByName( _rFieldName
) >>= xColumn
;
384 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
385 if ( xColumns
.is() && !xColumn
.is() )
387 Sequence
< OUString
> aSeq
= xColumns
->getElementNames();
388 const OUString
* pIter
= aSeq
.getConstArray();
389 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
390 for(;pIter
!= pEnd
;++pIter
)
392 Reference
<XPropertySet
> xProp(xColumns
->getByName(*pIter
),UNO_QUERY
);
393 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
396 xProp
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
397 if ( sRealName
== _rFieldName
)
399 if ( m_xColumns
.is() && m_xColumns
->hasByName( *pIter
) )
400 m_xColumns
->getByName( *pIter
) >>= xColumn
;
407 catch( const Exception
& )
409 DBG_UNHANDLED_EXCEPTION();
415 Reference
< XPropertySet
> DlgFilterCrit::getQueryColumn( const OUString
& _rFieldName
) const
417 Reference
< XPropertySet
> xColumn
;
420 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY
)->getColumns();
421 if ( xColumns
.is() && xColumns
->hasByName( _rFieldName
) )
422 xColumns
->getByName( _rFieldName
) >>= xColumn
;
424 catch( const Exception
& )
426 DBG_UNHANDLED_EXCEPTION();
432 Reference
< XPropertySet
> DlgFilterCrit::getMatchingColumn( const Edit
& _rValueInput
) const
436 if ( &_rValueInput
== m_pET_WHEREVALUE1
)
438 sField
= m_pLB_WHEREFIELD1
->GetSelectEntry();
440 else if ( &_rValueInput
== m_pET_WHEREVALUE2
)
442 sField
= m_pLB_WHEREFIELD2
->GetSelectEntry();
444 else if ( &_rValueInput
== m_pET_WHEREVALUE3
)
446 sField
= m_pLB_WHEREFIELD3
->GetSelectEntry();
449 OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
453 return getColumn( sField
);
456 IMPL_LINK( DlgFilterCrit
, PredicateLoseFocus
, Edit
*, _pField
)
458 OSL_ENSURE( _pField
, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
461 // retrieve the field affected
462 Reference
< XPropertySet
> xColumn( getMatchingColumn( *_pField
) );
463 // and normalize it's content
466 OUString
sText( _pField
->GetText() );
467 m_aPredicateInput
.normalizePredicateString( sText
, xColumn
);
468 _pField
->SetText( sText
);
475 void DlgFilterCrit::SetLine( sal_uInt16 nIdx
,const PropertyValue
& _rItem
,bool _bOr
)
478 _rItem
.Value
>>= aCondition
;
479 OUString aStr
= aCondition
;
480 if ( _rItem
.Handle
== SQLFilterOperator::LIKE
||
481 _rItem
.Handle
== SQLFilterOperator::NOT_LIKE
)
482 ::Replace_SQL_PlaceHolder(aStr
);
483 aStr
= comphelper::string::stripEnd(aStr
, ' ');
485 Reference
< XPropertySet
> xColumn
= getColumn( _rItem
.Name
);
487 // remove the predicate from the condition
488 switch(_rItem
.Handle
)
490 case SQLFilterOperator::EQUAL
:
493 case SQLFilterOperator::NOT_EQUAL
:
496 case SQLFilterOperator::LESS
:
499 case SQLFilterOperator::LESS_EQUAL
:
502 case SQLFilterOperator::GREATER
:
505 case SQLFilterOperator::GREATER_EQUAL
:
508 case SQLFilterOperator::NOT_LIKE
:
511 case SQLFilterOperator::LIKE
:
514 case SQLFilterOperator::SQLNULL
:
517 case SQLFilterOperator::NOT_SQLNULL
:
518 aStr
= aStr
.copy(11);
521 aStr
= comphelper::string::stripStart(aStr
, ' ');
523 // to make sure that we only set first three
524 ListBox
* pColumnListControl
= NULL
;
525 ListBox
* pPredicateListControl
= NULL
;
526 Edit
* pPredicateValueControl
= NULL
;
530 pColumnListControl
= m_pLB_WHEREFIELD1
;
531 pPredicateListControl
= m_pLB_WHERECOMP1
;
532 pPredicateValueControl
= m_pET_WHEREVALUE1
;
535 m_pLB_WHERECOND2
->SelectEntryPos( _bOr
? 1 : 0 );
537 pColumnListControl
= m_pLB_WHEREFIELD2
;
538 pPredicateListControl
= m_pLB_WHERECOMP2
;
539 pPredicateValueControl
= m_pET_WHEREVALUE2
;
542 m_pLB_WHERECOND3
->SelectEntryPos( _bOr
? 1 : 0 );
544 pColumnListControl
= m_pLB_WHEREFIELD3
;
545 pPredicateListControl
= m_pLB_WHERECOMP3
;
546 pPredicateValueControl
= m_pET_WHEREVALUE3
;
550 if ( pColumnListControl
&& pPredicateListControl
&& pPredicateValueControl
)
554 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
557 // select the appropriate field name
558 SelectField( *pColumnListControl
, sName
);
559 ListSelectHdl( pColumnListControl
);
561 // select the appropriate condition
562 pPredicateListControl
->SelectEntryPos( GetSelectionPos( (sal_Int32
)_rItem
.Handle
, *pPredicateListControl
) );
564 // initially normalize this value
565 OUString
aString( aStr
);
566 m_aPredicateInput
.normalizePredicateString( aString
, xColumn
);
567 pPredicateValueControl
->SetText( aString
);
571 void DlgFilterCrit::SelectField( ListBox
& rBox
, const OUString
& rField
)
573 sal_uInt16 nCnt
= rBox
.GetEntryCount();
575 for( sal_uInt16 i
=0 ; i
<nCnt
; i
++ )
577 if(rBox
.GetEntry(i
) == rField
)
579 rBox
.SelectEntryPos(i
);
584 rBox
.SelectEntryPos(0);
587 void DlgFilterCrit::EnableLines()
589 // enabling/disabling of whole lines
590 if( LbPos(*m_pLB_WHEREFIELD1
) == 0 )
592 m_pLB_WHEREFIELD2
->Disable();
593 m_pLB_WHERECOND2
->Disable();
594 m_pLB_WHERECOMP2
->Disable();
595 m_pET_WHEREVALUE2
->Disable();
597 m_pLB_WHEREFIELD3
->Disable();
598 m_pLB_WHERECOND3
->Disable();
599 m_pLB_WHERECOMP3
->Disable();
600 m_pET_WHEREVALUE3
->Disable();
604 m_pLB_WHEREFIELD2
->Enable();
605 m_pLB_WHERECOND2
->Enable();
606 m_pLB_WHERECOMP2
->Enable();
607 m_pET_WHEREVALUE2
->Enable();
609 m_pLB_WHEREFIELD3
->Enable();
610 m_pLB_WHERECOND3
->Enable();
611 m_pLB_WHERECOMP3
->Enable();
612 m_pET_WHEREVALUE3
->Enable();
615 if( LbPos(*m_pLB_WHEREFIELD2
) == 0 )
617 m_pLB_WHEREFIELD3
->Disable();
618 m_pLB_WHERECOND3
->Disable();
619 m_pLB_WHERECOMP3
->Disable();
620 m_pET_WHEREVALUE3
->Disable();
624 m_pLB_WHEREFIELD3
->Enable();
625 m_pLB_WHERECOND3
->Enable();
626 m_pLB_WHERECOMP3
->Enable();
627 m_pET_WHEREVALUE3
->Enable();
630 // comparison field equal to NOENTRY
631 if( LbPos(*m_pLB_WHEREFIELD1
) == 0 )
633 m_pLB_WHERECOMP1
->Disable();
634 m_pET_WHEREVALUE1
->Disable();
638 m_pLB_WHEREFIELD1
->Enable();
639 m_pLB_WHERECOMP1
->Enable();
640 m_pET_WHEREVALUE1
->Enable();
643 if( LbPos(*m_pLB_WHEREFIELD2
) == 0 )
645 m_pLB_WHERECOND2
->Disable();
646 m_pLB_WHERECOMP2
->Disable();
647 m_pET_WHEREVALUE2
->Disable();
651 m_pLB_WHERECOND2
->Enable();
652 m_pLB_WHEREFIELD2
->Enable();
653 m_pLB_WHERECOMP2
->Enable();
654 m_pET_WHEREVALUE2
->Enable();
657 if( LbPos(*m_pLB_WHEREFIELD3
) == 0 )
659 m_pLB_WHERECOND3
->Disable();
660 m_pLB_WHERECOMP3
->Disable();
661 m_pET_WHEREVALUE3
->Disable();
665 m_pLB_WHERECOND3
->Enable();
666 m_pLB_WHERECOND3
->Enable();
667 m_pLB_WHEREFIELD3
->Enable();
668 m_pLB_WHERECOMP3
->Enable();
669 m_pET_WHEREVALUE3
->Enable();
672 // comparison operator equal to ISNULL or ISNOTNULL
673 if(m_pLB_WHERECOMP1
->GetEntryCount() > 2 &&
674 ((LbPos(*m_pLB_WHERECOMP1
) == m_pLB_WHERECOMP1
->GetEntryCount()-1) ||
675 (LbPos(*m_pLB_WHERECOMP1
) == m_pLB_WHERECOMP1
->GetEntryCount()-2)) )
676 m_pET_WHEREVALUE1
->Disable();
678 if(m_pLB_WHERECOMP2
->GetEntryCount() > 2 &&
679 ((LbPos(*m_pLB_WHERECOMP2
) == m_pLB_WHERECOMP2
->GetEntryCount()-1) ||
680 (LbPos(*m_pLB_WHERECOMP2
) == m_pLB_WHERECOMP2
->GetEntryCount()-2)) )
681 m_pET_WHEREVALUE2
->Disable();
683 if(m_pLB_WHERECOMP3
->GetEntryCount() > 2 &&
684 ((LbPos(*m_pLB_WHERECOMP3
) == m_pLB_WHERECOMP3
->GetEntryCount()-1) ||
685 (LbPos(*m_pLB_WHERECOMP3
) == m_pLB_WHERECOMP3
->GetEntryCount()-2)) )
686 m_pET_WHEREVALUE3
->Disable();
689 IMPL_LINK( DlgFilterCrit
, ListSelectHdl
, ListBox
*, pListBox
)
693 if(pListBox
== m_pLB_WHEREFIELD1
)
695 aName
= LbText(*m_pLB_WHEREFIELD1
);
696 pComp
= m_pLB_WHERECOMP1
;
698 else if(pListBox
== m_pLB_WHEREFIELD2
)
700 aName
= LbText(*m_pLB_WHEREFIELD2
);
701 pComp
= m_pLB_WHERECOMP2
;
705 aName
= LbText(*m_pLB_WHEREFIELD3
);
706 pComp
= m_pLB_WHERECOMP3
;
711 Reference
<XPropertySet
> xColumn
= getColumn(aName
);
714 sal_Int32 nDataType
= 0;
715 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
716 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
718 if(eColumnSearch
== ColumnSearch::FULL
)
720 for(sal_Int32 i
=0;i
< comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS
, ';');i
++)
721 pComp
->InsertEntry(m_aSTR_COMPARE_OPERATORS
.getToken(i
, ';'));
723 else if(eColumnSearch
== ColumnSearch::CHAR
)
725 for(sal_Int32 i
=6; i
<10; i
++)
726 pComp
->InsertEntry(m_aSTR_COMPARE_OPERATORS
.getToken(i
, ';'));
728 else if(eColumnSearch
== ColumnSearch::BASIC
)
731 for( i
= 0; i
< 6; i
++ )
732 pComp
->InsertEntry(m_aSTR_COMPARE_OPERATORS
.getToken(i
, ';'));
733 for(i
=8; i
< comphelper::string::getTokenCount(m_aSTR_COMPARE_OPERATORS
, ';'); ++i
)
734 pComp
->InsertEntry(m_aSTR_COMPARE_OPERATORS
.getToken(i
, ';'));
738 OSL_FAIL("DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
741 pComp
->SelectEntryPos(0);
747 IMPL_LINK( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, /*pListBox*/ )
753 void DlgFilterCrit::BuildWherePart()
755 Sequence
<Sequence
<PropertyValue
> > aFilter
,aHaving
;
759 if( LbPos(*m_pLB_WHEREFIELD1
) != 0 )
761 PropertyValue aValue
;
762 if ( getCondition(*m_pLB_WHEREFIELD1
,*m_pLB_WHERECOMP1
,*m_pET_WHEREVALUE1
,aValue
) )
764 aHaving
[0].realloc(1);
765 aHaving
[0][0] = aValue
;
769 aFilter
[0].realloc(1);
770 aFilter
[0][0] = aValue
;
774 if( LbPos(*m_pLB_WHEREFIELD2
) != 0 )
776 PropertyValue aValue
;
777 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
778 if ( getCondition(*m_pLB_WHEREFIELD2
,*m_pLB_WHERECOMP2
,*m_pET_WHEREVALUE2
,aValue
) )
780 PropertyValue
* pPos
= NULL
;
781 if ( m_pLB_WHERECOND2
->GetSelectEntryPos() )
783 sal_Int32 nPos
= _rValues
.getLength();
784 _rValues
.realloc( nPos
+ 1);
785 _rValues
[nPos
].realloc( 1);
786 pPos
= &_rValues
[nPos
][0];
790 sal_Int32 nPos
= _rValues
.getLength() - 1;
791 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
792 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
793 pPos
= &_rValues
[nPos
][nAndPos
];
798 if( LbPos(*m_pLB_WHEREFIELD3
) != 0 )
800 PropertyValue aValue
;
801 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
802 if ( getCondition(*m_pLB_WHEREFIELD3
,*m_pLB_WHERECOMP3
,*m_pET_WHEREVALUE3
,aValue
) )
804 PropertyValue
* pPos
= NULL
;
805 if ( m_pLB_WHERECOND3
->GetSelectEntryPos() )
807 sal_Int32 nPos
= _rValues
.getLength();
808 _rValues
.realloc( nPos
+ 1);
809 _rValues
[nPos
].realloc( 1);
810 pPos
= &_rValues
[nPos
][0];
814 sal_Int32 nPos
= _rValues
.getLength() - 1;
815 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
816 _rValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
817 pPos
= &_rValues
[nPos
][nAndPos
];
823 m_xQueryComposer
->setStructuredFilter(aFilter
);
824 m_xQueryComposer
->setStructuredHavingClause(aHaving
);
826 catch(const Exception
&)
828 DBG_UNHANDLED_EXCEPTION();
832 void DlgFilterCrit::fillLines(const Sequence
<Sequence
<PropertyValue
> >& _aValues
)
834 const Sequence
<PropertyValue
>* pOrIter
= _aValues
.getConstArray();
835 const Sequence
<PropertyValue
>* pOrEnd
= pOrIter
+ _aValues
.getLength();
836 for(sal_uInt16 i
=0;pOrIter
!= pOrEnd
; ++pOrIter
)
839 const PropertyValue
* pAndIter
= pOrIter
->getConstArray();
840 const PropertyValue
* pAndEnd
= pAndIter
+ pOrIter
->getLength();
841 for(;pAndIter
!= pAndEnd
; ++pAndIter
)
843 SetLine( i
++,*pAndIter
,bOr
);
849 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */