build fix
[LibreOffice.git] / connectivity / source / drivers / mork / MQueryHelper.hxx
blob1871b4591e77b966a7ab46d11e5859f617fe07c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
28 namespace mork
30 class OConnection;
31 class MQueryHelper;
32 class ErrorDescriptor;
34 namespace MQueryOp {
35 typedef enum {
36 Exists = 0,
37 DoesNotExist = 1,
38 Contains = 2,
39 DoesNotContain = 3,
40 Is = 4,
41 IsNot = 5,
42 BeginsWith = 6,
43 EndsWith = 7,
44 RegExp = 8
45 } cond_type;
48 class MQueryExpressionBase {
49 public:
50 typedef enum {
51 Unknown,
52 StringExpr,
53 Expr
54 } node_type;
56 protected:
57 node_type m_eNodeType;
59 explicit MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {}
61 public:
62 virtual ~MQueryExpressionBase() {}
64 bool isStringExpr( ) const { return m_eNodeType == StringExpr; }
65 bool isExpr( ) const { return m_eNodeType == Expr; }
68 class MQueryExpressionString : public MQueryExpressionBase {
69 protected:
70 OUString m_aName; // LHS
71 MQueryOp::cond_type m_aBooleanCondition;
72 OUString m_aValue; // RHS
74 public:
76 MQueryExpressionString( const OUString& lhs,
77 MQueryOp::cond_type cond,
78 const OUString& rhs )
79 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
80 , m_aName( lhs )
81 , m_aBooleanCondition( cond )
82 , m_aValue( rhs )
86 MQueryExpressionString( const OUString& lhs,
87 MQueryOp::cond_type cond )
88 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
89 , m_aName( lhs )
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;
104 public:
105 typedef ::std::vector< MQueryExpressionBase* > ExprVector;
107 typedef enum {
108 AND,
110 } bool_cond;
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)
134 delete *i;
138 protected:
139 ExprVector m_aExprVector;
140 bool_cond m_aExprCondType;
142 private:
143 MQueryExpression(const MQueryExpression&) = delete;
144 MQueryExpression& operator=(const MQueryExpression&) = delete;
147 class MQueryHelperResultEntry
149 private:
150 typedef std::unordered_map< OString, OUString, OStringHash > FieldMap;
152 FieldMap m_Fields;
154 public:
155 MQueryHelperResultEntry();
156 ~MQueryHelperResultEntry();
158 OUString getValue( const OString &key ) const;
159 void setValue( const OString &key, const OUString & rValue);
162 class MQueryHelper final
164 private:
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;
175 public:
176 explicit MQueryHelper(const OColumnAlias& _ca);
177 ~MQueryHelper();
179 void reset();
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: */