1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_connectivity.hxx"
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski #include "kcondition.hxx"
28*b1cdbd2cSJim Jagielski #include "kfields.hxx"
29*b1cdbd2cSJim Jagielski #include "connectivity/CommonTools.hxx"
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski using namespace ::connectivity::kab;
32*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::sdbc;
33*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
~KabCondition()34*b1cdbd2cSJim Jagielski KabCondition::~KabCondition()
35*b1cdbd2cSJim Jagielski {
36*b1cdbd2cSJim Jagielski }
37*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionConstant(const sal_Bool bValue)38*b1cdbd2cSJim Jagielski KabConditionConstant::KabConditionConstant(const sal_Bool bValue)
39*b1cdbd2cSJim Jagielski : KabCondition(),
40*b1cdbd2cSJim Jagielski m_bValue(bValue)
41*b1cdbd2cSJim Jagielski {
42*b1cdbd2cSJim Jagielski }
43*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysTrue() const44*b1cdbd2cSJim Jagielski sal_Bool KabConditionConstant::isAlwaysTrue() const
45*b1cdbd2cSJim Jagielski {
46*b1cdbd2cSJim Jagielski return m_bValue;
47*b1cdbd2cSJim Jagielski }
48*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysFalse() const49*b1cdbd2cSJim Jagielski sal_Bool KabConditionConstant::isAlwaysFalse() const
50*b1cdbd2cSJim Jagielski {
51*b1cdbd2cSJim Jagielski return !m_bValue;
52*b1cdbd2cSJim Jagielski }
53*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee &) const54*b1cdbd2cSJim Jagielski sal_Bool KabConditionConstant::eval(const ::KABC::Addressee &) const
55*b1cdbd2cSJim Jagielski {
56*b1cdbd2cSJim Jagielski return m_bValue;
57*b1cdbd2cSJim Jagielski }
58*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionColumn(const::rtl::OUString & sColumnName)59*b1cdbd2cSJim Jagielski KabConditionColumn::KabConditionColumn(const ::rtl::OUString &sColumnName) throw(SQLException)
60*b1cdbd2cSJim Jagielski : KabCondition(),
61*b1cdbd2cSJim Jagielski m_nFieldNumber(findKabField(sColumnName))
62*b1cdbd2cSJim Jagielski {
63*b1cdbd2cSJim Jagielski }
64*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysTrue() const65*b1cdbd2cSJim Jagielski sal_Bool KabConditionColumn::isAlwaysTrue() const
66*b1cdbd2cSJim Jagielski {
67*b1cdbd2cSJim Jagielski // Sometimes true, sometimes false
68*b1cdbd2cSJim Jagielski return sal_False;
69*b1cdbd2cSJim Jagielski }
70*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysFalse() const71*b1cdbd2cSJim Jagielski sal_Bool KabConditionColumn::isAlwaysFalse() const
72*b1cdbd2cSJim Jagielski {
73*b1cdbd2cSJim Jagielski // Sometimes true, sometimes false
74*b1cdbd2cSJim Jagielski return sal_False;
75*b1cdbd2cSJim Jagielski }
76*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionNull(const::rtl::OUString & sColumnName)77*b1cdbd2cSJim Jagielski KabConditionNull::KabConditionNull(const ::rtl::OUString &sColumnName) throw(SQLException)
78*b1cdbd2cSJim Jagielski : KabConditionColumn(sColumnName)
79*b1cdbd2cSJim Jagielski {
80*b1cdbd2cSJim Jagielski }
81*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const82*b1cdbd2cSJim Jagielski sal_Bool KabConditionNull::eval(const ::KABC::Addressee &aAddressee) const
83*b1cdbd2cSJim Jagielski {
84*b1cdbd2cSJim Jagielski QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
85*b1cdbd2cSJim Jagielski
86*b1cdbd2cSJim Jagielski return aQtName.isNull();
87*b1cdbd2cSJim Jagielski // KDE address book currently does not use NULL values.
88*b1cdbd2cSJim Jagielski // But it might do it someday
89*b1cdbd2cSJim Jagielski }
90*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionNotNull(const::rtl::OUString & sColumnName)91*b1cdbd2cSJim Jagielski KabConditionNotNull::KabConditionNotNull(const ::rtl::OUString &sColumnName) throw(SQLException)
92*b1cdbd2cSJim Jagielski : KabConditionColumn(sColumnName)
93*b1cdbd2cSJim Jagielski {
94*b1cdbd2cSJim Jagielski }
95*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const96*b1cdbd2cSJim Jagielski sal_Bool KabConditionNotNull::eval(const ::KABC::Addressee &aAddressee) const
97*b1cdbd2cSJim Jagielski {
98*b1cdbd2cSJim Jagielski QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski return !aQtName.isNull();
101*b1cdbd2cSJim Jagielski // KDE address book currently does not use NULL values.
102*b1cdbd2cSJim Jagielski // But it might do it someday
103*b1cdbd2cSJim Jagielski }
104*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionCompare(const::rtl::OUString & sColumnName,const::rtl::OUString & sMatchString)105*b1cdbd2cSJim Jagielski KabConditionCompare::KabConditionCompare(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
106*b1cdbd2cSJim Jagielski : KabConditionColumn(sColumnName),
107*b1cdbd2cSJim Jagielski m_sMatchString(sMatchString)
108*b1cdbd2cSJim Jagielski {
109*b1cdbd2cSJim Jagielski }
110*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionEqual(const::rtl::OUString & sColumnName,const::rtl::OUString & sMatchString)111*b1cdbd2cSJim Jagielski KabConditionEqual::KabConditionEqual(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
112*b1cdbd2cSJim Jagielski : KabConditionCompare(sColumnName, sMatchString)
113*b1cdbd2cSJim Jagielski {
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const116*b1cdbd2cSJim Jagielski sal_Bool KabConditionEqual::eval(const ::KABC::Addressee &aAddressee) const
117*b1cdbd2cSJim Jagielski {
118*b1cdbd2cSJim Jagielski QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
119*b1cdbd2cSJim Jagielski // Timestamps should not be compared according to their string value
120*b1cdbd2cSJim Jagielski // The syntax for such queries should be like
121*b1cdbd2cSJim Jagielski // {ts '2004-03-29 12:55:00.000000'}
122*b1cdbd2cSJim Jagielski // They should also support operators like '<' or '>='
123*b1cdbd2cSJim Jagielski
124*b1cdbd2cSJim Jagielski if (aQtName.isNull()) return sal_False;
125*b1cdbd2cSJim Jagielski
126*b1cdbd2cSJim Jagielski ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
127*b1cdbd2cSJim Jagielski return sValue == m_sMatchString;
128*b1cdbd2cSJim Jagielski }
129*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionDifferent(const::rtl::OUString & sColumnName,const::rtl::OUString & sMatchString)130*b1cdbd2cSJim Jagielski KabConditionDifferent::KabConditionDifferent(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
131*b1cdbd2cSJim Jagielski : KabConditionCompare(sColumnName, sMatchString)
132*b1cdbd2cSJim Jagielski {
133*b1cdbd2cSJim Jagielski }
134*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const135*b1cdbd2cSJim Jagielski sal_Bool KabConditionDifferent::eval(const ::KABC::Addressee &aAddressee) const
136*b1cdbd2cSJim Jagielski {
137*b1cdbd2cSJim Jagielski QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
138*b1cdbd2cSJim Jagielski
139*b1cdbd2cSJim Jagielski if (aQtName.isNull()) return sal_False;
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
142*b1cdbd2cSJim Jagielski return sValue != m_sMatchString;
143*b1cdbd2cSJim Jagielski }
144*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionSimilar(const::rtl::OUString & sColumnName,const::rtl::OUString & sMatchString)145*b1cdbd2cSJim Jagielski KabConditionSimilar::KabConditionSimilar(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
146*b1cdbd2cSJim Jagielski : KabConditionCompare(sColumnName, sMatchString)
147*b1cdbd2cSJim Jagielski {
148*b1cdbd2cSJim Jagielski }
149*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const150*b1cdbd2cSJim Jagielski sal_Bool KabConditionSimilar::eval(const ::KABC::Addressee &aAddressee) const
151*b1cdbd2cSJim Jagielski {
152*b1cdbd2cSJim Jagielski QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski if (aQtName.isNull()) return sal_False;
155*b1cdbd2cSJim Jagielski
156*b1cdbd2cSJim Jagielski ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
157*b1cdbd2cSJim Jagielski return match(m_sMatchString, sValue, '\0');
158*b1cdbd2cSJim Jagielski }
159*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionBoolean(KabCondition * pLeft,KabCondition * pRight)160*b1cdbd2cSJim Jagielski KabConditionBoolean::KabConditionBoolean(KabCondition *pLeft, KabCondition *pRight)
161*b1cdbd2cSJim Jagielski : KabCondition(),
162*b1cdbd2cSJim Jagielski m_pLeft(pLeft),
163*b1cdbd2cSJim Jagielski m_pRight(pRight)
164*b1cdbd2cSJim Jagielski {
165*b1cdbd2cSJim Jagielski }
166*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
~KabConditionBoolean()167*b1cdbd2cSJim Jagielski KabConditionBoolean::~KabConditionBoolean()
168*b1cdbd2cSJim Jagielski {
169*b1cdbd2cSJim Jagielski delete m_pLeft;
170*b1cdbd2cSJim Jagielski delete m_pRight;
171*b1cdbd2cSJim Jagielski }
172*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionOr(KabCondition * pLeft,KabCondition * pRight)173*b1cdbd2cSJim Jagielski KabConditionOr::KabConditionOr(KabCondition *pLeft, KabCondition *pRight)
174*b1cdbd2cSJim Jagielski : KabConditionBoolean(pLeft, pRight)
175*b1cdbd2cSJim Jagielski {
176*b1cdbd2cSJim Jagielski }
177*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysTrue() const178*b1cdbd2cSJim Jagielski sal_Bool KabConditionOr::isAlwaysTrue() const
179*b1cdbd2cSJim Jagielski {
180*b1cdbd2cSJim Jagielski return m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue();
181*b1cdbd2cSJim Jagielski }
182*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysFalse() const183*b1cdbd2cSJim Jagielski sal_Bool KabConditionOr::isAlwaysFalse() const
184*b1cdbd2cSJim Jagielski {
185*b1cdbd2cSJim Jagielski return m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse();
186*b1cdbd2cSJim Jagielski }
187*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const188*b1cdbd2cSJim Jagielski sal_Bool KabConditionOr::eval(const ::KABC::Addressee &aAddressee) const
189*b1cdbd2cSJim Jagielski {
190*b1cdbd2cSJim Jagielski // We avoid evaluating terms as much as we can
191*b1cdbd2cSJim Jagielski if (m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue()) return sal_True;
192*b1cdbd2cSJim Jagielski if (m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse()) return sal_False;
193*b1cdbd2cSJim Jagielski
194*b1cdbd2cSJim Jagielski if (m_pLeft->eval(aAddressee)) return sal_True;
195*b1cdbd2cSJim Jagielski if (m_pRight->eval(aAddressee)) return sal_True;
196*b1cdbd2cSJim Jagielski
197*b1cdbd2cSJim Jagielski return sal_False;
198*b1cdbd2cSJim Jagielski }
199*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
KabConditionAnd(KabCondition * pLeft,KabCondition * pRight)200*b1cdbd2cSJim Jagielski KabConditionAnd::KabConditionAnd(KabCondition *pLeft, KabCondition *pRight)
201*b1cdbd2cSJim Jagielski : KabConditionBoolean(pLeft, pRight)
202*b1cdbd2cSJim Jagielski {
203*b1cdbd2cSJim Jagielski }
204*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysTrue() const205*b1cdbd2cSJim Jagielski sal_Bool KabConditionAnd::isAlwaysTrue() const
206*b1cdbd2cSJim Jagielski {
207*b1cdbd2cSJim Jagielski return m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue();
208*b1cdbd2cSJim Jagielski }
209*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
isAlwaysFalse() const210*b1cdbd2cSJim Jagielski sal_Bool KabConditionAnd::isAlwaysFalse() const
211*b1cdbd2cSJim Jagielski {
212*b1cdbd2cSJim Jagielski return m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse();
213*b1cdbd2cSJim Jagielski }
214*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------------
eval(const::KABC::Addressee & aAddressee) const215*b1cdbd2cSJim Jagielski sal_Bool KabConditionAnd::eval(const ::KABC::Addressee &aAddressee) const
216*b1cdbd2cSJim Jagielski {
217*b1cdbd2cSJim Jagielski // We avoid evaluating terms as much as we can
218*b1cdbd2cSJim Jagielski if (m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse()) return sal_False;
219*b1cdbd2cSJim Jagielski if (m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue()) return sal_True;
220*b1cdbd2cSJim Jagielski
221*b1cdbd2cSJim Jagielski if (!m_pLeft->eval(aAddressee)) return sal_False;
222*b1cdbd2cSJim Jagielski if (!m_pRight->eval(aAddressee)) return sal_False;
223*b1cdbd2cSJim Jagielski
224*b1cdbd2cSJim Jagielski return sal_True;
225*b1cdbd2cSJim Jagielski }
226