Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / queryfilter.cxx
blob8221f5d19dc78f2ef0054d54a647dbaf4540061c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
31 #ifndef DBAUI_QUERYFILTER_HXX
32 #include "queryfilter.hxx"
33 #endif
34 #ifndef _DBAUI_MODULE_DBU_HXX_
35 #include "moduledbu.hxx"
36 #endif
37 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
38 #include <com/sun/star/sdbc/DataType.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
41 #include <com/sun/star/util/Date.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
44 #include <com/sun/star/util/DateTime.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
47 #include <com/sun/star/util/Time.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
50 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_SDBC_COLUMNSEARCH_HPP_
53 #include <com/sun/star/sdbc/ColumnSearch.hpp>
54 #endif
55 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
56 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_SDB_SQLFILTEROPERATOR_HPP_
59 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
60 #endif
61 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
62 #include <com/sun/star/sdbc/XRow.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
65 #include <com/sun/star/sdbc/XResultSet.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
68 #include <com/sun/star/container/XNameAccess.hpp>
69 #endif
70 #ifndef _TOOLS_DEBUG_HXX
71 #include <tools/debug.hxx>
72 #endif
73 #ifndef TOOLS_DIAGNOSE_EX_H
74 #include <tools/diagnose_ex.h>
75 #endif
76 #ifndef TOOLS_DIAGNOSE_EX_H
77 #include <tools/diagnose_ex.h>
78 #endif
79 #ifndef _DBAUI_MODULE_DBU_HXX_
80 #include "moduledbu.hxx"
81 #endif
82 #ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
83 #include <connectivity/sqliterator.hxx>
84 #endif
85 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
86 #include <connectivity/dbtools.hxx>
87 #endif
88 #ifndef DBAUI_QUERYFILTER_HRC
89 #include "queryfilter.hrc"
90 #endif
91 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
92 #include "dbustrings.hrc"
93 #endif
94 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
95 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
96 #endif
97 #ifndef _COM_SUN_STAR_SDB_SQLFILTEROPERATOR_HPP_
98 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
99 #endif
101 using namespace dbaui;
102 using namespace connectivity;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::lang;
105 using namespace ::com::sun::star::container;
106 using namespace ::com::sun::star::util;
107 using namespace ::com::sun::star::sdb;
108 using namespace ::com::sun::star::sdbc;
109 using namespace ::com::sun::star::sdbcx;
110 using namespace ::com::sun::star::sdb;
111 using namespace ::com::sun::star::beans;
113 //------------------------------------------------------------------------------
114 void Replace_OS_PlaceHolder(String& aString)
116 while (aString.SearchAndReplace( '*', '%' ) != STRING_NOTFOUND) ;
117 while (aString.SearchAndReplace( '?', '_' ) != STRING_NOTFOUND) ;
120 //------------------------------------------------------------------------------
121 void Replace_SQL_PlaceHolder(String& aString)
123 while (aString.SearchAndReplace( '%', '*' ) != STRING_NOTFOUND) ;
124 while (aString.SearchAndReplace( '_', '?' ) != STRING_NOTFOUND) ;
127 DBG_NAME(DlgFilterCrit);
128 //------------------------------------------------------------------------------
129 DlgFilterCrit::DlgFilterCrit(Window * pParent,
130 const Reference< XMultiServiceFactory >& _rxORB,
131 const Reference< XConnection>& _rxConnection,
132 const Reference< XSingleSelectQueryComposer >& _rxComposer,
133 const Reference< XNameAccess>& _rxCols
135 :ModalDialog( pParent, ModuleRes( DLG_FILTERCRIT ) )
136 ,aLB_WHEREFIELD1 ( this, ModuleRes( LB_WHEREFIELD1 ) )
137 ,aLB_WHERECOMP1 ( this, ModuleRes( LB_WHERECOMP1 ) )
138 ,aET_WHEREVALUE1 ( this, ModuleRes( ET_WHEREVALUE1 ) )
139 ,aLB_WHERECOND2 ( this, ModuleRes( LB_WHERECOND2 ) )
140 ,aLB_WHEREFIELD2 ( this, ModuleRes( LB_WHEREFIELD2 ) )
141 ,aLB_WHERECOMP2 ( this, ModuleRes( LB_WHERECOMP2 ) )
142 ,aET_WHEREVALUE2 ( this, ModuleRes( ET_WHEREVALUE2 ) )
143 ,aLB_WHERECOND3 ( this, ModuleRes( LB_WHERECOND3 ) )
144 ,aLB_WHEREFIELD3 ( this, ModuleRes( LB_WHEREFIELD3 ) )
145 ,aLB_WHERECOMP3 ( this, ModuleRes( LB_WHERECOMP3 ) )
146 ,aET_WHEREVALUE3 ( this, ModuleRes( ET_WHEREVALUE3 ) )
147 ,aFT_WHEREFIELD ( this, ModuleRes( FT_WHEREFIELD ) )
148 ,aFT_WHERECOMP ( this, ModuleRes( FT_WHERECOMP ) )
149 ,aFT_WHEREVALUE ( this, ModuleRes( FT_WHEREVALUE ) )
150 ,aFT_WHEREOPER ( this, ModuleRes( FT_WHEREOPER ) )
151 ,aFL_FIELDS ( this, ModuleRes( FL_FIELDS ) )
152 ,aBT_OK ( this, ModuleRes( BT_OK ) )
153 ,aBT_CANCEL ( this, ModuleRes( BT_CANCEL ) )
154 ,aBT_HELP ( this, ModuleRes( BT_HELP ) )
155 ,aSTR_NOENTRY ( ModuleRes( STR_NOENTRY ) )
156 ,aSTR_COMPARE_OPERATORS( ModuleRes( STR_COMPARE_OPERATORS ) )
157 ,m_xQueryComposer(_rxComposer)
158 ,m_xColumns( _rxCols )
159 ,m_xConnection( _rxConnection )
160 ,m_xMetaData( _rxConnection->getMetaData() )
161 ,m_aPredicateInput( _rxORB, _rxConnection, getParseContext() )
163 DBG_CTOR(DlgFilterCrit,NULL);
164 // Den String fuer noEntry in die ListBoxen der Feldnamen schreiben
165 aLB_WHEREFIELD1.InsertEntry( aSTR_NOENTRY );
166 aLB_WHEREFIELD2.InsertEntry( aSTR_NOENTRY );
167 aLB_WHEREFIELD3.InsertEntry( aSTR_NOENTRY );
171 // ... sowie auch die restlichen Felder
172 Sequence< ::rtl::OUString> aNames = m_xColumns->getElementNames();
173 const ::rtl::OUString* pIter = aNames.getConstArray();
174 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
175 Reference<XPropertySet> xColumn;
176 for(;pIter != pEnd;++pIter)
180 xColumn.set( m_xColumns->getByName( *pIter ), UNO_QUERY_THROW );
182 sal_Int32 nDataType( 0 );
183 OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_TYPE ) >>= nDataType );
184 sal_Int32 eColumnSearch = ::dbtools::getSearchColumnFlag( m_xConnection, nDataType );
185 if ( eColumnSearch == ColumnSearch::NONE )
186 continue;
188 sal_Bool bIsSearchable( sal_True );
189 OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISSEARCHABLE ) >>= bIsSearchable );
190 if ( !bIsSearchable )
191 continue;
193 catch( const Exception& )
195 DBG_UNHANDLED_EXCEPTION();
197 aLB_WHEREFIELD1.InsertEntry( *pIter );
198 aLB_WHEREFIELD2.InsertEntry( *pIter );
199 aLB_WHEREFIELD3.InsertEntry( *pIter );
202 Reference<XNameAccess> xSelectColumns = Reference<XColumnsSupplier>(m_xQueryComposer,UNO_QUERY)->getColumns();
203 aNames = xSelectColumns->getElementNames();
204 pIter = aNames.getConstArray();
205 pEnd = pIter + aNames.getLength();
206 for(;pIter != pEnd;++pIter)
208 // don't insert a column name twice
209 if ( !m_xColumns->hasByName(*pIter) )
211 xColumn.set(xSelectColumns->getByName(*pIter),UNO_QUERY);
212 OSL_ENSURE(xColumn.is(),"DlgFilterCrit::DlgFilterCrit: Column is null!");
213 sal_Int32 nDataType(0);
214 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
215 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
216 // TODO
217 // !pColumn->IsFunction()
218 if(eColumnSearch != ColumnSearch::NONE)
220 aLB_WHEREFIELD1.InsertEntry( *pIter );
221 aLB_WHEREFIELD2.InsertEntry( *pIter );
222 aLB_WHEREFIELD3.InsertEntry( *pIter );
226 // initialize the listboxes with noEntry
227 aLB_WHEREFIELD1.SelectEntryPos(0);
228 aLB_WHEREFIELD2.SelectEntryPos(0);
229 aLB_WHEREFIELD3.SelectEntryPos(0);
231 // insert the criteria into the dialog
232 Sequence<Sequence<PropertyValue > > aValues = m_xQueryComposer->getStructuredFilter();
233 fillLines(aValues);
234 aValues = m_xQueryComposer->getStructuredHavingClause();
235 fillLines(aValues);
238 catch(Exception&)
240 FreeResource();
241 throw;
244 EnableLines();
246 aLB_WHEREFIELD1.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
247 aLB_WHEREFIELD2.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
248 aLB_WHEREFIELD3.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectHdl));
250 aLB_WHERECOMP1.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
251 aLB_WHERECOMP2.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
252 aLB_WHERECOMP3.SetSelectHdl(LINK(this,DlgFilterCrit,ListSelectCompHdl));
254 aET_WHEREVALUE1.SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
255 aET_WHEREVALUE2.SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
256 aET_WHEREVALUE3.SetLoseFocusHdl( LINK( this, DlgFilterCrit, PredicateLoseFocus ) );
258 if ( aET_WHEREVALUE1.IsEnabled() )
259 aET_WHEREVALUE1.GrabFocus();
261 FreeResource();
263 //------------------------------------------------------------------------------
264 DlgFilterCrit::~DlgFilterCrit()
266 DBG_DTOR(DlgFilterCrit,NULL);
269 #define LbText(x) ((x).GetSelectEntry())
270 #define LbPos(x) ((x).GetSelectEntryPos())
272 //------------------------------------------------------------------------------
273 sal_Int32 DlgFilterCrit::GetOSQLPredicateType( const String& _rSelectedPredicate ) const
275 sal_Int32 nPredicateIndex = -1;
276 for ( xub_StrLen i=0; i<aSTR_COMPARE_OPERATORS.GetTokenCount(); ++i)
277 if ( aSTR_COMPARE_OPERATORS.GetToken(i) == _rSelectedPredicate )
279 nPredicateIndex = i;
280 break;
283 sal_Int32 nPredicateType = SQLFilterOperator::NOT_SQLNULL;
284 switch ( nPredicateIndex )
286 case 0:
287 nPredicateType = SQLFilterOperator::EQUAL;
288 break;
289 case 1:
290 nPredicateType = SQLFilterOperator::NOT_EQUAL;
291 break;
292 case 2:
293 nPredicateType = SQLFilterOperator::LESS;
294 break;
295 case 3:
296 nPredicateType = SQLFilterOperator::LESS_EQUAL;
297 break;
298 case 4:
299 nPredicateType = SQLFilterOperator::GREATER;
300 break;
301 case 5:
302 nPredicateType = SQLFilterOperator::GREATER_EQUAL;
303 break;
304 case 6:
305 nPredicateType = SQLFilterOperator::LIKE;
306 break;
307 case 7:
308 nPredicateType = SQLFilterOperator::NOT_LIKE;
309 break;
310 case 8:
311 nPredicateType = SQLFilterOperator::SQLNULL;
312 break;
313 case 9:
314 nPredicateType = SQLFilterOperator::NOT_SQLNULL;
315 break;
316 default:
317 OSL_ENSURE( false, "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
318 break;
321 return nPredicateType;
323 //------------------------------------------------------------------------------
324 sal_uInt16 DlgFilterCrit::GetSelectionPos(sal_Int32 eType,const ListBox& rListBox) const
326 sal_uInt16 nPos;
327 switch(eType)
329 case SQLFilterOperator::EQUAL:
330 nPos = 0;
331 break;
332 case SQLFilterOperator::NOT_EQUAL:
333 nPos = 1;
334 break;
335 case SQLFilterOperator::LESS:
336 nPos = 2;
337 break;
338 case SQLFilterOperator::LESS_EQUAL:
339 nPos = 3;
340 break;
341 case SQLFilterOperator::GREATER:
342 nPos = 4;
343 break;
344 case SQLFilterOperator::GREATER_EQUAL:
345 nPos = 5;
346 break;
347 case SQLFilterOperator::NOT_LIKE:
348 nPos = rListBox.GetEntryCount() > 2 ? rListBox.GetEntryCount()-3 : 0;
349 break;
350 case SQLFilterOperator::LIKE:
351 nPos = rListBox.GetEntryCount() > 2 ? rListBox.GetEntryCount()-4 : 1;
352 break;
353 case SQLFilterOperator::SQLNULL:
354 nPos = rListBox.GetEntryCount()-2;
355 break;
356 case SQLFilterOperator::NOT_SQLNULL:
357 nPos = rListBox.GetEntryCount()-1;
358 break;
359 default:
360 // TODO What value should this be?
361 nPos = 0;
362 break;
364 return nPos;
366 // -----------------------------------------------------------------------------
367 sal_Bool DlgFilterCrit::getCondition(const ListBox& _rField,const ListBox& _rComp,const Edit& _rValue,PropertyValue& _rFilter) const
369 sal_Bool bHaving = sal_False;
372 ::rtl::OUString sTableName;
373 sal_Bool bFunction = sal_False;
374 _rFilter.Name = _rField.GetSelectEntry();
375 Reference< XPropertySet > xColumn = getQueryColumn(_rFilter.Name);
376 if ( xColumn.is() )
378 Reference< XPropertySetInfo > xInfo = xColumn->getPropertySetInfo();
379 if ( xInfo->hasPropertyByName(PROPERTY_REALNAME) )
381 if ( xInfo->hasPropertyByName(PROPERTY_TABLENAME) )
383 xColumn->getPropertyValue(PROPERTY_TABLENAME) >>= sTableName;
384 if ( sTableName.getLength() )
386 // properly quote all parts of the table name, so e.g. <schema>.<table> becomes "<schema>"."<table>"
387 ::rtl::OUString aCatlog,aSchema,aTable;
388 ::dbtools::qualifiedNameComponents( m_xMetaData, sTableName, aCatlog, aSchema, aTable, ::dbtools::eInDataManipulation );
389 sTableName = ::dbtools::composeTableName( m_xMetaData, aCatlog, aSchema, aTable, sal_True, ::dbtools::eInDataManipulation );
392 xColumn->getPropertyValue(PROPERTY_REALNAME) >>= _rFilter.Name;
393 static ::rtl::OUString sAgg(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction"));
394 if ( xInfo->hasPropertyByName(sAgg) )
395 xColumn->getPropertyValue(sAgg) >>= bHaving;
396 static ::rtl::OUString sFunction(RTL_CONSTASCII_USTRINGPARAM("Function"));
397 if ( xInfo->hasPropertyByName(sFunction) )
398 xColumn->getPropertyValue(sFunction) >>= bFunction;
400 if ( !bFunction )
402 const ::rtl::OUString aQuote = m_xMetaData.is() ? m_xMetaData->getIdentifierQuoteString() : ::rtl::OUString();
403 _rFilter.Name = ::dbtools::quoteName(aQuote,_rFilter.Name);
404 if ( sTableName.getLength() )
406 static ::rtl::OUString sSep(RTL_CONSTASCII_USTRINGPARAM("."));
407 sTableName += sSep;
408 sTableName += _rFilter.Name;
409 _rFilter.Name = sTableName;
411 } // if ( !bFunction )
414 catch(Exception)
418 _rFilter.Handle = GetOSQLPredicateType( _rComp.GetSelectEntry() );
419 if ( SQLFilterOperator::SQLNULL != _rFilter.Handle && _rFilter.Handle != SQLFilterOperator::NOT_SQLNULL )
421 String sPredicateValue = m_aPredicateInput.getPredicateValue( _rValue.GetText(), getMatchingColumn( _rValue ), sal_True );
422 ::Replace_OS_PlaceHolder( sPredicateValue );
423 _rFilter.Value <<= ::rtl::OUString(sPredicateValue);
425 return bHaving;
428 //------------------------------------------------------------------------------
429 Reference< XPropertySet > DlgFilterCrit::getColumn( const ::rtl::OUString& _rFieldName ) const
431 Reference< XPropertySet > xColumn;
434 if ( m_xColumns.is() && m_xColumns->hasByName( _rFieldName ) )
435 m_xColumns->getByName( _rFieldName ) >>= xColumn;
437 Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
438 if ( xColumns.is() && !xColumn.is() )
440 Sequence< ::rtl::OUString> aSeq = xColumns->getElementNames();
441 const ::rtl::OUString* pIter = aSeq.getConstArray();
442 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
443 for(;pIter != pEnd;++pIter)
445 Reference<XPropertySet> xProp(xColumns->getByName(*pIter),UNO_QUERY);
446 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME) )
448 ::rtl::OUString sRealName;
449 xProp->getPropertyValue(PROPERTY_REALNAME) >>= sRealName;
450 if ( sRealName == _rFieldName )
452 if ( m_xColumns.is() && m_xColumns->hasByName( *pIter ) )
453 m_xColumns->getByName( *pIter ) >>= xColumn;
454 break;
460 catch( const Exception& )
462 DBG_UNHANDLED_EXCEPTION();
465 return xColumn;
467 //------------------------------------------------------------------------------
468 Reference< XPropertySet > DlgFilterCrit::getQueryColumn( const ::rtl::OUString& _rFieldName ) const
470 Reference< XPropertySet > xColumn;
473 Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
474 if ( xColumns.is() && xColumns->hasByName( _rFieldName ) )
475 xColumns->getByName( _rFieldName ) >>= xColumn;
477 catch( const Exception& )
479 DBG_UNHANDLED_EXCEPTION();
482 return xColumn;
485 //------------------------------------------------------------------------------
486 Reference< XPropertySet > DlgFilterCrit::getMatchingColumn( const Edit& _rValueInput ) const
488 // the name
489 ::rtl::OUString sField;
490 if ( &_rValueInput == &aET_WHEREVALUE1 )
492 sField = aLB_WHEREFIELD1.GetSelectEntry();
494 else if ( &_rValueInput == &aET_WHEREVALUE2 )
496 sField = aLB_WHEREFIELD2.GetSelectEntry();
498 else if ( &_rValueInput == &aET_WHEREVALUE3 )
500 sField = aLB_WHEREFIELD3.GetSelectEntry();
502 else {
503 DBG_ERROR( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
506 // the field itself
507 return getColumn( sField );
510 //------------------------------------------------------------------------------
511 IMPL_LINK( DlgFilterCrit, PredicateLoseFocus, Edit*, _pField )
513 DBG_ASSERT( _pField, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
514 if ( _pField )
516 // retrieve the field affected
517 Reference< XPropertySet> xColumn( getMatchingColumn( *_pField ) );
518 // and normalize it's content
519 if ( xColumn.is() )
521 ::rtl::OUString sText( _pField->GetText() );
522 m_aPredicateInput.normalizePredicateString( sText, xColumn );
523 _pField->SetText( sText );
527 return 0L;
530 //------------------------------------------------------------------------------
531 //------------------------------------------------------------------------------
532 void DlgFilterCrit::SetLine( sal_uInt16 nIdx,const PropertyValue& _rItem,sal_Bool _bOr )
534 DBG_CHKTHIS(DlgFilterCrit,NULL);
535 ::rtl::OUString aCondition;
536 _rItem.Value >>= aCondition;
537 String aStr = aCondition.getStr();
538 ::Replace_SQL_PlaceHolder(aStr);
539 aStr.EraseTrailingChars();
541 Reference< XPropertySet > xColumn = getColumn( _rItem.Name );
543 // remove the predicate from the condition
544 switch(_rItem.Handle)
546 case SQLFilterOperator::EQUAL:
547 // aStr.Erase(0,1);
548 break;
549 case SQLFilterOperator::NOT_EQUAL:
550 aStr.Erase(0,2);
551 break;
552 case SQLFilterOperator::LESS:
553 aStr.Erase(0,1);
554 break;
555 case SQLFilterOperator::LESS_EQUAL:
556 aStr.Erase(0,2);
557 break;
558 case SQLFilterOperator::GREATER:
559 aStr.Erase(0,1);
560 break;
561 case SQLFilterOperator::GREATER_EQUAL:
562 aStr.Erase(0,2);
563 break;
564 case SQLFilterOperator::NOT_LIKE:
565 aStr.Erase(0,8);
566 break;
567 case SQLFilterOperator::LIKE:
568 aStr.Erase(0,4);
569 break;
570 case SQLFilterOperator::SQLNULL:
571 aStr.Erase(0,7);
572 break;
573 case SQLFilterOperator::NOT_SQLNULL:
574 aStr.Erase(0,11);
575 break;
577 aStr.EraseLeadingChars();
579 // to make sure that we only set first three
580 ListBox* pColumnListControl = NULL;
581 ListBox* pPredicateListControl = NULL;
582 Edit* pPredicateValueControl = NULL;
583 switch( nIdx )
585 case 0:
586 pColumnListControl = &aLB_WHEREFIELD1;
587 pPredicateListControl = &aLB_WHERECOMP1;
588 pPredicateValueControl = &aET_WHEREVALUE1;
589 break;
591 case 1:
592 aLB_WHERECOND2.SelectEntryPos( _bOr ? 1 : 0 );
594 pColumnListControl = &aLB_WHEREFIELD2;
595 pPredicateListControl = &aLB_WHERECOMP2;
596 pPredicateValueControl = &aET_WHEREVALUE2;
597 break;
599 case 2:
600 aLB_WHERECOND3.SelectEntryPos( _bOr ? 1 : 0 );
602 pColumnListControl = &aLB_WHEREFIELD3;
603 pPredicateListControl = &aLB_WHERECOMP3;
604 pPredicateValueControl = &aET_WHEREVALUE3;
605 break;
608 if ( pColumnListControl && pPredicateListControl && pPredicateValueControl )
610 ::rtl::OUString sName;
611 if ( xColumn.is() )
612 xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
613 else
614 sName = _rItem.Name;
615 // select the appropriate field name
616 SelectField( *pColumnListControl, sName );
617 ListSelectHdl( pColumnListControl );
619 // select the appropriate condition
620 pPredicateListControl->SelectEntryPos( GetSelectionPos( (sal_Int32)_rItem.Handle, *pPredicateListControl ) );
622 // initially normalize this value
623 ::rtl::OUString aString( aStr );
624 m_aPredicateInput.normalizePredicateString( aString, xColumn );
625 pPredicateValueControl->SetText( aString );
629 //------------------------------------------------------------------------------
630 void DlgFilterCrit::SelectField( ListBox& rBox, const String& rField )
632 DBG_CHKTHIS(DlgFilterCrit,NULL);
633 sal_uInt16 nCnt = rBox.GetEntryCount();
634 // sal_Bool bCase = m_rIterator.TablesAreSensitive();
636 for( sal_uInt16 i=0 ; i<nCnt ; i++ )
638 // if(bCase ? rBox.GetEntry(i) == rField : rBox.GetEntry(i).EqualsIgnoreCaseAscii(rField))
639 if(rBox.GetEntry(i) == rField)
641 rBox.SelectEntryPos(i);
642 return;
646 rBox.SelectEntryPos(0);
649 //------------------------------------------------------------------------------
650 void DlgFilterCrit::EnableLines()
652 DBG_CHKTHIS(DlgFilterCrit,NULL);
653 // Enablen/Disablen ganzer Zeilen
654 if( LbPos(aLB_WHEREFIELD1) == 0 )
656 aLB_WHEREFIELD2.Disable();
657 aLB_WHERECOND2.Disable();
658 aLB_WHERECOMP2.Disable();
659 aET_WHEREVALUE2.Disable();
661 aLB_WHEREFIELD3.Disable();
662 aLB_WHERECOND3.Disable();
663 aLB_WHERECOMP3.Disable();
664 aET_WHEREVALUE3.Disable();
666 else
668 aLB_WHEREFIELD2.Enable();
669 aLB_WHERECOND2.Enable();
670 aLB_WHERECOMP2.Enable();
671 aET_WHEREVALUE2.Enable();
673 aLB_WHEREFIELD3.Enable();
674 aLB_WHERECOND3.Enable();
675 aLB_WHERECOMP3.Enable();
676 aET_WHEREVALUE3.Enable();
679 if( LbPos(aLB_WHEREFIELD2) == 0 )
681 aLB_WHEREFIELD3.Disable();
682 aLB_WHERECOND3.Disable();
683 aLB_WHERECOMP3.Disable();
684 aET_WHEREVALUE3.Disable();
686 else
688 aLB_WHEREFIELD3.Enable();
689 aLB_WHERECOND3.Enable();
690 aLB_WHERECOMP3.Enable();
691 aET_WHEREVALUE3.Enable();
694 // Vergleichsfeld gleich NOENTRY
695 if( LbPos(aLB_WHEREFIELD1) == 0 )
697 aLB_WHERECOMP1.Disable();
698 aET_WHEREVALUE1.Disable();
700 else
702 aLB_WHEREFIELD1.Enable();
703 aLB_WHERECOMP1.Enable();
704 aET_WHEREVALUE1.Enable();
707 if( LbPos(aLB_WHEREFIELD2) == 0 )
709 aLB_WHERECOND2.Disable();
710 aLB_WHERECOMP2.Disable();
711 aET_WHEREVALUE2.Disable();
713 else
715 aLB_WHERECOND2.Enable();
716 aLB_WHEREFIELD2.Enable();
717 aLB_WHERECOMP2.Enable();
718 aET_WHEREVALUE2.Enable();
721 if( LbPos(aLB_WHEREFIELD3) == 0 )
723 aLB_WHERECOND3.Disable();
724 aLB_WHERECOMP3.Disable();
725 aET_WHEREVALUE3.Disable();
727 else
729 aLB_WHERECOND3.Enable();
730 aLB_WHERECOND3.Enable();
731 aLB_WHEREFIELD3.Enable();
732 aLB_WHERECOMP3.Enable();
733 aET_WHEREVALUE3.Enable();
736 // Vergleichsoperator gleich ISNULL oder ISNOTNULL
737 if(aLB_WHERECOMP1.GetEntryCount() > 2 &&
738 ((LbPos(aLB_WHERECOMP1) == aLB_WHERECOMP1.GetEntryCount()-1) ||
739 (LbPos(aLB_WHERECOMP1) == aLB_WHERECOMP1.GetEntryCount()-2)) )
740 aET_WHEREVALUE1.Disable();
742 if(aLB_WHERECOMP2.GetEntryCount() > 2 &&
743 ((LbPos(aLB_WHERECOMP2) == aLB_WHERECOMP2.GetEntryCount()-1) ||
744 (LbPos(aLB_WHERECOMP2) == aLB_WHERECOMP2.GetEntryCount()-2)) )
745 aET_WHEREVALUE2.Disable();
747 if(aLB_WHERECOMP3.GetEntryCount() > 2 &&
748 ((LbPos(aLB_WHERECOMP3) == aLB_WHERECOMP3.GetEntryCount()-1) ||
749 (LbPos(aLB_WHERECOMP3) == aLB_WHERECOMP3.GetEntryCount()-2)) )
750 aET_WHEREVALUE3.Disable();
754 //------------------------------------------------------------------------------
755 IMPL_LINK( DlgFilterCrit, ListSelectHdl, ListBox *, pListBox )
757 String aName;
758 ListBox* pComp;
759 if(pListBox == &aLB_WHEREFIELD1)
761 aName = LbText(aLB_WHEREFIELD1);
762 pComp = &aLB_WHERECOMP1;
764 else if(pListBox == &aLB_WHEREFIELD2)
766 aName = LbText(aLB_WHEREFIELD2);
767 pComp = &aLB_WHERECOMP2;
769 else
771 aName = LbText(aLB_WHEREFIELD3);
772 pComp = &aLB_WHERECOMP3;
775 pComp->Clear();
777 Reference<XPropertySet> xColumn = getColumn(aName);
778 if ( xColumn.is() )
780 sal_Int32 nDataType = 0;
781 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
782 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
784 if(eColumnSearch == ColumnSearch::FULL)
786 for(xub_StrLen i=0;i<aSTR_COMPARE_OPERATORS.GetTokenCount();i++)
787 pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i));
789 else if(eColumnSearch == ColumnSearch::CHAR)
791 for(xub_StrLen i=6;i<10;i++)
792 pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i));
794 else if(eColumnSearch == ColumnSearch::BASIC)
796 xub_StrLen i;
797 for( i = 0; i < 6; i++ )
798 pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i));
799 for(i=8;i<aSTR_COMPARE_OPERATORS.GetTokenCount();i++)
800 pComp->InsertEntry(aSTR_COMPARE_OPERATORS.GetToken(i));
802 else
804 DBG_ASSERT(0,"DlgFilterCrit::ListSelectHdl: Diese Column d�rfte garnicht vorhanden sein!");
807 pComp->SelectEntryPos(0);
809 EnableLines();
810 return 0;
815 //------------------------------------------------------------------------------
816 IMPL_LINK_INLINE_START( DlgFilterCrit, ListSelectCompHdl, ListBox *, /*pListBox*/ )
818 EnableLines();
819 return 0;
821 IMPL_LINK_INLINE_END( DlgFilterCrit, ListSelectCompHdl, ListBox *, pListBox )
822 //------------------------------------------------------------------------------
823 void DlgFilterCrit::BuildWherePart()
825 DBG_CHKTHIS(DlgFilterCrit,NULL);
826 Sequence<Sequence<PropertyValue> > aFilter,aHaving;
827 aFilter.realloc(1);
828 aHaving.realloc(1);
829 // ::rtl::OUString aFilter;
831 if( LbPos(aLB_WHEREFIELD1) != 0 )
833 PropertyValue aValue;
834 if ( getCondition(aLB_WHEREFIELD1,aLB_WHERECOMP1,aET_WHEREVALUE1,aValue) )
836 aHaving[0].realloc(1);
837 aHaving[0][0] = aValue;
839 else
841 aFilter[0].realloc(1);
842 aFilter[0][0] = aValue;
846 if( LbPos(aLB_WHEREFIELD2) != 0 )
848 PropertyValue aValue;
849 Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
850 if ( getCondition(aLB_WHEREFIELD2,aLB_WHERECOMP2,aET_WHEREVALUE2,aValue) )
851 _rValues = aHaving;
852 PropertyValue* pPos = NULL;
853 if ( aLB_WHERECOND2.GetSelectEntryPos() )
855 sal_Int32 nPos = _rValues.getLength();
856 _rValues.realloc( nPos + 1);
857 _rValues[nPos].realloc( 1);
858 pPos = &_rValues[nPos][0];
860 else
862 sal_Int32 nPos = _rValues.getLength() - 1;
863 sal_Int32 nAndPos = _rValues[nPos].getLength();
864 _rValues[nPos].realloc( _rValues[nPos].getLength() + 1);
865 pPos = &_rValues[nPos][nAndPos];
867 *pPos = aValue;
870 if( LbPos(aLB_WHEREFIELD3) != 0 )
872 PropertyValue aValue;
873 Sequence<Sequence<PropertyValue> >& _rValues = aFilter;
874 if ( getCondition(aLB_WHEREFIELD3,aLB_WHERECOMP3,aET_WHEREVALUE3,aValue) )
875 _rValues = aHaving;
876 PropertyValue* pPos = NULL;
877 if ( aLB_WHERECOND3.GetSelectEntryPos() )
879 sal_Int32 nPos = _rValues.getLength();
880 _rValues.realloc( nPos + 1);
881 _rValues[nPos].realloc( 1);
882 pPos = &_rValues[nPos][0];
884 else
886 sal_Int32 nPos = _rValues.getLength() - 1;
887 sal_Int32 nAndPos = _rValues[nPos].getLength();
888 _rValues[nPos].realloc( _rValues[nPos].getLength() + 1);
889 pPos = &_rValues[nPos][nAndPos];
891 *pPos = aValue;
895 m_xQueryComposer->setStructuredFilter(aFilter);
896 m_xQueryComposer->setStructuredHavingClause(aHaving);
898 catch(Exception)
900 DBG_UNHANDLED_EXCEPTION();
903 // -----------------------------------------------------------------------------
904 void DlgFilterCrit::fillLines(const Sequence<Sequence<PropertyValue > >& _aValues)
906 const Sequence<PropertyValue >* pOrIter = _aValues.getConstArray();
907 const Sequence<PropertyValue >* pOrEnd = pOrIter + _aValues.getLength();
908 sal_Bool bOr = sal_True;
909 for(sal_uInt16 i=0;pOrIter != pOrEnd; ++pOrIter)
911 bOr = sal_True;
912 const PropertyValue* pAndIter = pOrIter->getConstArray();
913 const PropertyValue* pAndEnd = pAndIter + pOrIter->getLength();
914 for(;pAndIter != pAndEnd; ++pAndIter)
916 SetLine( i++,*pAndIter,bOr);
917 bOr = sal_False;