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 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
22 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
24 #include "MColumnAlias.hxx"
25 #include "MErrorResource.hxx"
26 #include <connectivity/FValue.hxx>
27 #include "MNSDeclares.hxx"
28 #include <osl/thread.hxx>
29 #include <com/sun/star/mozilla/MozillaProductType.hpp>
31 namespace connectivity
37 struct MQueryDirectory
;
54 class MQueryExpressionBase
{
63 node_type m_eNodeType
;
65 MQueryExpressionBase() : m_eNodeType( Unknown
) {}
66 MQueryExpressionBase( node_type _eNodeType
) : m_eNodeType( _eNodeType
) {}
69 sal_Bool
isUnknown( ) const { return m_eNodeType
== Unknown
; }
70 sal_Bool
isStringExpr( ) const { return m_eNodeType
== StringExpr
; }
71 sal_Bool
isExpr( ) const { return m_eNodeType
== Expr
; }
74 class MQueryExpressionString
: public MQueryExpressionBase
{
76 OUString m_aName
; // LHS
77 MQueryOp::cond_type m_aBooleanCondition
;
78 OUString m_aValue
; // RHS
82 MQueryExpressionString( OUString
& lhs
,
83 MQueryOp::cond_type cond
,
85 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
87 , m_aBooleanCondition( cond
)
92 MQueryExpressionString( OUString
& lhs
,
93 MQueryOp::cond_type cond
)
94 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
96 , m_aBooleanCondition( cond
)
97 , m_aValue( OUString() )
101 const OUString
& getName() const { return m_aName
; }
102 MQueryOp::cond_type
getCond() const { return m_aBooleanCondition
; }
103 const OUString
& getValue() const { return m_aValue
; }
108 class MQueryExpression
: public MQueryExpressionBase
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
;
149 * A query resultset with a maximum limit of
150 * m_nMaxNrOfReturns return items, is created from
151 * the following SQL statement:
153 * -------------------------------------------------
154 * SELECT m_aAttributes FROM m_aAddressbook
155 * WHERE m_aMatchItems SQL_OPR m_aMatchValue
156 * -------------------------------------------------
158 * We are\are not, depending on boolean m_bQuerySubDirs,
159 * interested in querying the sub-directories of the
160 * addressbook directory, if any.
163 * m_aSqlOppr contains the SQL operations for every
164 * attribute in m_aAttributes.
165 * This member must be initialised together with
168 * The SQL operations defined for 'SQL_OPR' are:
170 * matchDoesNotExist = 1,
172 * matchDoesNotContain = 3,
175 * matchBeginsWith = 6,
177 * matchSoundsLike = 8,
179 * There must be mapping to one of these values.
181 * The following members MUST be initialised before
182 * a query is executed:
183 * m_Attributes, m_aMapAttrOppr, m_aAddressbook,
184 * m_aMatchItems and m_aMatchValue.
186 * m_bQuerySubDirs and m_nMaxNrReturns are set to a
187 * default value in the constructor which can be
188 * overridden. If (element of) m_aSqlOppr is not set,
189 * the default SQL operation is 'matchIs'.
193 MQueryDirectory
*m_aQueryDirectory
;
194 MQueryHelper
*m_aQueryHelper
;
195 OUString m_aAddressbook
;
196 sal_Int32 m_nMaxNrOfReturns
;
197 sal_Bool m_bQuerySubDirs
;
198 MQueryExpression m_aExpr
;
199 const OColumnAlias
& m_rColumnAlias
;
200 ::com::sun::star::mozilla::MozillaProductType
203 ErrorDescriptor m_aError
;
207 ::osl::Mutex m_aMutex
;
208 #if OSL_DEBUG_LEVEL > 0
209 oslThreadIdentifier m_oThreadID
;
214 * - Contains accessors to the members of this class.
215 * - executeQuery() initiates a non-blocking query.
217 sal_Int32
executeQuery(OConnection
* _pCon
);
218 sal_Int32
executeQueryProxied(OConnection
* _pCon
); //Used only by MNSMozabProxy
220 sal_Int32
createNewCard(); //return Row count number
221 sal_Int32
deleteRow(const sal_Int32 rowIndex
);
222 sal_Int32
commitRow(const sal_Int32 rowIndex
);
223 sal_Bool
resyncRow(sal_Int32 nDBRow
);
225 sal_Bool
isWritable(OConnection
* _pCon
);
227 sal_uInt32
InsertLoginInfo(OConnection
* _pCon
);
229 void setAddressbook( OUString
&);
231 const OColumnAlias
& getColumnAlias() const { return m_rColumnAlias
; }
233 void setExpression( MQueryExpression
&_expr
);
235 void setMaxNrOfReturns( const sal_Int32
);
237 sal_Int32
getRowCount( void );
238 sal_uInt32
getRealRowCount( void );
239 sal_Bool
queryComplete( void );
240 sal_Bool
waitForQueryComplete( void );
241 sal_Bool
checkRowAvailable( sal_Int32 nDBRow
);
242 sal_Bool
getRowValue( connectivity::ORowSetValue
& rValue
,
244 const OUString
& aDBColumnName
,
245 sal_Int32 nType
) const;
246 sal_Bool
setRowValue( connectivity::ORowSetValue
& rValue
,
248 const OUString
& aDBColumnName
,
249 sal_Int32 nType
) const;
250 sal_Int32
getRowStates(sal_Int32 nDBRow
);
251 sal_Bool
setRowStates(sal_Int32 nDBRow
,sal_Int32 aState
);
253 bool hadError() const { return m_aError
.is(); }
254 inline const ErrorDescriptor
& getError() const { return m_aError
; }
258 MQuery( const OColumnAlias
& _ca
);
260 static MNameMapper
* CreateNameMapper();
261 static void FreeNameMapper( MNameMapper
* _ptr
);
266 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */