merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / kab / kcondition.cxx
blob0bcf5f9dcc021271e6ff0e993eaf90aaab05078a
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 * $RCSfile: kcondition.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "kcondition.hxx"
35 #include "kfields.hxx"
36 #include "connectivity/CommonTools.hxx"
38 using namespace ::connectivity::kab;
39 using namespace ::com::sun::star::sdbc;
40 // -----------------------------------------------------------------------------
41 KabCondition::~KabCondition()
44 // -----------------------------------------------------------------------------
45 KabConditionConstant::KabConditionConstant(const sal_Bool bValue)
46 : KabCondition(),
47 m_bValue(bValue)
50 // -----------------------------------------------------------------------------
51 sal_Bool KabConditionConstant::isAlwaysTrue() const
53 return m_bValue;
55 // -----------------------------------------------------------------------------
56 sal_Bool KabConditionConstant::isAlwaysFalse() const
58 return !m_bValue;
60 // -----------------------------------------------------------------------------
61 sal_Bool KabConditionConstant::eval(const ::KABC::Addressee &) const
63 return m_bValue;
65 // -----------------------------------------------------------------------------
66 KabConditionColumn::KabConditionColumn(const ::rtl::OUString &sColumnName) throw(SQLException)
67 : KabCondition(),
68 m_nFieldNumber(findKabField(sColumnName))
71 // -----------------------------------------------------------------------------
72 sal_Bool KabConditionColumn::isAlwaysTrue() const
74 // Sometimes true, sometimes false
75 return sal_False;
77 // -----------------------------------------------------------------------------
78 sal_Bool KabConditionColumn::isAlwaysFalse() const
80 // Sometimes true, sometimes false
81 return sal_False;
83 // -----------------------------------------------------------------------------
84 KabConditionNull::KabConditionNull(const ::rtl::OUString &sColumnName) throw(SQLException)
85 : KabConditionColumn(sColumnName)
88 // -----------------------------------------------------------------------------
89 sal_Bool KabConditionNull::eval(const ::KABC::Addressee &aAddressee) const
91 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
93 return aQtName.isNull();
94 // KDE address book currently does not use NULL values.
95 // But it might do it someday
97 // -----------------------------------------------------------------------------
98 KabConditionNotNull::KabConditionNotNull(const ::rtl::OUString &sColumnName) throw(SQLException)
99 : KabConditionColumn(sColumnName)
102 // -----------------------------------------------------------------------------
103 sal_Bool KabConditionNotNull::eval(const ::KABC::Addressee &aAddressee) const
105 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
107 return !aQtName.isNull();
108 // KDE address book currently does not use NULL values.
109 // But it might do it someday
111 // -----------------------------------------------------------------------------
112 KabConditionCompare::KabConditionCompare(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
113 : KabConditionColumn(sColumnName),
114 m_sMatchString(sMatchString)
117 // -----------------------------------------------------------------------------
118 KabConditionEqual::KabConditionEqual(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
119 : KabConditionCompare(sColumnName, sMatchString)
122 // -----------------------------------------------------------------------------
123 sal_Bool KabConditionEqual::eval(const ::KABC::Addressee &aAddressee) const
125 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
126 // Timestamps should not be compared according to their string value
127 // The syntax for such queries should be like
128 // {ts '2004-03-29 12:55:00.000000'}
129 // They should also support operators like '<' or '>='
131 if (aQtName.isNull()) return sal_False;
133 ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
134 return sValue == m_sMatchString;
136 // -----------------------------------------------------------------------------
137 KabConditionDifferent::KabConditionDifferent(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
138 : KabConditionCompare(sColumnName, sMatchString)
141 // -----------------------------------------------------------------------------
142 sal_Bool KabConditionDifferent::eval(const ::KABC::Addressee &aAddressee) const
144 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
146 if (aQtName.isNull()) return sal_False;
148 ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
149 return sValue != m_sMatchString;
151 // -----------------------------------------------------------------------------
152 KabConditionSimilar::KabConditionSimilar(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException)
153 : KabConditionCompare(sColumnName, sMatchString)
156 // -----------------------------------------------------------------------------
157 sal_Bool KabConditionSimilar::eval(const ::KABC::Addressee &aAddressee) const
159 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
161 if (aQtName.isNull()) return sal_False;
163 ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2());
164 return match(m_sMatchString, sValue, '\0');
166 // -----------------------------------------------------------------------------
167 KabConditionBoolean::KabConditionBoolean(KabCondition *pLeft, KabCondition *pRight)
168 : KabCondition(),
169 m_pLeft(pLeft),
170 m_pRight(pRight)
173 // -----------------------------------------------------------------------------
174 KabConditionBoolean::~KabConditionBoolean()
176 delete m_pLeft;
177 delete m_pRight;
179 // -----------------------------------------------------------------------------
180 KabConditionOr::KabConditionOr(KabCondition *pLeft, KabCondition *pRight)
181 : KabConditionBoolean(pLeft, pRight)
184 // -----------------------------------------------------------------------------
185 sal_Bool KabConditionOr::isAlwaysTrue() const
187 return m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue();
189 // -----------------------------------------------------------------------------
190 sal_Bool KabConditionOr::isAlwaysFalse() const
192 return m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse();
194 // -----------------------------------------------------------------------------
195 sal_Bool KabConditionOr::eval(const ::KABC::Addressee &aAddressee) const
197 // We avoid evaluating terms as much as we can
198 if (m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue()) return sal_True;
199 if (m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse()) return sal_False;
201 if (m_pLeft->eval(aAddressee)) return sal_True;
202 if (m_pRight->eval(aAddressee)) return sal_True;
204 return sal_False;
206 // -----------------------------------------------------------------------------
207 KabConditionAnd::KabConditionAnd(KabCondition *pLeft, KabCondition *pRight)
208 : KabConditionBoolean(pLeft, pRight)
211 // -----------------------------------------------------------------------------
212 sal_Bool KabConditionAnd::isAlwaysTrue() const
214 return m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue();
216 // -----------------------------------------------------------------------------
217 sal_Bool KabConditionAnd::isAlwaysFalse() const
219 return m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse();
221 // -----------------------------------------------------------------------------
222 sal_Bool KabConditionAnd::eval(const ::KABC::Addressee &aAddressee) const
224 // We avoid evaluating terms as much as we can
225 if (m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse()) return sal_False;
226 if (m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue()) return sal_True;
228 if (!m_pLeft->eval(aAddressee)) return sal_False;
229 if (!m_pRight->eval(aAddressee)) return sal_False;
231 return sal_True;