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>
29#include <osl/diagnose.h>
32#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
47 aString = aString.replaceAll(
"*",
"%" );
48 aString = aString.replaceAll(
"?",
"_" );
53 aString = aString.replaceAll(
"%",
"*" );
54 aString = aString.replaceAll(
"_",
"?" );
62 : GenericDialogController(pParent,
"dbaccess/ui/queryfilterdialog.ui",
"QueryFilterDialog")
63 , m_xQueryComposer(_rxComposer)
64 , m_xColumns( _rxCols )
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"))
88 for (sal_Int32
i = 0;
i < nEntryCount; ++
i)
96 const OUString* pIter = aNames.getConstArray();
97 const OUString* pEnd = pIter + aNames.getLength();
99 for(;pIter != pEnd;++pIter)
108 if ( eColumnSearch == ColumnSearch::NONE )
111 bool bIsSearchable(
true );
113 if ( !bIsSearchable )
126 aNames = xSelectColumns->getElementNames();
127 pIter = aNames.getConstArray();
128 pEnd = pIter + aNames.getLength();
129 for(;pIter != pEnd;++pIter)
134 xColumn.set(xSelectColumns->getByName(*pIter),UNO_QUERY);
135 OSL_ENSURE(
xColumn.is(),
"DlgFilterCrit::DlgFilterCrit: Column is null!");
141 if(eColumnSearch != ColumnSearch::NONE)
185 sal_Int32 nPredicateIndex = -1;
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;
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:
260 case SQLFilterOperator::LIKE:
263 case SQLFilterOperator::SQLNULL:
266 case SQLFilterOperator::NOT_SQLNULL:
279 bool bHaving =
false;
286 bool bFunction =
false;
294 if ( !sTableName.isEmpty() )
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 );
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;
314 _rFilter.Name = ::dbtools::quoteName(aQuote,_rFilter.Name);
315 if ( !sTableName.isEmpty() )
317 sTableName +=
"." + _rFilter.Name;
318 _rFilter.Name = sTableName;
328 if ( SQLFilterOperator::SQLNULL != _rFilter.Handle && _rFilter.Handle != SQLFilterOperator::NOT_SQLNULL )
330 OUString sPredicateValue;
332 if ( _rFilter.Handle == SQLFilterOperator::LIKE ||
333 _rFilter.Handle == SQLFilterOperator::NOT_LIKE )
335 _rFilter.Value <<= sPredicateValue;
349 if ( xColumns.is() && !
xColumn.is() )
352 const OUString* pIter =
aSeq.getConstArray();
353 const OUString* pEnd = pIter +
aSeq.getLength();
354 for(;pIter != pEnd;++pIter)
357 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(
PROPERTY_REALNAME) )
361 if ( sRealName == _rFieldName )
385 if ( xColumns.is() && xColumns->hasByName( _rFieldName ) )
386 xColumns->getByName( _rFieldName ) >>=
xColumn;
413 OSL_FAIL(
"DlgFilterCrit::getMatchingColumn: invalid event source!" );
429 m_aPredicateInput.normalizePredicateString(sText,
xColumn);
437 _rItem.Value >>=
aStr;
438 if ( _rItem.Handle == SQLFilterOperator::LIKE ||
439 _rItem.Handle == SQLFilterOperator::NOT_LIKE )
472 if ( !(pColumnListControl && pPredicateListControl && pPredicateValueControl) )
482 ListSelectHdl( *pColumnListControl );
488 OUString aString(
aStr );
490 pPredicateValueControl->
set_text( aString );
497 for( sal_Int32
i=0 ;
i<nCnt ;
i++ )
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();
640 if(eColumnSearch == ColumnSearch::FULL)
642 for(
size_t i=0;
i < m_aSTR_COMPARE_OPERATORS.size();
i++)
645 else if(eColumnSearch == ColumnSearch::CHAR)
647 for(sal_Int32
i=6;
i<10;
i++)
650 else if(eColumnSearch == ColumnSearch::BASIC)
653 for(
i = 0;
i < 6;
i++ )
655 for(
i=8;
i < m_aSTR_COMPARE_OPERATORS.size(); ++
i)
660 OSL_FAIL(
"DlgFilterCrit::ListSelectHdl: This column should not exist at all.");
679 PropertyValue aValue;
682 aHaving = { { aValue } };
686 aFilter = { { aValue} };
692 PropertyValue aValue;
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();
707 PropertyValue aValue;
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();
735 for(; pOrIter != pOrEnd; ++pOrIter)
737 const PropertyValue* pAndIter = pOrIter->getConstArray();
738 const PropertyValue* pAndEnd = pAndIter + pOrIter->getLength();
739 for(;pAndIter != pAndEnd; ++pAndIter)
const PropertyValue * pValues
constexpr tools::Long Width() const
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOND3
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
css::uno::Reference< css::sdbc::XConnection > m_xConnection
sal_Int32 GetOSQLPredicateType(std::u16string_view _rSelectedPredicate) const
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP3
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD3
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xQueryComposer
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP2
std::vector< OUString > m_aSTR_COMPARE_OPERATORS
css::uno::Reference< css::container::XNameAccess > m_xColumns
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD1
std::unique_ptr< weld::Entry > m_xET_WHEREVALUE2
std::unique_ptr< weld::ComboBox > m_xLB_WHEREFIELD2
std::unique_ptr< weld::Entry > m_xET_WHEREVALUE3
bool getCondition(const weld::ComboBox &_rField, const weld::ComboBox &_rComp, const weld::Entry &_rValue, css::beans::PropertyValue &_rFilter) const
::dbtools::OPredicateInputController m_aPredicateInput
std::unique_ptr< weld::ComboBox > m_xLB_WHERECOMP1
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
virtual ~DlgFilterCrit() override
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
virtual OUString get_active_text() const=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(...)
#define LINK(Instance, Class, Member)
Sequence< sal_Int8 > aSeq
double getLength(const B2DPolygon &rCandidate)
B2DTuple getColumn(const B2DHomMatrix &rMatrix, sal_uInt16 nCol)
OString stripEnd(const OString &rIn, char c)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
Reference< XConnection > m_xConnection
static void Replace_SQL_PlaceHolder(OUString &aString)
static void Replace_OS_PlaceHolder(OUString &aString)
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")