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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
23 #include <connectivity/FValue.hxx>
24 #include "MErrorResource.hxx"
26 namespace connectivity
32 class ErrorDescriptor
;
48 class MQueryExpressionBase
{
57 node_type m_eNodeType
;
59 explicit MQueryExpressionBase( node_type _eNodeType
) : m_eNodeType( _eNodeType
) {}
62 virtual ~MQueryExpressionBase() {}
64 bool isStringExpr( ) const { return m_eNodeType
== StringExpr
; }
65 bool isExpr( ) const { return m_eNodeType
== Expr
; }
68 class MQueryExpressionString
: public MQueryExpressionBase
{
70 OUString m_aName
; // LHS
71 MQueryOp::cond_type m_aBooleanCondition
;
72 OUString m_aValue
; // RHS
76 MQueryExpressionString( const OUString
& lhs
,
77 MQueryOp::cond_type cond
,
79 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
81 , m_aBooleanCondition( cond
)
86 MQueryExpressionString( const OUString
& lhs
,
87 MQueryOp::cond_type cond
)
88 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
90 , m_aBooleanCondition( cond
)
91 , m_aValue( OUString() )
95 const OUString
& getName() const { return m_aName
; }
96 MQueryOp::cond_type
getCond() const { return m_aBooleanCondition
; }
97 const OUString
& getValue() const { return m_aValue
; }
100 class MQueryExpression
: public MQueryExpressionBase
102 friend class MQueryHelper
;
105 typedef ::std::vector
< MQueryExpressionBase
* > ExprVector
;
112 // All expressions on a peer level use same condition operator
113 void setExpressionCondition( bool_cond _cond
)
114 { m_aExprCondType
= _cond
; }
116 void addExpression(MQueryExpressionBase
* expr
)
117 { m_aExprVector
.push_back(expr
); }
119 ExprVector
const & getExpressions( ) const
120 { return m_aExprVector
; }
122 // All expressions on a peer level use same condition operator
123 bool_cond
getExpressionCondition( ) const
124 { return m_aExprCondType
; }
126 MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::Expr
),
127 m_aExprCondType( OR
)
130 virtual ~MQueryExpression() override
{
131 for (ExprVector::iterator
i(m_aExprVector
.begin());
132 i
!= m_aExprVector
.end(); ++i
)
139 ExprVector m_aExprVector
;
140 bool_cond m_aExprCondType
;
143 MQueryExpression(const MQueryExpression
&) = delete;
144 MQueryExpression
& operator=(const MQueryExpression
&) = delete;
147 class MQueryHelperResultEntry
150 typedef std::unordered_map
< OString
, OUString
, OStringHash
> FieldMap
;
155 MQueryHelperResultEntry();
156 ~MQueryHelperResultEntry();
158 OUString
getValue( const OString
&key
) const;
159 void setValue( const OString
&key
, const OUString
& rValue
);
162 class MQueryHelper final
165 typedef std::vector
< MQueryHelperResultEntry
* > resultsArray
;
167 mutable ::osl::Mutex m_aMutex
;
168 resultsArray m_aResults
;
169 void append(MQueryHelperResultEntry
* resEnt
);
170 void clear_results();
171 OColumnAlias m_rColumnAlias
;
172 ErrorDescriptor m_aError
;
173 OUString m_aAddressbook
;
176 explicit MQueryHelper(const OColumnAlias
& _ca
);
180 MQueryHelperResultEntry
* getByIndex( sal_uInt32 nRow
);
181 static bool queryComplete() { return true; }
182 sal_Int32
getResultCount() const;
183 bool checkRowAvailable( sal_Int32 nDBRow
);
184 bool getRowValue( ORowSetValue
& rValue
, sal_Int32 nDBRow
,const OUString
& aDBColumnName
, sal_Int32 nType
);
185 sal_Int32
executeQuery(OConnection
* xConnection
, MQueryExpression
& expr
);
186 const OColumnAlias
& getColumnAlias() const { return m_rColumnAlias
; }
187 bool hadError() const { return m_aError
.is(); }
188 inline ErrorDescriptor
& getError() { return m_aError
; }
190 void setAddressbook( OUString
&);
195 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */