1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
44 namespace connectivity
50 struct MQueryDirectory
;
67 class MQueryExpressionBase
{
76 node_type m_eNodeType
;
78 MQueryExpressionBase() : m_eNodeType( Unknown
) {}
79 MQueryExpressionBase( node_type _eNodeType
) : m_eNodeType( _eNodeType
) {}
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
{
89 ::rtl::OUString m_aName
; // LHS
90 MQueryOp::cond_type m_aBooleanCondition
;
91 ::rtl::OUString m_aValue
; // RHS
95 MQueryExpressionString( ::rtl::OUString
& lhs
,
96 MQueryOp::cond_type cond
,
98 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
100 , m_aBooleanCondition( cond
)
105 MQueryExpressionString( ::rtl::OUString
& lhs
,
106 MQueryOp::cond_type cond
)
107 : MQueryExpressionBase( MQueryExpressionBase::StringExpr
)
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
; }
121 class MQueryExpression
: public MQueryExpressionBase
126 typedef ::std::vector
< MQueryExpressionBase
* > ExprVector
;
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(); }
153 ExprVector m_aExprVector
;
154 bool_cond m_aExprCondType
;
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.
176 * m_aSqlOppr contains the SQL operations for every
177 * attribute in m_aAttributes.
178 * This member must be initialised together with
181 * The SQL operations defined for 'SQL_OPR' are:
183 * matchDoesNotExist = 1,
185 * matchDoesNotContain = 3,
188 * matchBeginsWith = 6,
190 * matchSoundsLike = 8,
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'.
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
215 ::rtl::OUString m_Profile
;
216 ErrorDescriptor m_aError
;
220 ::osl::Mutex m_aMutex
;
221 #if OSL_DEBUG_LEVEL > 0
222 oslThreadIdentifier m_oThreadID
;
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
,
262 const rtl::OUString
& aDBColumnName
,
263 sal_Int32 nType
) const;
264 sal_Bool
setRowValue( connectivity::ORowSetValue
& rValue
,
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
; }
276 MQuery( const OColumnAlias
& _ca
);
278 static MNameMapper
* CreateNameMapper();
279 static void FreeNameMapper( MNameMapper
* _ptr
);
284 #endif // _CONNECTIVITY_MAB_QUERY_HXX_