merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / mozab / mozillasrc / MQuery.hxx
blob685f8e31523ad3312b1d009f3edaadf7425844c8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MQuery.hxx,v $
10 * $Revision: 1.16.66.1 $
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 ************************************************************************/
32 #ifndef _CONNECTIVITY_MAB_QUERY_HXX_
33 #define _CONNECTIVITY_MAB_QUERY_HXX_
35 #include "MColumnAlias.hxx"
36 #include "MErrorResource.hxx"
37 #include <connectivity/FValue.hxx>
38 #include "MNSDeclares.hxx"
39 #include <osl/thread.hxx>
40 #ifndef _COM_SUN_STAR_MOZILLA_MOZILLPRODUCTTYPE_HPP_
41 #include <com/sun/star/mozilla/MozillaProductType.hpp>
42 #endif
44 namespace connectivity
46 namespace mozab
49 class MQueryHelper;
50 struct MQueryDirectory;
52 namespace MQueryOp {
53 typedef enum {
54 Exists = 0,
55 DoesNotExist = 1,
56 Contains = 2,
57 DoesNotContain = 3,
58 Is = 4,
59 IsNot = 5,
60 BeginsWith = 6,
61 EndsWith = 7,
62 SoundsLike = 8,
63 RegExp = 9
64 } cond_type;
67 class MQueryExpressionBase {
68 public:
69 typedef enum {
70 Unknown,
71 StringExpr,
72 Expr
73 } node_type;
75 protected:
76 node_type m_eNodeType;
78 MQueryExpressionBase() : m_eNodeType( Unknown ) {}
79 MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {}
81 public:
82 sal_Bool isUnknown( ) { return m_eNodeType == Unknown; }
83 sal_Bool isStringExpr( ) { return m_eNodeType == StringExpr; }
84 sal_Bool isExpr( ) { return m_eNodeType == Expr; }
87 class MQueryExpressionString : public MQueryExpressionBase {
88 protected:
89 ::rtl::OUString m_aName; // LHS
90 MQueryOp::cond_type m_aBooleanCondition;
91 ::rtl::OUString m_aValue; // RHS
93 public:
95 MQueryExpressionString( ::rtl::OUString& lhs,
96 MQueryOp::cond_type cond,
97 ::rtl::OUString rhs )
98 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
99 , m_aName( lhs )
100 , m_aBooleanCondition( cond )
101 , m_aValue( rhs )
105 MQueryExpressionString( ::rtl::OUString& lhs,
106 MQueryOp::cond_type cond )
107 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
108 , m_aName( lhs )
109 , m_aBooleanCondition( cond )
110 , m_aValue( ::rtl::OUString() )
114 const ::rtl::OUString& getName() const { return m_aName; }
115 MQueryOp::cond_type getCond() const { return m_aBooleanCondition; }
116 const ::rtl::OUString& getValue() const { return m_aValue; }
119 class MQuery;
121 class MQueryExpression : public MQueryExpressionBase
123 friend class MQuery;
125 public:
126 typedef ::std::vector< MQueryExpressionBase* > ExprVector;
128 typedef enum {
129 AND,
131 } bool_cond;
133 void setExpressions( ExprVector& _exprVector )
134 { m_aExprVector = _exprVector; }
136 // All expressions on a peer level use same condition operator
137 void setExpressionCondition( bool_cond _cond )
138 { m_aExprCondType = _cond; }
140 ExprVector& getExpressions( )
141 { return m_aExprVector; }
143 // All expressions on a peer level use same condition operator
144 bool_cond getExpressionCondition( )
145 { return m_aExprCondType; }
147 MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::Expr ),
148 m_aExprCondType( OR )
149 { m_aExprVector.clear(); }
152 protected:
153 ExprVector m_aExprVector;
154 bool_cond m_aExprCondType;
159 class MQuery
162 * A query resultset with a maximum limit of
163 * m_nMaxNrOfReturns return items, is created from
164 * the following SQL statement:
166 * -------------------------------------------------
167 * SELECT m_aAttributes FROM m_aAddressbook
168 * WHERE m_aMatchItems SQL_OPR m_aMatchValue
169 * -------------------------------------------------
171 * We are\are not, depending on boolean m_bQuerySubDirs,
172 * interested in querying the sub-directories of the
173 * addressbook directory, if any.
175 * SQL_OPR:
176 * m_aSqlOppr contains the SQL operations for every
177 * attribute in m_aAttributes.
178 * This member must be initialised together with
179 * m_aAttributes.
181 * The SQL operations defined for 'SQL_OPR' are:
182 * matchExists = 0,
183 * matchDoesNotExist = 1,
184 * matchContains = 2,
185 * matchDoesNotContain = 3,
186 * matchIs = 4,
187 * matchIsNot = 5,
188 * matchBeginsWith = 6,
189 * matchEndsWith = 7,
190 * matchSoundsLike = 8,
191 * matchRegExp = 9.
192 * There must be mapping to one of these values.
194 * The following members MUST be initialised before
195 * a query is executed:
196 * m_Attributes, m_aMapAttrOppr, m_aAddressbook,
197 * m_aMatchItems and m_aMatchValue.
199 * m_bQuerySubDirs and m_nMaxNrReturns are set to a
200 * default value in the constructor which can be
201 * overridden. If (element of) m_aSqlOppr is not set,
202 * the default SQL operation is 'matchIs'.
205 private:
206 MQueryDirectory *m_aQueryDirectory;
207 MQueryHelper *m_aQueryHelper;
208 ::rtl::OUString m_aAddressbook;
209 sal_Int32 m_nMaxNrOfReturns;
210 sal_Bool m_bQuerySubDirs;
211 MQueryExpression m_aExpr;
212 const OColumnAlias& m_rColumnAlias;
213 ::com::sun::star::mozilla::MozillaProductType
214 m_Product;
215 ::rtl::OUString m_Profile;
216 ErrorDescriptor m_aError;
218 void construct();
219 protected:
220 ::osl::Mutex m_aMutex;
221 #if OSL_DEBUG_LEVEL > 0
222 oslThreadIdentifier m_oThreadID;
223 #endif
225 public:
227 * - Contains accessors to the members of this class.
228 * - executeQuery() initiates a non-blocking query.
230 sal_Int32 executeQuery(OConnection* _pCon);
231 sal_Int32 executeQueryProxied(OConnection* _pCon); //Used only by MNSMozabProxy
233 sal_Int32 createNewCard(); //return Row count number
234 sal_Int32 deleteRow(const sal_Int32 rowIndex);
235 sal_Int32 commitRow(const sal_Int32 rowIndex);
236 sal_Bool resyncRow(sal_Int32 nDBRow);
238 sal_Bool isWritable(OConnection* _pCon);
240 sal_uInt32 InsertLoginInfo(OConnection* _pCon);
242 void setAddressbook( ::rtl::OUString&);
243 ::rtl::OUString getAddressbook(void) const;
245 const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; }
247 void setExpression( MQueryExpression &_expr );
249 void setMaxNrOfReturns( const sal_Int32);
250 sal_Int32 getMaxNrOfReturns(void) const;
252 void setQuerySubDirs( sal_Bool&);
253 sal_Bool getQuerySubDirs(void) const;
255 sal_Int32 getRowCount( void );
256 sal_uInt32 getRealRowCount( void );
257 sal_Bool queryComplete( void );
258 sal_Bool waitForQueryComplete( void );
259 sal_Bool checkRowAvailable( sal_Int32 nDBRow );
260 sal_Bool getRowValue( connectivity::ORowSetValue& rValue,
261 sal_Int32 nDBRow,
262 const rtl::OUString& aDBColumnName,
263 sal_Int32 nType ) const;
264 sal_Bool setRowValue( connectivity::ORowSetValue& rValue,
265 sal_Int32 nDBRow,
266 const rtl::OUString& aDBColumnName,
267 sal_Int32 nType ) const;
268 sal_Int32 getRowStates(sal_Int32 nDBRow);
269 sal_Bool setRowStates(sal_Int32 nDBRow,sal_Int32 aState);
271 bool hadError() const { return m_aError.is(); }
272 inline const ErrorDescriptor& getError() const { return m_aError; }
274 public:
275 // MQuery();
276 MQuery( const OColumnAlias& _ca );
277 virtual ~MQuery();
278 static MNameMapper* CreateNameMapper();
279 static void FreeNameMapper( MNameMapper* _ptr );
284 #endif // _CONNECTIVITY_MAB_QUERY_HXX_