1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "macabcondition.hxx"
22 #include "MacabHeader.hxx"
23 #include "MacabRecord.hxx"
24 #include "connectivity/CommonTools.hxx"
26 using namespace ::connectivity::macab
;
27 using namespace ::com::sun::star::sdbc
;
29 MacabCondition::~MacabCondition()
33 MacabConditionConstant::MacabConditionConstant(const sal_Bool bValue
)
39 sal_Bool
MacabConditionConstant::isAlwaysTrue() const
44 sal_Bool
MacabConditionConstant::isAlwaysFalse() const
49 sal_Bool
MacabConditionConstant::eval(const MacabRecord
*) const
54 MacabConditionColumn::MacabConditionColumn(const MacabHeader
*header
, const OUString
&sColumnName
) throw(SQLException
)
56 m_nFieldNumber(header
->getColumnNumber(sColumnName
))
60 sal_Bool
MacabConditionColumn::isAlwaysTrue() const
62 // Sometimes true, sometimes false
66 sal_Bool
MacabConditionColumn::isAlwaysFalse() const
68 // Sometimes true, sometimes false
72 MacabConditionNull::MacabConditionNull(const MacabHeader
*header
, const OUString
&sColumnName
) throw(SQLException
)
73 : MacabConditionColumn(header
, sColumnName
)
77 sal_Bool
MacabConditionNull::eval(const MacabRecord
*aRecord
) const
79 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
83 else if(aValue
->value
== NULL
)
89 MacabConditionNotNull::MacabConditionNotNull(const MacabHeader
*header
, const OUString
&sColumnName
) throw(SQLException
)
90 : MacabConditionColumn(header
, sColumnName
)
94 sal_Bool
MacabConditionNotNull::eval(const MacabRecord
*aRecord
) const
96 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
100 else if(aValue
->value
== NULL
)
106 MacabConditionCompare::MacabConditionCompare(const MacabHeader
*header
, const OUString
&sColumnName
, const OUString
&sMatchString
) throw(SQLException
)
107 : MacabConditionColumn(header
, sColumnName
),
108 m_sMatchString(sMatchString
)
112 MacabConditionEqual::MacabConditionEqual(const MacabHeader
*header
, const OUString
&sColumnName
, const OUString
&sMatchString
) throw(SQLException
)
113 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
117 sal_Bool
MacabConditionEqual::eval(const MacabRecord
*aRecord
) const
119 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
124 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
129 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
135 MacabConditionDifferent::MacabConditionDifferent(const MacabHeader
*header
, const OUString
&sColumnName
, const OUString
&sMatchString
) throw(SQLException
)
136 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
140 sal_Bool
MacabConditionDifferent::eval(const MacabRecord
*aRecord
) const
142 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
147 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
152 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
158 MacabConditionSimilar::MacabConditionSimilar(const MacabHeader
*header
, const OUString
&sColumnName
, const OUString
&sMatchString
) throw(SQLException
)
159 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
163 sal_Bool
MacabConditionSimilar::eval(const MacabRecord
*aRecord
) const
165 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
170 OUString sName
= MacabRecord::fieldToString(aValue
);
172 return match(m_sMatchString
, sName
, '\0');
175 MacabConditionBoolean::MacabConditionBoolean(MacabCondition
*pLeft
, MacabCondition
*pRight
)
182 MacabConditionBoolean::~MacabConditionBoolean()
188 MacabConditionOr::MacabConditionOr(MacabCondition
*pLeft
, MacabCondition
*pRight
)
189 : MacabConditionBoolean(pLeft
, pRight
)
193 sal_Bool
MacabConditionOr::isAlwaysTrue() const
195 return m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue();
198 sal_Bool
MacabConditionOr::isAlwaysFalse() const
200 return m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse();
203 sal_Bool
MacabConditionOr::eval(const MacabRecord
*aRecord
) const
205 // We avoid evaluating terms as much as we can
206 if (m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue()) return sal_True
;
207 if (m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse()) return sal_False
;
209 if (m_pLeft
->eval(aRecord
)) return sal_True
;
210 if (m_pRight
->eval(aRecord
)) return sal_True
;
215 MacabConditionAnd::MacabConditionAnd(MacabCondition
*pLeft
, MacabCondition
*pRight
)
216 : MacabConditionBoolean(pLeft
, pRight
)
220 sal_Bool
MacabConditionAnd::isAlwaysTrue() const
222 return m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue();
225 sal_Bool
MacabConditionAnd::isAlwaysFalse() const
227 return m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse();
230 sal_Bool
MacabConditionAnd::eval(const MacabRecord
*aRecord
) const
232 // We avoid evaluating terms as much as we can
233 if (m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse()) return sal_False
;
234 if (m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue()) return sal_True
;
236 if (!m_pLeft
->eval(aRecord
)) return sal_False
;
237 if (!m_pRight
->eval(aRecord
)) return sal_False
;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */