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 <com/sun/star/sdbc/DataType.hpp>
22 #include <com/sun/star/util/Date.hpp>
23 #include <com/sun/star/sdbc/ColumnSearch.hpp>
24 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
26 #include <com/sun/star/sdbc/XConnection.hpp>
27 #include <comphelper/string.hxx>
28 #include <comphelper/diagnose_ex.hxx>
29 #include <osl/diagnose.h>
30 #include <connectivity/dbtools.hxx>
31 #include <strings.hxx>
32 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
34 using namespace dbaui
;
35 using namespace connectivity
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::container
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::sdb
;
41 using namespace ::com::sun::star::sdbc
;
42 using namespace ::com::sun::star::sdbcx
;
43 using namespace ::com::sun::star::beans
;
45 static void Replace_OS_PlaceHolder(OUString
& aString
)
47 aString
= aString
.replaceAll( "*", "%" );
48 aString
= aString
.replaceAll( "?", "_" );
51 static void Replace_SQL_PlaceHolder(OUString
& aString
)
53 aString
= aString
.replaceAll( "%", "*" );
54 aString
= aString
.replaceAll( "_", "?" );
57 DlgFilterCrit::DlgFilterCrit(weld::Window
* pParent
,
58 const Reference
< XComponentContext
>& rxContext
,
59 const Reference
< XConnection
>& _rxConnection
,
60 const Reference
< XSingleSelectQueryComposer
>& _rxComposer
,
61 const Reference
< XNameAccess
>& _rxCols
)
62 : GenericDialogController(pParent
, "dbaccess/ui/queryfilterdialog.ui", "QueryFilterDialog")
63 , m_xQueryComposer(_rxComposer
)
64 , m_xColumns( _rxCols
)
65 , m_xConnection( _rxConnection
)
66 , m_xMetaData( _rxConnection
->getMetaData() )
67 , m_aPredicateInput( rxContext
, _rxConnection
, getParseContext() )
68 , m_xLB_WHEREFIELD1(m_xBuilder
->weld_combo_box("field1"))
69 , m_xLB_WHERECOMP1(m_xBuilder
->weld_combo_box("cond1"))
70 , m_xET_WHEREVALUE1(m_xBuilder
->weld_entry("value1"))
71 , m_xLB_WHERECOND2(m_xBuilder
->weld_combo_box("op2"))
72 , m_xLB_WHEREFIELD2(m_xBuilder
->weld_combo_box("field2"))
73 , m_xLB_WHERECOMP2(m_xBuilder
->weld_combo_box("cond2"))
74 , m_xET_WHEREVALUE2(m_xBuilder
->weld_entry("value2"))
75 , m_xLB_WHERECOND3(m_xBuilder
->weld_combo_box("op3"))
76 , m_xLB_WHEREFIELD3(m_xBuilder
->weld_combo_box("field3"))
77 , m_xLB_WHERECOMP3(m_xBuilder
->weld_combo_box("cond3"))
78 , m_xET_WHEREVALUE3(m_xBuilder
->weld_entry("value3"))
80 //set all condition preferred width to max width
81 //if all entries exist
82 Size
aSize(m_xLB_WHERECOMP1
->get_preferred_size());
83 m_xLB_WHERECOMP1
->set_size_request(aSize
.Width(), -1);
84 m_xLB_WHERECOMP2
->set_size_request(aSize
.Width(), -1);
85 m_xLB_WHERECOMP3
->set_size_request(aSize
.Width(), -1);
86 const sal_Int32 nEntryCount
= m_xLB_WHERECOMP1
->get_count();
87 m_aSTR_COMPARE_OPERATORS
.resize(nEntryCount
);
88 for (sal_Int32 i
= 0; i
< nEntryCount
; ++i
)
90 m_aSTR_COMPARE_OPERATORS
[i
] = m_xLB_WHERECOMP1
->get_text(i
);
92 m_xLB_WHERECOMP1
->clear();
94 // ... also write it into the remaining fields
95 Sequence
< OUString
> aNames
= m_xColumns
->getElementNames();
96 const OUString
* pIter
= aNames
.getConstArray();
97 const OUString
* pEnd
= pIter
+ aNames
.getLength();
98 Reference
<XPropertySet
> xColumn
;
99 for(;pIter
!= pEnd
;++pIter
)
103 xColumn
.set( m_xColumns
->getByName( *pIter
), UNO_QUERY_THROW
);
105 sal_Int32
nDataType( 0 );
106 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_TYPE
) >>= nDataType
);
107 sal_Int32 eColumnSearch
= ::dbtools::getSearchColumnFlag( m_xConnection
, nDataType
);
108 if ( eColumnSearch
== ColumnSearch::NONE
)
111 bool bIsSearchable( true );
112 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_ISSEARCHABLE
) >>= bIsSearchable
);
113 if ( !bIsSearchable
)
116 catch( const Exception
& )
118 DBG_UNHANDLED_EXCEPTION("dbaccess");
120 m_xLB_WHEREFIELD1
->append_text( *pIter
);
121 m_xLB_WHEREFIELD2
->append_text( *pIter
);
122 m_xLB_WHEREFIELD3
->append_text( *pIter
);
125 Reference
<XNameAccess
> xSelectColumns
= Reference
<XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY_THROW
)->getColumns();
126 aNames
= xSelectColumns
->getElementNames();
127 pIter
= aNames
.getConstArray();
128 pEnd
= pIter
+ aNames
.getLength();
129 for(;pIter
!= pEnd
;++pIter
)
131 // don't insert a column name twice
132 if ( !m_xColumns
->hasByName(*pIter
) )
134 xColumn
.set(xSelectColumns
->getByName(*pIter
),UNO_QUERY
);
135 OSL_ENSURE(xColumn
.is(),"DlgFilterCrit::DlgFilterCrit: Column is null!");
136 sal_Int32
nDataType(0);
137 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
138 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
140 // !pColumn->IsFunction()
141 if(eColumnSearch
!= ColumnSearch::NONE
)
143 m_xLB_WHEREFIELD1
->append_text( *pIter
);
144 m_xLB_WHEREFIELD2
->append_text( *pIter
);
145 m_xLB_WHEREFIELD3
->append_text( *pIter
);
149 // initialize the listboxes with noEntry
150 m_xLB_WHEREFIELD1
->set_active(0);
151 m_xLB_WHEREFIELD2
->set_active(0);
152 m_xLB_WHEREFIELD3
->set_active(0);
154 // insert the criteria into the dialog
155 Sequence
<Sequence
<PropertyValue
> > aValues
= m_xQueryComposer
->getStructuredFilter();
157 fillLines(i
, aValues
);
158 aValues
= m_xQueryComposer
->getStructuredHavingClause();
159 fillLines(i
, aValues
);
163 m_xLB_WHEREFIELD1
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectHdl
));
164 m_xLB_WHEREFIELD2
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectHdl
));
165 m_xLB_WHEREFIELD3
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectHdl
));
167 m_xLB_WHERECOMP1
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
168 m_xLB_WHERECOMP2
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
169 m_xLB_WHERECOMP3
->connect_changed(LINK(this,DlgFilterCrit
,ListSelectCompHdl
));
171 m_xET_WHEREVALUE1
->connect_focus_out( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
172 m_xET_WHEREVALUE2
->connect_focus_out( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
173 m_xET_WHEREVALUE3
->connect_focus_out( LINK( this, DlgFilterCrit
, PredicateLoseFocus
) );
175 if (m_xET_WHEREVALUE1
->get_sensitive())
176 m_xET_WHEREVALUE1
->grab_focus();
179 DlgFilterCrit::~DlgFilterCrit()
183 sal_Int32
DlgFilterCrit::GetOSQLPredicateType( std::u16string_view _rSelectedPredicate
) const
185 sal_Int32 nPredicateIndex
= -1;
186 for ( size_t i
=0; i
< m_aSTR_COMPARE_OPERATORS
.size(); ++i
)
187 if ( m_aSTR_COMPARE_OPERATORS
[i
] == _rSelectedPredicate
)
193 sal_Int32 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
194 switch ( nPredicateIndex
)
197 nPredicateType
= SQLFilterOperator::EQUAL
;
200 nPredicateType
= SQLFilterOperator::NOT_EQUAL
;
203 nPredicateType
= SQLFilterOperator::LESS
;
206 nPredicateType
= SQLFilterOperator::LESS_EQUAL
;
209 nPredicateType
= SQLFilterOperator::GREATER
;
212 nPredicateType
= SQLFilterOperator::GREATER_EQUAL
;
215 nPredicateType
= SQLFilterOperator::LIKE
;
218 nPredicateType
= SQLFilterOperator::NOT_LIKE
;
221 nPredicateType
= SQLFilterOperator::SQLNULL
;
224 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
227 OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
231 return nPredicateType
;
234 sal_Int32
DlgFilterCrit::GetSelectionPos(sal_Int32 eType
, const weld::ComboBox
& rListBox
)
239 case SQLFilterOperator::EQUAL
:
242 case SQLFilterOperator::NOT_EQUAL
:
245 case SQLFilterOperator::LESS
:
248 case SQLFilterOperator::LESS_EQUAL
:
251 case SQLFilterOperator::GREATER
:
254 case SQLFilterOperator::GREATER_EQUAL
:
257 case SQLFilterOperator::NOT_LIKE
:
258 nPos
= rListBox
.get_count() > 2 ? rListBox
.get_count()-3 : 0;
260 case SQLFilterOperator::LIKE
:
261 nPos
= rListBox
.get_count() > 2 ? rListBox
.get_count()-4 : 1;
263 case SQLFilterOperator::SQLNULL
:
264 nPos
= rListBox
.get_count()-2;
266 case SQLFilterOperator::NOT_SQLNULL
:
267 nPos
= rListBox
.get_count()-1;
270 // TODO What value should this be?
277 bool DlgFilterCrit::getCondition(const weld::ComboBox
& _rField
,const weld::ComboBox
& _rComp
,const weld::Entry
& _rValue
,PropertyValue
& _rFilter
) const
279 bool bHaving
= false;
282 _rFilter
.Name
= _rField
.get_active_text();
283 Reference
< XPropertySet
> xColumn
= getQueryColumn(_rFilter
.Name
);
286 bool bFunction
= false;
288 Reference
< XPropertySetInfo
> xInfo
= xColumn
->getPropertySetInfo();
289 if ( xInfo
->hasPropertyByName(PROPERTY_REALNAME
) )
291 if ( xInfo
->hasPropertyByName(PROPERTY_TABLENAME
) )
293 xColumn
->getPropertyValue(PROPERTY_TABLENAME
) >>= sTableName
;
294 if ( !sTableName
.isEmpty() )
296 // properly quote all parts of the table name, so
297 // e.g. <schema>.<table> becomes "<schema>"."<table>"
298 OUString aCatalog
,aSchema
,aTable
;
299 ::dbtools::qualifiedNameComponents( m_xMetaData
, sTableName
, aCatalog
, aSchema
, aTable
, ::dbtools::EComposeRule::InDataManipulation
);
300 sTableName
= ::dbtools::composeTableName( m_xMetaData
, aCatalog
, aSchema
, aTable
, true, ::dbtools::EComposeRule::InDataManipulation
);
303 xColumn
->getPropertyValue(PROPERTY_REALNAME
) >>= _rFilter
.Name
;
304 static constexpr OUStringLiteral sAgg
= u
"AggregateFunction";
305 if ( xInfo
->hasPropertyByName(sAgg
) )
306 xColumn
->getPropertyValue(sAgg
) >>= bHaving
;
307 static constexpr OUStringLiteral sFunction
= u
"Function";
308 if ( xInfo
->hasPropertyByName(sFunction
) )
309 xColumn
->getPropertyValue(sFunction
) >>= bFunction
;
313 const OUString aQuote
= m_xMetaData
.is() ? m_xMetaData
->getIdentifierQuoteString() : OUString();
314 _rFilter
.Name
= ::dbtools::quoteName(aQuote
,_rFilter
.Name
);
315 if ( !sTableName
.isEmpty() )
317 sTableName
+= "." + _rFilter
.Name
;
318 _rFilter
.Name
= sTableName
;
323 catch(const Exception
&)
327 _rFilter
.Handle
= GetOSQLPredicateType( _rComp
.get_active_text() );
328 if ( SQLFilterOperator::SQLNULL
!= _rFilter
.Handle
&& _rFilter
.Handle
!= SQLFilterOperator::NOT_SQLNULL
)
330 OUString sPredicateValue
;
331 m_aPredicateInput
.getPredicateValue( _rValue
.get_text(), getMatchingColumn( _rValue
) ) >>= sPredicateValue
;
332 if ( _rFilter
.Handle
== SQLFilterOperator::LIKE
||
333 _rFilter
.Handle
== SQLFilterOperator::NOT_LIKE
)
334 ::Replace_OS_PlaceHolder( sPredicateValue
);
335 _rFilter
.Value
<<= sPredicateValue
;
340 Reference
< XPropertySet
> DlgFilterCrit::getColumn( const OUString
& _rFieldName
) const
342 Reference
< XPropertySet
> xColumn
;
345 if ( m_xColumns
.is() && m_xColumns
->hasByName( _rFieldName
) )
346 m_xColumns
->getByName( _rFieldName
) >>= xColumn
;
348 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY_THROW
)->getColumns();
349 if ( xColumns
.is() && !xColumn
.is() )
351 Sequence
< OUString
> aSeq
= xColumns
->getElementNames();
352 const OUString
* pIter
= aSeq
.getConstArray();
353 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
354 for(;pIter
!= pEnd
;++pIter
)
356 Reference
<XPropertySet
> xProp(xColumns
->getByName(*pIter
),UNO_QUERY
);
357 if ( xProp
.is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
) )
360 xProp
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
361 if ( sRealName
== _rFieldName
)
363 if ( m_xColumns
.is() && m_xColumns
->hasByName( *pIter
) )
364 m_xColumns
->getByName( *pIter
) >>= xColumn
;
371 catch( const Exception
& )
373 DBG_UNHANDLED_EXCEPTION("dbaccess");
379 Reference
< XPropertySet
> DlgFilterCrit::getQueryColumn( const OUString
& _rFieldName
) const
381 Reference
< XPropertySet
> xColumn
;
384 Reference
< XNameAccess
> xColumns
= Reference
< XColumnsSupplier
>(m_xQueryComposer
,UNO_QUERY_THROW
)->getColumns();
385 if ( xColumns
.is() && xColumns
->hasByName( _rFieldName
) )
386 xColumns
->getByName( _rFieldName
) >>= xColumn
;
388 catch( const Exception
& )
390 DBG_UNHANDLED_EXCEPTION("dbaccess");
396 Reference
< XPropertySet
> DlgFilterCrit::getMatchingColumn( const weld::Entry
& _rValueInput
) const
400 if ( &_rValueInput
== m_xET_WHEREVALUE1
.get() )
402 sField
= m_xLB_WHEREFIELD1
->get_active_text();
404 else if ( &_rValueInput
== m_xET_WHEREVALUE2
.get() )
406 sField
= m_xLB_WHEREFIELD2
->get_active_text();
408 else if ( &_rValueInput
== m_xET_WHEREVALUE3
.get() )
410 sField
= m_xLB_WHEREFIELD3
->get_active_text();
413 OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
417 return getColumn( sField
);
420 IMPL_LINK( DlgFilterCrit
, PredicateLoseFocus
, weld::Widget
&, rControl
, void )
422 weld::Entry
& rField
= dynamic_cast<weld::Entry
&>(rControl
);
423 // retrieve the field affected
424 Reference
< XPropertySet
> xColumn(getMatchingColumn(rField
));
425 // and normalize its content
428 OUString
sText(rField
.get_text());
429 m_aPredicateInput
.normalizePredicateString(sText
, xColumn
);
430 rField
.set_text(sText
);
434 void DlgFilterCrit::SetLine( int nIdx
, const PropertyValue
& _rItem
, bool _bOr
)
437 _rItem
.Value
>>= aStr
;
438 if ( _rItem
.Handle
== SQLFilterOperator::LIKE
||
439 _rItem
.Handle
== SQLFilterOperator::NOT_LIKE
)
440 ::Replace_SQL_PlaceHolder(aStr
);
441 aStr
= comphelper::string::stripEnd(aStr
, ' ');
443 Reference
< XPropertySet
> xColumn
= getColumn( _rItem
.Name
);
445 // to make sure that we only set first three
446 weld::ComboBox
* pColumnListControl
= nullptr;
447 weld::ComboBox
* pPredicateListControl
= nullptr;
448 weld::Entry
* pPredicateValueControl
= nullptr;
452 pColumnListControl
= m_xLB_WHEREFIELD1
.get();
453 pPredicateListControl
= m_xLB_WHERECOMP1
.get();
454 pPredicateValueControl
= m_xET_WHEREVALUE1
.get();
457 m_xLB_WHERECOND2
->set_active( _bOr
? 1 : 0 );
459 pColumnListControl
= m_xLB_WHEREFIELD2
.get();
460 pPredicateListControl
= m_xLB_WHERECOMP2
.get();
461 pPredicateValueControl
= m_xET_WHEREVALUE2
.get();
464 m_xLB_WHERECOND3
->set_active( _bOr
? 1 : 0 );
466 pColumnListControl
= m_xLB_WHEREFIELD3
.get();
467 pPredicateListControl
= m_xLB_WHERECOMP3
.get();
468 pPredicateValueControl
= m_xET_WHEREVALUE3
.get();
472 if ( !(pColumnListControl
&& pPredicateListControl
&& pPredicateValueControl
) )
477 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
480 // select the appropriate field name
481 SelectField( *pColumnListControl
, sName
);
482 ListSelectHdl( *pColumnListControl
);
484 // select the appropriate condition
485 pPredicateListControl
->set_active( GetSelectionPos( _rItem
.Handle
, *pPredicateListControl
) );
487 // initially normalize this value
488 OUString
aString( aStr
);
489 m_aPredicateInput
.normalizePredicateString( aString
, xColumn
);
490 pPredicateValueControl
->set_text( aString
);
493 void DlgFilterCrit::SelectField(weld::ComboBox
& rBox
, std::u16string_view rField
)
495 const sal_Int32 nCnt
= rBox
.get_count();
497 for( sal_Int32 i
=0 ; i
<nCnt
; i
++ )
499 if (rBox
.get_text(i
) == rField
)
509 void DlgFilterCrit::EnableLines()
511 // enabling/disabling of whole lines
512 if( m_xLB_WHEREFIELD1
->get_active() == 0 )
514 m_xLB_WHEREFIELD2
->set_sensitive(false);
515 m_xLB_WHERECOND2
->set_sensitive(false);
516 m_xLB_WHERECOMP2
->set_sensitive(false);
517 m_xET_WHEREVALUE2
->set_sensitive(false);
519 m_xLB_WHEREFIELD3
->set_sensitive(false);
520 m_xLB_WHERECOND3
->set_sensitive(false);
521 m_xLB_WHERECOMP3
->set_sensitive(false);
522 m_xET_WHEREVALUE3
->set_sensitive(false);
526 m_xLB_WHEREFIELD2
->set_sensitive(true);
527 m_xLB_WHERECOND2
->set_sensitive(true);
528 m_xLB_WHERECOMP2
->set_sensitive(true);
529 m_xET_WHEREVALUE2
->set_sensitive(true);
531 m_xLB_WHEREFIELD3
->set_sensitive(true);
532 m_xLB_WHERECOND3
->set_sensitive(true);
533 m_xLB_WHERECOMP3
->set_sensitive(true);
534 m_xET_WHEREVALUE3
->set_sensitive(true);
537 if( m_xLB_WHEREFIELD2
->get_active() == 0 )
539 m_xLB_WHEREFIELD3
->set_sensitive(false);
540 m_xLB_WHERECOND3
->set_sensitive(false);
541 m_xLB_WHERECOMP3
->set_sensitive(false);
542 m_xET_WHEREVALUE3
->set_sensitive(false);
546 m_xLB_WHEREFIELD3
->set_sensitive(true);
547 m_xLB_WHERECOND3
->set_sensitive(true);
548 m_xLB_WHERECOMP3
->set_sensitive(true);
549 m_xET_WHEREVALUE3
->set_sensitive(true);
552 // comparison field equal to NOENTRY
553 if( m_xLB_WHEREFIELD1
->get_active() == 0 )
555 m_xLB_WHERECOMP1
->set_sensitive(false);
556 m_xET_WHEREVALUE1
->set_sensitive(false);
560 m_xLB_WHEREFIELD1
->set_sensitive(true);
561 m_xLB_WHERECOMP1
->set_sensitive(true);
562 m_xET_WHEREVALUE1
->set_sensitive(true);
565 if( m_xLB_WHEREFIELD2
->get_active() == 0 )
567 m_xLB_WHERECOND2
->set_sensitive(false);
568 m_xLB_WHERECOMP2
->set_sensitive(false);
569 m_xET_WHEREVALUE2
->set_sensitive(false);
573 m_xLB_WHERECOND2
->set_sensitive(true);
574 m_xLB_WHEREFIELD2
->set_sensitive(true);
575 m_xLB_WHERECOMP2
->set_sensitive(true);
576 m_xET_WHEREVALUE2
->set_sensitive(true);
579 if( m_xLB_WHEREFIELD3
->get_active() == 0 )
581 m_xLB_WHERECOND3
->set_sensitive(false);
582 m_xLB_WHERECOMP3
->set_sensitive(false);
583 m_xET_WHEREVALUE3
->set_sensitive(false);
587 m_xLB_WHERECOND3
->set_sensitive(true);
588 m_xLB_WHERECOND3
->set_sensitive(true);
589 m_xLB_WHEREFIELD3
->set_sensitive(true);
590 m_xLB_WHERECOMP3
->set_sensitive(true);
591 m_xET_WHEREVALUE3
->set_sensitive(true);
594 // comparison operator equal to ISNULL or ISNOTNULL
595 if(m_xLB_WHERECOMP1
->get_count() > 2 &&
596 ((m_xLB_WHERECOMP1
->get_active() == m_xLB_WHERECOMP1
->get_count()-1) ||
597 (m_xLB_WHERECOMP1
->get_active() == m_xLB_WHERECOMP1
->get_count()-2)) )
598 m_xET_WHEREVALUE1
->set_sensitive(false);
600 if(m_xLB_WHERECOMP2
->get_count() > 2 &&
601 ((m_xLB_WHERECOMP2
->get_active() == m_xLB_WHERECOMP2
->get_count()-1) ||
602 (m_xLB_WHERECOMP2
->get_active() == m_xLB_WHERECOMP2
->get_count()-2)) )
603 m_xET_WHEREVALUE2
->set_sensitive(false);
605 if(m_xLB_WHERECOMP3
->get_count() > 2 &&
606 ((m_xLB_WHERECOMP3
->get_active() == m_xLB_WHERECOMP3
->get_count()-1) ||
607 (m_xLB_WHERECOMP3
->get_active() == m_xLB_WHERECOMP3
->get_count()-2)) )
608 m_xET_WHEREVALUE3
->set_sensitive(false);
611 IMPL_LINK( DlgFilterCrit
, ListSelectHdl
, weld::ComboBox
&, rListBox
, void )
614 weld::ComboBox
* pComp
;
615 if(&rListBox
== m_xLB_WHEREFIELD1
.get())
617 aName
= m_xLB_WHEREFIELD1
->get_active_text();
618 pComp
= m_xLB_WHERECOMP1
.get();
620 else if(&rListBox
== m_xLB_WHEREFIELD2
.get())
622 aName
= m_xLB_WHEREFIELD2
->get_active_text();
623 pComp
= m_xLB_WHERECOMP2
.get();
627 aName
= m_xLB_WHEREFIELD3
->get_active_text();
628 pComp
= m_xLB_WHERECOMP3
.get();
633 Reference
<XPropertySet
> xColumn
= getColumn(aName
);
636 sal_Int32 nDataType
= 0;
637 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
638 sal_Int32 eColumnSearch
= dbtools::getSearchColumnFlag(m_xConnection
,nDataType
);
640 if(eColumnSearch
== ColumnSearch::FULL
)
642 for(size_t i
=0;i
< m_aSTR_COMPARE_OPERATORS
.size(); i
++)
643 pComp
->append_text(m_aSTR_COMPARE_OPERATORS
[i
]);
645 else if(eColumnSearch
== ColumnSearch::CHAR
)
647 for(sal_Int32 i
=6; i
<10; i
++)
648 pComp
->append_text(m_aSTR_COMPARE_OPERATORS
[i
]);
650 else if(eColumnSearch
== ColumnSearch::BASIC
)
653 for( i
= 0; i
< 6; i
++ )
654 pComp
->append_text(m_aSTR_COMPARE_OPERATORS
[i
]);
655 for(i
=8; i
< m_aSTR_COMPARE_OPERATORS
.size(); ++i
)
656 pComp
->append_text(m_aSTR_COMPARE_OPERATORS
[i
]);
660 OSL_FAIL("DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
663 pComp
->set_active(0);
668 IMPL_LINK_NOARG(DlgFilterCrit
, ListSelectCompHdl
, weld::ComboBox
&, void)
673 void DlgFilterCrit::BuildWherePart()
675 Sequence
<Sequence
<PropertyValue
> > aFilter(1),aHaving(1);
677 if( m_xLB_WHEREFIELD1
->get_active() != 0 )
679 PropertyValue aValue
;
680 if ( getCondition(*m_xLB_WHEREFIELD1
,*m_xLB_WHERECOMP1
,*m_xET_WHEREVALUE1
,aValue
) )
682 aHaving
= { { aValue
} };
686 aFilter
= { { aValue
} };
690 if( m_xLB_WHEREFIELD2
->get_active() != 0 )
692 PropertyValue aValue
;
693 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
694 if ( getCondition(*m_xLB_WHEREFIELD2
,*m_xLB_WHERECOMP2
,*m_xET_WHEREVALUE2
,aValue
) )
696 if ( m_xLB_WHERECOND2
->get_active() )
697 _rValues
.realloc( _rValues
.getLength() + 1);
698 sal_Int32 nPos
= _rValues
.getLength() - 1;
699 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
700 auto pValues
= _rValues
.getArray();
701 pValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
702 pValues
[nPos
].getArray()[nAndPos
] = aValue
;
705 if( m_xLB_WHEREFIELD3
->get_active() != 0 )
707 PropertyValue aValue
;
708 Sequence
<Sequence
<PropertyValue
> >& _rValues
= aFilter
;
709 if ( getCondition(*m_xLB_WHEREFIELD3
,*m_xLB_WHERECOMP3
,*m_xET_WHEREVALUE3
,aValue
) )
711 if (m_xLB_WHERECOND3
->get_active())
712 _rValues
.realloc( _rValues
.getLength() + 1);
713 sal_Int32 nPos
= _rValues
.getLength() - 1;
714 sal_Int32 nAndPos
= _rValues
[nPos
].getLength();
715 auto pValues
= _rValues
.getArray();
716 pValues
[nPos
].realloc( _rValues
[nPos
].getLength() + 1);
717 pValues
[nPos
].getArray()[nAndPos
] = aValue
;
721 m_xQueryComposer
->setStructuredFilter(aFilter
);
722 m_xQueryComposer
->setStructuredHavingClause(aHaving
);
724 catch(const Exception
&)
726 DBG_UNHANDLED_EXCEPTION("dbaccess");
730 void DlgFilterCrit::fillLines(int &i
, const Sequence
< Sequence
< PropertyValue
> >& _aValues
)
732 const Sequence
<PropertyValue
>* pOrIter
= _aValues
.getConstArray();
733 const Sequence
<PropertyValue
>* pOrEnd
= pOrIter
+ _aValues
.getLength();
734 bool bOr(i
!= 0); // WHERE clause and HAVING clause are always ANDed, nor ORed
735 for(; pOrIter
!= pOrEnd
; ++pOrIter
)
737 const PropertyValue
* pAndIter
= pOrIter
->getConstArray();
738 const PropertyValue
* pAndEnd
= pAndIter
+ pOrIter
->getLength();
739 for(;pAndIter
!= pAndEnd
; ++pAndIter
)
741 SetLine( i
++,*pAndIter
,bOr
);
748 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */