LibreOffice Module dbaccess (master) 1
queryfilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <queryfilter.hxx>
21#include <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>
29#include <osl/diagnose.h>
31#include <strings.hxx>
32#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
33
34using namespace dbaui;
35using namespace connectivity;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::container;
39using namespace ::com::sun::star::util;
40using namespace ::com::sun::star::sdb;
41using namespace ::com::sun::star::sdbc;
42using namespace ::com::sun::star::sdbcx;
43using namespace ::com::sun::star::beans;
44
45static void Replace_OS_PlaceHolder(OUString& aString)
46{
47 aString = aString.replaceAll( "*", "%" );
48 aString = aString.replaceAll( "?", "_" );
49}
50
51static void Replace_SQL_PlaceHolder(OUString& aString)
52{
53 aString = aString.replaceAll( "%", "*" );
54 aString = aString.replaceAll( "_", "?" );
55}
56
57DlgFilterCrit::DlgFilterCrit(weld::Window * pParent,
58 const Reference< XComponentContext >& rxContext,
59 const Reference< XConnection>& _rxConnection,
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"))
79{
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)
89 {
91 }
92 m_xLB_WHERECOMP1->clear();
93
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();
99 for(;pIter != pEnd;++pIter)
100 {
101 try
102 {
103 xColumn.set( m_xColumns->getByName( *pIter ), UNO_QUERY_THROW );
104
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 )
109 continue;
110
111 bool bIsSearchable( true );
112 OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISSEARCHABLE ) >>= bIsSearchable );
113 if ( !bIsSearchable )
114 continue;
115 }
116 catch( const Exception& )
117 {
118 DBG_UNHANDLED_EXCEPTION("dbaccess");
119 }
120 m_xLB_WHEREFIELD1->append_text( *pIter );
121 m_xLB_WHEREFIELD2->append_text( *pIter );
122 m_xLB_WHEREFIELD3->append_text( *pIter );
123 }
124
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)
130 {
131 // don't insert a column name twice
132 if ( !m_xColumns->hasByName(*pIter) )
133 {
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);
139 // TODO
140 // !pColumn->IsFunction()
141 if(eColumnSearch != ColumnSearch::NONE)
142 {
143 m_xLB_WHEREFIELD1->append_text( *pIter );
144 m_xLB_WHEREFIELD2->append_text( *pIter );
145 m_xLB_WHEREFIELD3->append_text( *pIter );
146 }
147 }
148 }
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);
153
154 // insert the criteria into the dialog
155 Sequence<Sequence<PropertyValue > > aValues = m_xQueryComposer->getStructuredFilter();
156 int i(0);
157 fillLines(i, aValues);
158 aValues = m_xQueryComposer->getStructuredHavingClause();
159 fillLines(i, aValues);
160
161 EnableLines();
162
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));
166
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));
170
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 ) );
174
175 if (m_xET_WHEREVALUE1->get_sensitive())
176 m_xET_WHEREVALUE1->grab_focus();
177}
178
180{
181}
182
183sal_Int32 DlgFilterCrit::GetOSQLPredicateType( std::u16string_view _rSelectedPredicate ) const
184{
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 )
188 {
189 nPredicateIndex = i;
190 break;
191 }
192
193 sal_Int32 nPredicateType = SQLFilterOperator::NOT_SQLNULL;
194 switch ( nPredicateIndex )
195 {
196 case 0:
197 nPredicateType = SQLFilterOperator::EQUAL;
198 break;
199 case 1:
200 nPredicateType = SQLFilterOperator::NOT_EQUAL;
201 break;
202 case 2:
203 nPredicateType = SQLFilterOperator::LESS;
204 break;
205 case 3:
206 nPredicateType = SQLFilterOperator::LESS_EQUAL;
207 break;
208 case 4:
209 nPredicateType = SQLFilterOperator::GREATER;
210 break;
211 case 5:
212 nPredicateType = SQLFilterOperator::GREATER_EQUAL;
213 break;
214 case 6:
215 nPredicateType = SQLFilterOperator::LIKE;
216 break;
217 case 7:
218 nPredicateType = SQLFilterOperator::NOT_LIKE;
219 break;
220 case 8:
221 nPredicateType = SQLFilterOperator::SQLNULL;
222 break;
223 case 9:
224 nPredicateType = SQLFilterOperator::NOT_SQLNULL;
225 break;
226 default:
227 OSL_FAIL( "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
228 break;
229 }
230
231 return nPredicateType;
232}
233
234sal_Int32 DlgFilterCrit::GetSelectionPos(sal_Int32 eType, const weld::ComboBox& rListBox)
235{
236 sal_Int32 nPos;
237 switch(eType)
238 {
239 case SQLFilterOperator::EQUAL:
240 nPos = 0;
241 break;
242 case SQLFilterOperator::NOT_EQUAL:
243 nPos = 1;
244 break;
245 case SQLFilterOperator::LESS:
246 nPos = 2;
247 break;
248 case SQLFilterOperator::LESS_EQUAL:
249 nPos = 3;
250 break;
251 case SQLFilterOperator::GREATER:
252 nPos = 4;
253 break;
254 case SQLFilterOperator::GREATER_EQUAL:
255 nPos = 5;
256 break;
257 case SQLFilterOperator::NOT_LIKE:
258 nPos = rListBox.get_count() > 2 ? rListBox.get_count()-3 : 0;
259 break;
260 case SQLFilterOperator::LIKE:
261 nPos = rListBox.get_count() > 2 ? rListBox.get_count()-4 : 1;
262 break;
263 case SQLFilterOperator::SQLNULL:
264 nPos = rListBox.get_count()-2;
265 break;
266 case SQLFilterOperator::NOT_SQLNULL:
267 nPos = rListBox.get_count()-1;
268 break;
269 default:
270 // TODO What value should this be?
271 nPos = 0;
272 break;
273 }
274 return nPos;
275}
276
277bool DlgFilterCrit::getCondition(const weld::ComboBox& _rField,const weld::ComboBox& _rComp,const weld::Entry& _rValue,PropertyValue& _rFilter) const
278{
279 bool bHaving = false;
280 try
281 {
282 _rFilter.Name = _rField.get_active_text();
284 if ( xColumn.is() )
285 {
286 bool bFunction = false;
287 OUString sTableName;
288 Reference< XPropertySetInfo > xInfo = xColumn->getPropertySetInfo();
289 if ( xInfo->hasPropertyByName(PROPERTY_REALNAME) )
290 {
291 if ( xInfo->hasPropertyByName(PROPERTY_TABLENAME) )
292 {
293 xColumn->getPropertyValue(PROPERTY_TABLENAME) >>= sTableName;
294 if ( !sTableName.isEmpty() )
295 {
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 );
301 }
302 }
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;
310 }
311 if ( !bFunction )
312 {
313 const OUString aQuote = m_xMetaData.is() ? m_xMetaData->getIdentifierQuoteString() : OUString();
314 _rFilter.Name = ::dbtools::quoteName(aQuote,_rFilter.Name);
315 if ( !sTableName.isEmpty() )
316 {
317 sTableName += "." + _rFilter.Name;
318 _rFilter.Name = sTableName;
319 }
320 }
321 }
322 }
323 catch(const Exception&)
324 {
325 }
326
327 _rFilter.Handle = GetOSQLPredicateType( _rComp.get_active_text() );
328 if ( SQLFilterOperator::SQLNULL != _rFilter.Handle && _rFilter.Handle != SQLFilterOperator::NOT_SQLNULL )
329 {
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;
336 }
337 return bHaving;
338}
339
340Reference< XPropertySet > DlgFilterCrit::getColumn( const OUString& _rFieldName ) const
341{
343 try
344 {
345 if ( m_xColumns.is() && m_xColumns->hasByName( _rFieldName ) )
346 m_xColumns->getByName( _rFieldName ) >>= xColumn;
347
348 Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY_THROW)->getColumns();
349 if ( xColumns.is() && !xColumn.is() )
350 {
351 Sequence< OUString> aSeq = xColumns->getElementNames();
352 const OUString* pIter = aSeq.getConstArray();
353 const OUString* pEnd = pIter + aSeq.getLength();
354 for(;pIter != pEnd;++pIter)
355 {
356 Reference<XPropertySet> xProp(xColumns->getByName(*pIter),UNO_QUERY);
357 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME) )
358 {
359 OUString sRealName;
360 xProp->getPropertyValue(PROPERTY_REALNAME) >>= sRealName;
361 if ( sRealName == _rFieldName )
362 {
363 if ( m_xColumns.is() && m_xColumns->hasByName( *pIter ) )
364 m_xColumns->getByName( *pIter ) >>= xColumn;
365 break;
366 }
367 }
368 }
369 }
370 }
371 catch( const Exception& )
372 {
373 DBG_UNHANDLED_EXCEPTION("dbaccess");
374 }
375
376 return xColumn;
377}
378
380{
382 try
383 {
384 Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY_THROW)->getColumns();
385 if ( xColumns.is() && xColumns->hasByName( _rFieldName ) )
386 xColumns->getByName( _rFieldName ) >>= xColumn;
387 }
388 catch( const Exception& )
389 {
390 DBG_UNHANDLED_EXCEPTION("dbaccess");
391 }
392
393 return xColumn;
394}
395
397{
398 // the name
399 OUString sField;
400 if ( &_rValueInput == m_xET_WHEREVALUE1.get() )
401 {
402 sField = m_xLB_WHEREFIELD1->get_active_text();
403 }
404 else if ( &_rValueInput == m_xET_WHEREVALUE2.get() )
405 {
406 sField = m_xLB_WHEREFIELD2->get_active_text();
407 }
408 else if ( &_rValueInput == m_xET_WHEREVALUE3.get() )
409 {
410 sField = m_xLB_WHEREFIELD3->get_active_text();
411 }
412 else {
413 OSL_FAIL( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
414 }
415
416 // the field itself
417 return getColumn( sField );
418}
419
420IMPL_LINK( DlgFilterCrit, PredicateLoseFocus, weld::Widget&, rControl, void )
421{
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
426 if ( xColumn.is() )
427 {
428 OUString sText(rField.get_text());
429 m_aPredicateInput.normalizePredicateString(sText, xColumn);
430 rField.set_text(sText);
431 }
432}
433
434void DlgFilterCrit::SetLine( int nIdx, const PropertyValue& _rItem, bool _bOr )
435{
436 OUString aStr;
437 _rItem.Value >>= aStr;
438 if ( _rItem.Handle == SQLFilterOperator::LIKE ||
439 _rItem.Handle == SQLFilterOperator::NOT_LIKE )
442
444
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;
449 switch( nIdx )
450 {
451 case 0:
452 pColumnListControl = m_xLB_WHEREFIELD1.get();
453 pPredicateListControl = m_xLB_WHERECOMP1.get();
454 pPredicateValueControl = m_xET_WHEREVALUE1.get();
455 break;
456 case 1:
457 m_xLB_WHERECOND2->set_active( _bOr ? 1 : 0 );
458
459 pColumnListControl = m_xLB_WHEREFIELD2.get();
460 pPredicateListControl = m_xLB_WHERECOMP2.get();
461 pPredicateValueControl = m_xET_WHEREVALUE2.get();
462 break;
463 case 2:
464 m_xLB_WHERECOND3->set_active( _bOr ? 1 : 0 );
465
466 pColumnListControl = m_xLB_WHEREFIELD3.get();
467 pPredicateListControl = m_xLB_WHERECOMP3.get();
468 pPredicateValueControl = m_xET_WHEREVALUE3.get();
469 break;
470 }
471
472 if ( !(pColumnListControl && pPredicateListControl && pPredicateValueControl) )
473 return;
474
475 OUString sName;
476 if ( xColumn.is() )
477 xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
478 else
479 sName = _rItem.Name;
480 // select the appropriate field name
481 SelectField( *pColumnListControl, sName );
482 ListSelectHdl( *pColumnListControl );
483
484 // select the appropriate condition
485 pPredicateListControl->set_active( GetSelectionPos( _rItem.Handle, *pPredicateListControl ) );
486
487 // initially normalize this value
488 OUString aString( aStr );
490 pPredicateValueControl->set_text( aString );
491}
492
493void DlgFilterCrit::SelectField(weld::ComboBox& rBox, std::u16string_view rField)
494{
495 const sal_Int32 nCnt = rBox.get_count();
496
497 for( sal_Int32 i=0 ; i<nCnt ; i++ )
498 {
499 if (rBox.get_text(i) == rField)
500 {
501 rBox.set_active(i);
502 return;
503 }
504 }
505
506 rBox.set_active(0);
507}
508
510{
511 // enabling/disabling of whole lines
512 if( m_xLB_WHEREFIELD1->get_active() == 0 )
513 {
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);
518
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);
523 }
524 else
525 {
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);
530
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);
535 }
536
537 if( m_xLB_WHEREFIELD2->get_active() == 0 )
538 {
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);
543 }
544 else
545 {
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);
550 }
551
552 // comparison field equal to NOENTRY
553 if( m_xLB_WHEREFIELD1->get_active() == 0 )
554 {
555 m_xLB_WHERECOMP1->set_sensitive(false);
556 m_xET_WHEREVALUE1->set_sensitive(false);
557 }
558 else
559 {
560 m_xLB_WHEREFIELD1->set_sensitive(true);
561 m_xLB_WHERECOMP1->set_sensitive(true);
562 m_xET_WHEREVALUE1->set_sensitive(true);
563 }
564
565 if( m_xLB_WHEREFIELD2->get_active() == 0 )
566 {
567 m_xLB_WHERECOND2->set_sensitive(false);
568 m_xLB_WHERECOMP2->set_sensitive(false);
569 m_xET_WHEREVALUE2->set_sensitive(false);
570 }
571 else
572 {
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);
577 }
578
579 if( m_xLB_WHEREFIELD3->get_active() == 0 )
580 {
581 m_xLB_WHERECOND3->set_sensitive(false);
582 m_xLB_WHERECOMP3->set_sensitive(false);
583 m_xET_WHEREVALUE3->set_sensitive(false);
584 }
585 else
586 {
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);
592 }
593
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);
599
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);
604
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);
609}
610
611IMPL_LINK( DlgFilterCrit, ListSelectHdl, weld::ComboBox&, rListBox, void )
612{
613 OUString aName;
614 weld::ComboBox* pComp;
615 if(&rListBox == m_xLB_WHEREFIELD1.get())
616 {
617 aName = m_xLB_WHEREFIELD1->get_active_text();
618 pComp = m_xLB_WHERECOMP1.get();
619 }
620 else if(&rListBox == m_xLB_WHEREFIELD2.get())
621 {
622 aName = m_xLB_WHEREFIELD2->get_active_text();
623 pComp = m_xLB_WHERECOMP2.get();
624 }
625 else
626 {
627 aName = m_xLB_WHEREFIELD3->get_active_text();
628 pComp = m_xLB_WHERECOMP3.get();
629 }
630
631 pComp->clear();
632
634 if ( xColumn.is() )
635 {
636 sal_Int32 nDataType = 0;
637 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
638 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
639
640 if(eColumnSearch == ColumnSearch::FULL)
641 {
642 for(size_t i=0;i < m_aSTR_COMPARE_OPERATORS.size(); i++)
643 pComp->append_text(m_aSTR_COMPARE_OPERATORS[i]);
644 }
645 else if(eColumnSearch == ColumnSearch::CHAR)
646 {
647 for(sal_Int32 i=6; i<10; i++)
648 pComp->append_text(m_aSTR_COMPARE_OPERATORS[i]);
649 }
650 else if(eColumnSearch == ColumnSearch::BASIC)
651 {
652 size_t i;
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]);
657 }
658 else
659 {
660 OSL_FAIL("DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
661 }
662 }
663 pComp->set_active(0);
664
665 EnableLines();
666}
667
669{
670 EnableLines();
671}
672
674{
675 Sequence<Sequence<PropertyValue> > aFilter(1),aHaving(1);
676
677 if( m_xLB_WHEREFIELD1->get_active() != 0 )
678 {
679 PropertyValue aValue;
681 {
682 aHaving = { { aValue } };
683 }
684 else
685 {
686 aFilter = { { aValue} };
687 }
688 }
689
690 if( m_xLB_WHEREFIELD2->get_active() != 0 )
691 {
692 PropertyValue aValue;
693 Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
695 _rValues = aHaving;
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;
703 }
704
705 if( m_xLB_WHEREFIELD3->get_active() != 0 )
706 {
707 PropertyValue aValue;
708 Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
710 _rValues = aHaving;
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;
718 }
719 try
720 {
721 m_xQueryComposer->setStructuredFilter(aFilter);
722 m_xQueryComposer->setStructuredHavingClause(aHaving);
723 }
724 catch(const Exception&)
725 {
726 DBG_UNHANDLED_EXCEPTION("dbaccess");
727 }
728}
729
731{
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)
736 {
737 const PropertyValue* pAndIter = pOrIter->getConstArray();
738 const PropertyValue* pAndEnd = pAndIter + pOrIter->getLength();
739 for(;pAndIter != pAndEnd; ++pAndIter)
740 {
741 SetLine( i++,*pAndIter,bOr);
742 bOr = false;
743 }
744 bOr=true;
745 }
746}
747
748/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
sal_Int32 nDataType
OptionalString sName
constexpr tools::Long Width() const
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOND3
Definition: queryfilter.hxx:73
static sal_Int32 GetSelectionPos(sal_Int32 eType, const weld::ComboBox &rListBox)
css::uno::Reference< css::beans::XPropertySet > getQueryColumn(const OUString &_rFieldName) const
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOND2
Definition: queryfilter.hxx:68
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: queryfilter.hxx:59
sal_Int32 GetOSQLPredicateType(std::u16string_view _rSelectedPredicate) const
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP3
Definition: queryfilter.hxx:75
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD3
Definition: queryfilter.hxx:74
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xQueryComposer
Definition: queryfilter.hxx:57
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP2
Definition: queryfilter.hxx:70
std::vector< OUString > m_aSTR_COMPARE_OPERATORS
Definition: queryfilter.hxx:55
css::uno::Reference< css::container::XNameAccess > m_xColumns
Definition: queryfilter.hxx:58
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD1
Definition: queryfilter.hxx:64
std::unique_ptr< weld::Entry > m_xET_WHEREVALUE2
Definition: queryfilter.hxx:71
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD2
Definition: queryfilter.hxx:69
std::unique_ptr< weld::Entry > m_xET_WHEREVALUE3
Definition: queryfilter.hxx:76
bool getCondition(const weld::ComboBox &_rField, const weld::ComboBox &_rComp, const weld::Entry &_rValue, css::beans::PropertyValue &_rFilter) const
::dbtools::OPredicateInputController m_aPredicateInput
Definition: queryfilter.hxx:62
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP1
Definition: queryfilter.hxx:65
static void SelectField(weld::ComboBox &rBox, std::u16string_view rField)
css::uno::Reference< css::beans::XPropertySet > getColumn(const OUString &_rFieldName) const
css::uno::Reference< css::beans::XPropertySet > getMatchingColumn(const weld::Entry &_rValueInput) const
void fillLines(int &i, const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > &_aValues)
void SetLine(int nIdx, const css::beans::PropertyValue &_rItem, bool _bOr)
std::unique_ptr< weld::Entry > m_xET_WHEREVALUE1
Definition: queryfilter.hxx:66
virtual ~DlgFilterCrit() override
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: queryfilter.hxx:60
bool normalizePredicateString(OUString &_rPredicateValue, const css::uno::Reference< css::beans::XPropertySet > &_rxField, OUString *_pErrorMessage=nullptr) const
css::uno::Any getPredicateValue(const OUString &_rPredicateValue, const css::uno::Reference< css::beans::XPropertySet > &_rxField) const
virtual OUString get_active_text() const=0
virtual void clear()=0
virtual void set_active(int pos)=0
virtual OUString get_text(int pos) const=0
void append_text(const OUString &rStr)
virtual int get_count() const=0
virtual void set_text(const OUString &rText)=0
virtual OUString get_text() const=0
#define DBG_UNHANDLED_EXCEPTION(...)
float u
Reference< XColumn > xColumn
OUString eType
Definition: generalpage.cxx:78
OUString aName
sal_uInt16 nPos
Sequence< sal_Int8 > aSeq
aStr
double getLength(const B2DPolygon &rCandidate)
B2DTuple getColumn(const B2DHomMatrix &rMatrix, sal_uInt16 nCol)
@ Exception
OString stripEnd(const OString &rIn, char c)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
sal_Int32 getSearchColumnFlag(const Reference< XConnection > &_rxConn, sal_Int32 _nDataType)
int i
Reference< XConnection > m_xConnection
Definition: objectnames.cxx:79
static void Replace_SQL_PlaceHolder(OUString &aString)
Definition: queryfilter.cxx:51
static void Replace_OS_PlaceHolder(OUString &aString)
Definition: queryfilter.cxx:45
constexpr OUStringLiteral PROPERTY_REALNAME(u"RealName")
constexpr OUStringLiteral PROPERTY_ISSEARCHABLE(u"IsSearchable")
constexpr OUStringLiteral PROPERTY_TABLENAME(u"TableName")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")