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_INC_ODBC_OSTATEMENT_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX
23 #include <com/sun/star/sdbc/XStatement.hpp>
24 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
25 #include <com/sun/star/sdbc/XMultipleResults.hpp>
26 #include <com/sun/star/sdbc/XBatchExecution.hpp>
27 #include <com/sun/star/sdbc/XCloseable.hpp>
28 #include <com/sun/star/sdbc/SQLWarning.hpp>
29 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
30 #include <com/sun/star/util/XCancellable.hpp>
31 #include <comphelper/proparrhlp.hxx>
32 #include <cppuhelper/compbase6.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <connectivity/CommonTools.hxx>
35 #include "odbc/OFunctions.hxx"
36 #include "odbc/OConnection.hxx"
37 #include "odbc/odbcbasedllapi.hxx"
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <comphelper/broadcasthelper.hxx>
42 namespace connectivity
47 typedef ::cppu::WeakComponentImplHelper6
< ::com::sun::star::sdbc::XStatement
,
48 ::com::sun::star::sdbc::XWarningsSupplier
,
49 ::com::sun::star::util::XCancellable
,
50 ::com::sun::star::sdbc::XCloseable
,
51 ::com::sun::star::sdbc::XGeneratedResultSet
,
52 ::com::sun::star::sdbc::XMultipleResults
> OStatement_BASE
;
56 //************ Class: java.sql.Statement
58 class OOO_DLLPUBLIC_ODBCBASE OStatement_Base
:
59 public comphelper::OBaseMutex
,
60 public OStatement_BASE
,
61 public ::cppu::OPropertySetHelper
,
62 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
65 ::com::sun::star::sdbc::SQLWarning m_aLastWarning
;
67 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
68 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XStatement
> m_xGeneratedStatement
;
71 ::std::list
< OUString
> m_aBatchList
;
72 OUString m_sSqlStatement
;
74 OConnection
* m_pConnection
;// The owning Connection object
75 SQLHANDLE m_aStatementHandle
;
76 SQLUSMALLINT
* m_pRowStatusArray
;
77 ::cppu::OBroadcastHelper
& rBHelper
;
81 sal_Int64
getQueryTimeOut() const;
82 sal_Int64
getMaxFieldSize() const;
83 sal_Int64
getMaxRows() const;
84 sal_Int32
getResultSetConcurrency() const;
85 sal_Int32
getResultSetType() const;
86 sal_Int32
getFetchDirection() const;
87 sal_Int32
getFetchSize() const;
88 OUString
getCursorName() const;
89 bool isUsingBookmarks() const;
90 bool getEscapeProcessing() const;
91 template < typename T
, SQLINTEGER BufferLength
> T
getStmtOption (SQLINTEGER fOption
, T dflt
= 0) const;
93 void setQueryTimeOut(sal_Int64 _par0
) ;
94 void setMaxFieldSize(sal_Int64 _par0
) ;
95 void setMaxRows(sal_Int64 _par0
) ;
96 void setFetchDirection(sal_Int32 _par0
) ;
97 void setFetchSize(sal_Int32 _par0
) ;
98 void setCursorName(const OUString
&_par0
);
99 void setEscapeProcessing( const bool _bEscapeProc
);
100 template < typename T
, SQLINTEGER BufferLength
> SQLRETURN
setStmtOption (SQLINTEGER fOption
, T value
) const;
102 void setResultSetConcurrency(sal_Int32 _par0
) ;
103 void setResultSetType(sal_Int32 _par0
) ;
104 void setUsingBookmarks(bool _bUseBookmark
) ;
106 void reset() throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
107 void clearMyResultSet() throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
108 void setWarning (const ::com::sun::star::sdbc::SQLWarning
&ex
)
109 throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
110 bool lockIfNecessary (const OUString
& sql
) throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
111 sal_Int32
getColumnCount() throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
115 // getResultSet returns the current result as a ResultSet. It
116 // returns NULL if the current result is not a ResultSet.
118 css::uno::Reference
<css::sdbc::XResultSet
> getResultSet(bool checkCount
)
119 throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
121 creates the driver specific resultset (factory)
123 virtual OResultSet
* createResulSet();
125 SQLLEN
getRowCount() throw (css::sdbc::SQLException
, css::uno::RuntimeException
);
128 void disposeResultSet();
130 // OPropertyArrayUsageHelper
131 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const SAL_OVERRIDE
;
132 // OPropertySetHelper
133 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() SAL_OVERRIDE
;
134 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
135 ::com::sun::star::uno::Any
& rConvertedValue
,
136 ::com::sun::star::uno::Any
& rOldValue
,
138 const ::com::sun::star::uno::Any
& rValue
)
139 throw (::com::sun::star::lang::IllegalArgumentException
) SAL_OVERRIDE
;
140 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
142 const ::com::sun::star::uno::Any
& rValue
144 throw (::com::sun::star::uno::Exception
, std::exception
) SAL_OVERRIDE
;
145 virtual void SAL_CALL
getFastPropertyValue(
146 ::com::sun::star::uno::Any
& rValue
,
148 ) const SAL_OVERRIDE
;
149 virtual ~OStatement_Base();
152 OStatement_Base(OConnection
* _pConnection
);
153 using OStatement_BASE::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
155 inline oslGenericFunction
getOdbcFunction(sal_Int32 _nIndex
) const
157 return m_pConnection
->getOdbcFunction(_nIndex
);
160 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
162 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
163 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
165 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
167 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
170 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
172 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
executeQuery( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
173 virtual sal_Int32 SAL_CALL
executeUpdate( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
174 virtual sal_Bool SAL_CALL
execute( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
175 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
getConnection( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
177 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
178 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
180 virtual void SAL_CALL
cancel( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
182 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
184 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
getResultSet( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
185 virtual sal_Int32 SAL_CALL
getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
186 virtual sal_Bool SAL_CALL
getMoreResults( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
187 //XGeneratedResultSet
188 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
getGeneratedValues( ) throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
191 SQLHANDLE
getConnectionHandle() { return m_pConnection
->getConnection(); }
192 OConnection
* getOwnConnection() const { return m_pConnection
;}
193 /** getCursorProperties return the properties for a specific cursor type
194 @param _nCursorType the CursorType
195 @param bFirst when true the first property set is returned
197 @return the cursor properties
199 SQLUINTEGER
getCursorProperties(SQLINTEGER _nCursorType
, bool bFirst
);
202 using OPropertySetHelper::getFastPropertyValue
;
205 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2
:
206 public OStatement_Base
207 ,public ::connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>
210 friend class OSubComponent
<OStatement_BASE2
, OStatement_BASE
>;
212 OStatement_BASE2(OConnection
* _pConnection
) : OStatement_Base(_pConnection
),
213 ::connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>((::cppu::OWeakObject
*)_pConnection
, this){}
215 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
217 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
220 class OOO_DLLPUBLIC_ODBCBASE OStatement
:
221 public OStatement_BASE2
,
222 public ::com::sun::star::sdbc::XBatchExecution
,
223 public ::com::sun::star::lang::XServiceInfo
226 virtual ~OStatement(){}
228 // A ctor that is needed for returning the object
229 OStatement( OConnection
* _pConnection
) : OStatement_BASE2( _pConnection
){}
230 DECLARE_SERVICE_INFO();
232 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
234 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
236 virtual void SAL_CALL
addBatch( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
237 virtual void SAL_CALL
clearBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
238 virtual ::com::sun::star::uno::Sequence
< sal_Int32
> SAL_CALL
executeBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
242 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */