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 <sal/types.h>
24 #include <rtl/ustring.hxx>
25 #include <osl/mutex.hxx>
26 #include <osl/conditn.hxx>
27 #include <osl/thread.hxx>
28 #include <connectivity/FValue.hxx>
30 #include <boost/unordered_map.hpp>
32 #include "MErrorResource.hxx"
34 namespace connectivity
40 class ErrorDescriptor
;
56 class MQueryExpressionBase
{
65 node_type m_eNodeType
;
67 MQueryExpressionBase() : m_eNodeType( Unknown
) {}
68 MQueryExpressionBase( node_type _eNodeType
) : m_eNodeType( _eNodeType
) {}
71 bool isUnknown( ) const { return m_eNodeType
== Unknown
; }
72 bool isStringExpr( ) const { return m_eNodeType
== StringExpr
; }
73 bool isExpr( ) const { return m_eNodeType
== Expr
; }
76 class MQueryExpressionString
: public MQueryExpressionBase
{
78 OUString m_aName
; // LHS
79 MQueryOp::cond_type m_aBooleanCondition
;
80 OUString m_aValue
; // RHS
84 MQueryExpressionString( const OUString
& lhs
,
85 MQueryOp::cond_type cond
,
87 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
89 , m_aBooleanCondition( cond
)
94 MQueryExpressionString( const OUString
& lhs
,
95 MQueryOp::cond_type cond
)
96 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
98 , m_aBooleanCondition( cond
)
99 , m_aValue( OUString() )
103 const OUString
& getName() const { return m_aName
; }
104 MQueryOp::cond_type
getCond() const { return m_aBooleanCondition
; }
105 const OUString
& getValue() const { return m_aValue
; }
108 class MQueryExpression
: public MQueryExpressionBase
110 friend class MQueryHelper
;
113 typedef ::std::vector
< MQueryExpressionBase
* > ExprVector
;
120 void setExpressions( ExprVector
& _exprVector
)
121 { m_aExprVector
= _exprVector
; }
123 // All expressions on a peer level use same condition operator
124 void setExpressionCondition( bool_cond _cond
)
125 { m_aExprCondType
= _cond
; }
127 ExprVector
& getExpressions( )
128 { return m_aExprVector
; }
130 // All expressions on a peer level use same condition operator
131 bool_cond
getExpressionCondition( ) const
132 { return m_aExprCondType
; }
134 MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::Expr
),
135 m_aExprCondType( OR
)
136 { m_aExprVector
.clear(); }
140 ExprVector m_aExprVector
;
141 bool_cond m_aExprCondType
;
145 class MQueryHelperResultEntry
148 typedef ::boost::unordered_map
< OString
, OUString
, OStringHash
> FieldMap
;
150 mutable ::osl::Mutex m_aMutex
;
154 MQueryHelperResultEntry();
155 ~MQueryHelperResultEntry();
157 OUString
getValue( const OString
&key
) const;
158 void setValue( const OString
&key
, const OUString
& rValue
);
164 typedef std::vector
< MQueryHelperResultEntry
* > resultsArray
;
166 mutable ::osl::Mutex m_aMutex
;
167 ::osl::Condition m_aCondition
;
168 resultsArray m_aResults
;
172 void append(MQueryHelperResultEntry
* resEnt
);
173 void clear_results();
174 OColumnAlias m_rColumnAlias
;
175 ErrorDescriptor m_aError
;
176 OUString m_aAddressbook
;
177 MQueryExpression m_aExpr
;
180 void clearResultOrComplete();
181 void notifyResultOrComplete();
182 sal_Bool waitForResultOrComplete( );
183 void getCardValues(nsIAbCard *card,sal_uInt32 rowIndex=0);
186 sal_Int32
doQueryDefaultTable(OConnection
* xConnection
);
187 sal_Int32
doQueryListTable(OConnection
* xConnection
, OString
& ouStringTable
);
190 MQueryHelper(const OColumnAlias
& _ca
);
191 virtual ~MQueryHelper();
194 MQueryHelperResultEntry
* getByIndex( sal_uInt32 nRow
);
195 bool isError() const;
196 bool queryComplete() const;
197 sal_Int32
getResultCount() const;
198 bool checkRowAvailable( sal_Int32 nDBRow
);
199 bool getRowValue( ORowSetValue
& rValue
, sal_Int32 nDBRow
,const OUString
& aDBColumnName
, sal_Int32 nType
);
200 sal_Int32
executeQuery(OConnection
* xConnection
);
201 const OColumnAlias
& getColumnAlias() const { return m_rColumnAlias
; }
202 bool hadError() const { return m_aError
.is(); }
203 inline ErrorDescriptor
& getError() { return m_aError
; }
205 void setAddressbook( OUString
&);
206 void setExpression( MQueryExpression
&_expr
);
212 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */