1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macabcondition.cxx,v $
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 "macabcondition.hxx"
35 #include "MacabHeader.hxx"
36 #include "MacabRecord.hxx"
37 #include "connectivity/CommonTools.hxx"
39 using namespace ::connectivity::macab
;
40 using namespace ::com::sun::star::sdbc
;
41 // -----------------------------------------------------------------------------
42 MacabCondition::~MacabCondition()
45 // -----------------------------------------------------------------------------
46 MacabConditionConstant::MacabConditionConstant(const sal_Bool bValue
)
51 // -----------------------------------------------------------------------------
52 sal_Bool
MacabConditionConstant::isAlwaysTrue() const
56 // -----------------------------------------------------------------------------
57 sal_Bool
MacabConditionConstant::isAlwaysFalse() const
61 // -----------------------------------------------------------------------------
62 sal_Bool
MacabConditionConstant::eval(const MacabRecord
*) const
66 // -----------------------------------------------------------------------------
67 MacabConditionColumn::MacabConditionColumn(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
) throw(SQLException
)
69 m_nFieldNumber(header
->getColumnNumber(sColumnName
))
72 // -----------------------------------------------------------------------------
73 sal_Bool
MacabConditionColumn::isAlwaysTrue() const
75 // Sometimes true, sometimes false
78 // -----------------------------------------------------------------------------
79 sal_Bool
MacabConditionColumn::isAlwaysFalse() const
81 // Sometimes true, sometimes false
84 // -----------------------------------------------------------------------------
85 MacabConditionNull::MacabConditionNull(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
) throw(SQLException
)
86 : MacabConditionColumn(header
, sColumnName
)
89 // -----------------------------------------------------------------------------
90 sal_Bool
MacabConditionNull::eval(const MacabRecord
*aRecord
) const
92 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
96 else if(aValue
->value
== NULL
)
101 // -----------------------------------------------------------------------------
102 MacabConditionNotNull::MacabConditionNotNull(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
) throw(SQLException
)
103 : MacabConditionColumn(header
, sColumnName
)
106 // -----------------------------------------------------------------------------
107 sal_Bool
MacabConditionNotNull::eval(const MacabRecord
*aRecord
) const
109 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
113 else if(aValue
->value
== NULL
)
118 // -----------------------------------------------------------------------------
119 MacabConditionCompare::MacabConditionCompare(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
, const ::rtl::OUString
&sMatchString
) throw(SQLException
)
120 : MacabConditionColumn(header
, sColumnName
),
121 m_sMatchString(sMatchString
)
124 // -----------------------------------------------------------------------------
125 MacabConditionEqual::MacabConditionEqual(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
, const ::rtl::OUString
&sMatchString
) throw(SQLException
)
126 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
129 // -----------------------------------------------------------------------------
130 sal_Bool
MacabConditionEqual::eval(const MacabRecord
*aRecord
) const
132 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
137 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
142 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
147 // -----------------------------------------------------------------------------
148 MacabConditionDifferent::MacabConditionDifferent(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
, const ::rtl::OUString
&sMatchString
) throw(SQLException
)
149 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
152 // -----------------------------------------------------------------------------
153 sal_Bool
MacabConditionDifferent::eval(const MacabRecord
*aRecord
) const
155 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
160 macabfield
*aValue2
= MacabRecord::createMacabField(m_sMatchString
,aValue
->type
);
165 sal_Int32 nReturn
= MacabRecord::compareFields(aValue
, aValue2
);
170 // -----------------------------------------------------------------------------
171 MacabConditionSimilar::MacabConditionSimilar(const MacabHeader
*header
, const ::rtl::OUString
&sColumnName
, const ::rtl::OUString
&sMatchString
) throw(SQLException
)
172 : MacabConditionCompare(header
, sColumnName
, sMatchString
)
175 // -----------------------------------------------------------------------------
176 sal_Bool
MacabConditionSimilar::eval(const MacabRecord
*aRecord
) const
178 macabfield
*aValue
= aRecord
->get(m_nFieldNumber
);
183 ::rtl::OUString sName
= MacabRecord::fieldToString(aValue
);
185 return match(m_sMatchString
, sName
, '\0');
187 // -----------------------------------------------------------------------------
188 MacabConditionBoolean::MacabConditionBoolean(MacabCondition
*pLeft
, MacabCondition
*pRight
)
194 // -----------------------------------------------------------------------------
195 MacabConditionBoolean::~MacabConditionBoolean()
200 // -----------------------------------------------------------------------------
201 MacabConditionOr::MacabConditionOr(MacabCondition
*pLeft
, MacabCondition
*pRight
)
202 : MacabConditionBoolean(pLeft
, pRight
)
205 // -----------------------------------------------------------------------------
206 sal_Bool
MacabConditionOr::isAlwaysTrue() const
208 return m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue();
210 // -----------------------------------------------------------------------------
211 sal_Bool
MacabConditionOr::isAlwaysFalse() const
213 return m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse();
215 // -----------------------------------------------------------------------------
216 sal_Bool
MacabConditionOr::eval(const MacabRecord
*aRecord
) const
218 // We avoid evaluating terms as much as we can
219 if (m_pLeft
->isAlwaysTrue() || m_pRight
->isAlwaysTrue()) return sal_True
;
220 if (m_pLeft
->isAlwaysFalse() && m_pRight
->isAlwaysFalse()) return sal_False
;
222 if (m_pLeft
->eval(aRecord
)) return sal_True
;
223 if (m_pRight
->eval(aRecord
)) return sal_True
;
227 // -----------------------------------------------------------------------------
228 MacabConditionAnd::MacabConditionAnd(MacabCondition
*pLeft
, MacabCondition
*pRight
)
229 : MacabConditionBoolean(pLeft
, pRight
)
232 // -----------------------------------------------------------------------------
233 sal_Bool
MacabConditionAnd::isAlwaysTrue() const
235 return m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue();
237 // -----------------------------------------------------------------------------
238 sal_Bool
MacabConditionAnd::isAlwaysFalse() const
240 return m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse();
242 // -----------------------------------------------------------------------------
243 sal_Bool
MacabConditionAnd::eval(const MacabRecord
*aRecord
) const
245 // We avoid evaluating terms as much as we can
246 if (m_pLeft
->isAlwaysFalse() || m_pRight
->isAlwaysFalse()) return sal_False
;
247 if (m_pLeft
->isAlwaysTrue() && m_pRight
->isAlwaysTrue()) return sal_True
;
249 if (!m_pLeft
->eval(aRecord
)) return sal_False
;
250 if (!m_pRight
->eval(aRecord
)) return sal_False
;