1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
34 #ifndef _DBAUI_MODULE_DBU_HXX_
35 #include "moduledbu.hxx"
37 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
38 #include <com/sun/star/sdbc/DataType.hpp>
40 #ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
41 #include <com/sun/star/util/Date.hpp>
43 #ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
44 #include <com/sun/star/util/DateTime.hpp>
46 #ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
47 #include <com/sun/star/util/Time.hpp>
49 #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
50 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
52 #ifndef _COM_SUN_STAR_SDBC_COLUMNSEARCH_HPP_
53 #include <com/sun/star/sdbc/ColumnSearch.hpp>
55 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
56 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
58 #ifndef _COM_SUN_STAR_SDB_SQLFILTEROPERATOR_HPP_
59 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
61 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
62 #include <com/sun/star/sdbc/XRow.hpp>
64 #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
65 #include <com/sun/star/sdbc/XResultSet.hpp>
67 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
68 #include <com/sun/star/container/XNameAccess.hpp>
70 #ifndef _TOOLS_DEBUG_HXX
71 #include <tools/debug.hxx>
73 #ifndef TOOLS_DIAGNOSE_EX_H
74 #include <tools/diagnose_ex.h>
76 #ifndef TOOLS_DIAGNOSE_EX_H
77 #include <tools/diagnose_ex.h>
79 #ifndef _DBAUI_MODULE_DBU_HXX_
80 #include "moduledbu.hxx"
82 #ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
83 #include <connectivity/sqliterator.hxx>
85 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
86 #include <connectivity/dbtools.hxx>
88 #ifndef DBAUI_QUERYFILTER_HRC
89 #include "queryfilter.hrc"
91 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
92 #include "dbustrings.hrc"
94 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
95 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
97 #ifndef _COM_SUN_STAR_SDB_SQLFILTEROPERATOR_HPP_
98 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
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
)
188 sal_Bool
bIsSearchable( sal_True
);
189 OSL_VERIFY( xColumn
->getPropertyValue( PROPERTY_ISSEARCHABLE
) >>= bIsSearchable
);
190 if ( !bIsSearchable
)
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
);
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();
234 aValues
= m_xQueryComposer
->getStructuredHavingClause();
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();
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
)
283 sal_Int32 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
284 switch ( nPredicateIndex
)
287 nPredicateType
= SQLFilterOperator::EQUAL
;
290 nPredicateType
= SQLFilterOperator::NOT_EQUAL
;
293 nPredicateType
= SQLFilterOperator::LESS
;
296 nPredicateType
= SQLFilterOperator::LESS_EQUAL
;
299 nPredicateType
= SQLFilterOperator::GREATER
;
302 nPredicateType
= SQLFilterOperator::GREATER_EQUAL
;
305 nPredicateType
= SQLFilterOperator::LIKE
;
308 nPredicateType
= SQLFilterOperator::NOT_LIKE
;
311 nPredicateType
= SQLFilterOperator::SQLNULL
;
314 nPredicateType
= SQLFilterOperator::NOT_SQLNULL
;
317 OSL_ENSURE( false, "DlgFilterCrit::GetOSQLPredicateType: unknown predicate string!" );
321 return nPredicateType
;
323 //------------------------------------------------------------------------------
324 sal_uInt16
DlgFilterCrit::GetSelectionPos(sal_Int32 eType
,const ListBox
& rListBox
) const
329 case SQLFilterOperator::EQUAL
:
332 case SQLFilterOperator::NOT_EQUAL
:
335 case SQLFilterOperator::LESS
:
338 case SQLFilterOperator::LESS_EQUAL
:
341 case SQLFilterOperator::GREATER
:
344 case SQLFilterOperator::GREATER_EQUAL
:
347 case SQLFilterOperator::NOT_LIKE
:
348 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-3 : 0;
350 case SQLFilterOperator::LIKE
:
351 nPos
= rListBox
.GetEntryCount() > 2 ? rListBox
.GetEntryCount()-4 : 1;
353 case SQLFilterOperator::SQLNULL
:
354 nPos
= rListBox
.GetEntryCount()-2;
356 case SQLFilterOperator::NOT_SQLNULL
:
357 nPos
= rListBox
.GetEntryCount()-1;
360 // TODO What value should this be?
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
);
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
;
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("."));
408 sTableName
+= _rFilter
.Name
;
409 _rFilter
.Name
= sTableName
;
411 } // if ( !bFunction )
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
);
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
;
460 catch( const Exception
& )
462 DBG_UNHANDLED_EXCEPTION();
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();
485 //------------------------------------------------------------------------------
486 Reference
< XPropertySet
> DlgFilterCrit::getMatchingColumn( const Edit
& _rValueInput
) const
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();
503 DBG_ERROR( "DlgFilterCrit::getMatchingColumn: invalid event source!" );
507 return getColumn( sField
);
510 //------------------------------------------------------------------------------
511 IMPL_LINK( DlgFilterCrit
, PredicateLoseFocus
, Edit
*, _pField
)
513 DBG_ASSERT( _pField
, "DlgFilterCrit::PredicateLoseFocus: invalid event source!" );
516 // retrieve the field affected
517 Reference
< XPropertySet
> xColumn( getMatchingColumn( *_pField
) );
518 // and normalize it's content
521 ::rtl::OUString
sText( _pField
->GetText() );
522 m_aPredicateInput
.normalizePredicateString( sText
, xColumn
);
523 _pField
->SetText( sText
);
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
:
549 case SQLFilterOperator::NOT_EQUAL
:
552 case SQLFilterOperator::LESS
:
555 case SQLFilterOperator::LESS_EQUAL
:
558 case SQLFilterOperator::GREATER
:
561 case SQLFilterOperator::GREATER_EQUAL
:
564 case SQLFilterOperator::NOT_LIKE
:
567 case SQLFilterOperator::LIKE
:
570 case SQLFilterOperator::SQLNULL
:
573 case SQLFilterOperator::NOT_SQLNULL
:
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
;
586 pColumnListControl
= &aLB_WHEREFIELD1
;
587 pPredicateListControl
= &aLB_WHERECOMP1
;
588 pPredicateValueControl
= &aET_WHEREVALUE1
;
592 aLB_WHERECOND2
.SelectEntryPos( _bOr
? 1 : 0 );
594 pColumnListControl
= &aLB_WHEREFIELD2
;
595 pPredicateListControl
= &aLB_WHERECOMP2
;
596 pPredicateValueControl
= &aET_WHEREVALUE2
;
600 aLB_WHERECOND3
.SelectEntryPos( _bOr
? 1 : 0 );
602 pColumnListControl
= &aLB_WHEREFIELD3
;
603 pPredicateListControl
= &aLB_WHERECOMP3
;
604 pPredicateValueControl
= &aET_WHEREVALUE3
;
608 if ( pColumnListControl
&& pPredicateListControl
&& pPredicateValueControl
)
610 ::rtl::OUString sName
;
612 xColumn
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
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
);
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();
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();
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();
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();
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();
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
)
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
;
771 aName
= LbText(aLB_WHEREFIELD3
);
772 pComp
= &aLB_WHERECOMP3
;
777 Reference
<XPropertySet
> xColumn
= getColumn(aName
);
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
)
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
));
804 DBG_ASSERT(0,"DlgFilterCrit::ListSelectHdl: Diese Column d�rfte garnicht vorhanden sein!");
807 pComp
->SelectEntryPos(0);
815 //------------------------------------------------------------------------------
816 IMPL_LINK_INLINE_START( DlgFilterCrit
, ListSelectCompHdl
, ListBox
*, /*pListBox*/ )
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
;
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
;
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
) )
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];
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
];
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
) )
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];
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
];
895 m_xQueryComposer
->setStructuredFilter(aFilter
);
896 m_xQueryComposer
->setStructuredHavingClause(aHaving
);
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
)
912 const PropertyValue
* pAndIter
= pOrIter
->getConstArray();
913 const PropertyValue
* pAndEnd
= pAndIter
+ pOrIter
->getLength();
914 for(;pAndIter
!= pAndEnd
; ++pAndIter
)
916 SetLine( i
++,*pAndIter
,bOr
);