1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "kcondition.hxx" 32*cdf0e10cSrcweir #include "kfields.hxx" 33*cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace ::connectivity::kab; 36*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 37*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 38*cdf0e10cSrcweir KabCondition::~KabCondition() 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir } 41*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 42*cdf0e10cSrcweir KabConditionConstant::KabConditionConstant(const sal_Bool bValue) 43*cdf0e10cSrcweir : KabCondition(), 44*cdf0e10cSrcweir m_bValue(bValue) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 48*cdf0e10cSrcweir sal_Bool KabConditionConstant::isAlwaysTrue() const 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir return m_bValue; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 53*cdf0e10cSrcweir sal_Bool KabConditionConstant::isAlwaysFalse() const 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir return !m_bValue; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 58*cdf0e10cSrcweir sal_Bool KabConditionConstant::eval(const ::KABC::Addressee &) const 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir return m_bValue; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 63*cdf0e10cSrcweir KabConditionColumn::KabConditionColumn(const ::rtl::OUString &sColumnName) throw(SQLException) 64*cdf0e10cSrcweir : KabCondition(), 65*cdf0e10cSrcweir m_nFieldNumber(findKabField(sColumnName)) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 69*cdf0e10cSrcweir sal_Bool KabConditionColumn::isAlwaysTrue() const 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir // Sometimes true, sometimes false 72*cdf0e10cSrcweir return sal_False; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 75*cdf0e10cSrcweir sal_Bool KabConditionColumn::isAlwaysFalse() const 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir // Sometimes true, sometimes false 78*cdf0e10cSrcweir return sal_False; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 81*cdf0e10cSrcweir KabConditionNull::KabConditionNull(const ::rtl::OUString &sColumnName) throw(SQLException) 82*cdf0e10cSrcweir : KabConditionColumn(sColumnName) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 86*cdf0e10cSrcweir sal_Bool KabConditionNull::eval(const ::KABC::Addressee &aAddressee) const 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir return aQtName.isNull(); 91*cdf0e10cSrcweir // KDE address book currently does not use NULL values. 92*cdf0e10cSrcweir // But it might do it someday 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 95*cdf0e10cSrcweir KabConditionNotNull::KabConditionNotNull(const ::rtl::OUString &sColumnName) throw(SQLException) 96*cdf0e10cSrcweir : KabConditionColumn(sColumnName) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 100*cdf0e10cSrcweir sal_Bool KabConditionNotNull::eval(const ::KABC::Addressee &aAddressee) const 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return !aQtName.isNull(); 105*cdf0e10cSrcweir // KDE address book currently does not use NULL values. 106*cdf0e10cSrcweir // But it might do it someday 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 109*cdf0e10cSrcweir KabConditionCompare::KabConditionCompare(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException) 110*cdf0e10cSrcweir : KabConditionColumn(sColumnName), 111*cdf0e10cSrcweir m_sMatchString(sMatchString) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 115*cdf0e10cSrcweir KabConditionEqual::KabConditionEqual(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException) 116*cdf0e10cSrcweir : KabConditionCompare(sColumnName, sMatchString) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 120*cdf0e10cSrcweir sal_Bool KabConditionEqual::eval(const ::KABC::Addressee &aAddressee) const 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber); 123*cdf0e10cSrcweir // Timestamps should not be compared according to their string value 124*cdf0e10cSrcweir // The syntax for such queries should be like 125*cdf0e10cSrcweir // {ts '2004-03-29 12:55:00.000000'} 126*cdf0e10cSrcweir // They should also support operators like '<' or '>=' 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if (aQtName.isNull()) return sal_False; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2()); 131*cdf0e10cSrcweir return sValue == m_sMatchString; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 134*cdf0e10cSrcweir KabConditionDifferent::KabConditionDifferent(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException) 135*cdf0e10cSrcweir : KabConditionCompare(sColumnName, sMatchString) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 139*cdf0e10cSrcweir sal_Bool KabConditionDifferent::eval(const ::KABC::Addressee &aAddressee) const 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir if (aQtName.isNull()) return sal_False; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2()); 146*cdf0e10cSrcweir return sValue != m_sMatchString; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 149*cdf0e10cSrcweir KabConditionSimilar::KabConditionSimilar(const ::rtl::OUString &sColumnName, const ::rtl::OUString &sMatchString) throw(SQLException) 150*cdf0e10cSrcweir : KabConditionCompare(sColumnName, sMatchString) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 154*cdf0e10cSrcweir sal_Bool KabConditionSimilar::eval(const ::KABC::Addressee &aAddressee) const 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if (aQtName.isNull()) return sal_False; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir ::rtl::OUString sValue((const sal_Unicode *) aQtName.ucs2()); 161*cdf0e10cSrcweir return match(m_sMatchString, sValue, '\0'); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 164*cdf0e10cSrcweir KabConditionBoolean::KabConditionBoolean(KabCondition *pLeft, KabCondition *pRight) 165*cdf0e10cSrcweir : KabCondition(), 166*cdf0e10cSrcweir m_pLeft(pLeft), 167*cdf0e10cSrcweir m_pRight(pRight) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 171*cdf0e10cSrcweir KabConditionBoolean::~KabConditionBoolean() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir delete m_pLeft; 174*cdf0e10cSrcweir delete m_pRight; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 177*cdf0e10cSrcweir KabConditionOr::KabConditionOr(KabCondition *pLeft, KabCondition *pRight) 178*cdf0e10cSrcweir : KabConditionBoolean(pLeft, pRight) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 182*cdf0e10cSrcweir sal_Bool KabConditionOr::isAlwaysTrue() const 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir return m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 187*cdf0e10cSrcweir sal_Bool KabConditionOr::isAlwaysFalse() const 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir return m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse(); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 192*cdf0e10cSrcweir sal_Bool KabConditionOr::eval(const ::KABC::Addressee &aAddressee) const 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir // We avoid evaluating terms as much as we can 195*cdf0e10cSrcweir if (m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue()) return sal_True; 196*cdf0e10cSrcweir if (m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse()) return sal_False; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if (m_pLeft->eval(aAddressee)) return sal_True; 199*cdf0e10cSrcweir if (m_pRight->eval(aAddressee)) return sal_True; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir return sal_False; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 204*cdf0e10cSrcweir KabConditionAnd::KabConditionAnd(KabCondition *pLeft, KabCondition *pRight) 205*cdf0e10cSrcweir : KabConditionBoolean(pLeft, pRight) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 209*cdf0e10cSrcweir sal_Bool KabConditionAnd::isAlwaysTrue() const 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir return m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue(); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 214*cdf0e10cSrcweir sal_Bool KabConditionAnd::isAlwaysFalse() const 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir return m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 219*cdf0e10cSrcweir sal_Bool KabConditionAnd::eval(const ::KABC::Addressee &aAddressee) const 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir // We avoid evaluating terms as much as we can 222*cdf0e10cSrcweir if (m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse()) return sal_False; 223*cdf0e10cSrcweir if (m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue()) return sal_True; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir if (!m_pLeft->eval(aAddressee)) return sal_False; 226*cdf0e10cSrcweir if (!m_pRight->eval(aAddressee)) return sal_False; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir return sal_True; 229*cdf0e10cSrcweir } 230