1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
30 #define _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
32 #include <com/sun/star/sdbc/XStatement.hpp>
33 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
34 #include <com/sun/star/sdbc/XMultipleResults.hpp>
35 #include <com/sun/star/sdbc/XBatchExecution.hpp>
36 #include <com/sun/star/sdbc/XCloseable.hpp>
37 #include <com/sun/star/sdbc/SQLWarning.hpp>
38 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
39 #include <com/sun/star/util/XCancellable.hpp>
40 #include <comphelper/proparrhlp.hxx>
41 #include <cppuhelper/compbase6.hxx>
42 #include <comphelper/uno3.hxx>
43 #include "connectivity/CommonTools.hxx"
44 #include "odbc/OFunctions.hxx"
45 #include "odbc/OConnection.hxx"
46 #include "odbc/odbcbasedllapi.hxx"
48 #include <com/sun/star/lang/XServiceInfo.hpp>
49 #include <comphelper/broadcasthelper.hxx>
51 namespace connectivity
56 typedef ::cppu::WeakComponentImplHelper6
< ::com::sun::star::sdbc::XStatement
,
57 ::com::sun::star::sdbc::XWarningsSupplier
,
58 ::com::sun::star::util::XCancellable
,
59 ::com::sun::star::sdbc::XCloseable
,
60 ::com::sun::star::sdbc::XGeneratedResultSet
,
61 ::com::sun::star::sdbc::XMultipleResults
> OStatement_BASE
;
64 //**************************************************************
65 //************ Class: java.sql.Statement
66 //**************************************************************
67 class OOO_DLLPUBLIC_ODBCBASE OStatement_Base
:
68 public comphelper::OBaseMutex
,
69 public OStatement_BASE
,
70 public ::cppu::OPropertySetHelper
,
71 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
74 ::com::sun::star::sdbc::SQLWarning m_aLastWarning
;
76 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
77 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XStatement
> m_xGeneratedStatement
;
80 ::std::list
< ::rtl::OUString
> m_aBatchList
;
81 ::rtl::OUString m_sSqlStatement
;
83 OConnection
* m_pConnection
;// The owning Connection object
84 SQLHANDLE m_aStatementHandle
;
85 SQLUSMALLINT
* m_pRowStatusArray
;
86 ::cppu::OBroadcastHelper
& rBHelper
;
90 sal_Int64
getQueryTimeOut() const;
91 sal_Int64
getMaxFieldSize() const;
92 sal_Int64
getMaxRows() const;
93 sal_Int32
getResultSetConcurrency() const;
94 sal_Int32
getResultSetType() const;
95 sal_Int32
getFetchDirection() const;
96 sal_Int32
getFetchSize() const;
97 ::rtl::OUString
getCursorName() const;
98 sal_Bool
isUsingBookmarks() const;
99 sal_Bool
getEscapeProcessing() const;
100 template < typename T
, SQLINTEGER BufferLength
> T
getStmtOption (SQLINTEGER fOption
, T dflt
= 0) const;
102 void setQueryTimeOut(sal_Int64 _par0
) ;
103 void setMaxFieldSize(sal_Int64 _par0
) ;
104 void setMaxRows(sal_Int64 _par0
) ;
105 void setFetchDirection(sal_Int32 _par0
) ;
106 void setFetchSize(sal_Int32 _par0
) ;
107 void setCursorName(const ::rtl::OUString
&_par0
);
108 void setEscapeProcessing( const sal_Bool _bEscapeProc
);
109 template < typename T
, SQLINTEGER BufferLength
> SQLRETURN
setStmtOption (SQLINTEGER fOption
, T value
) const;
111 virtual void setResultSetConcurrency(sal_Int32 _par0
) ;
112 virtual void setResultSetType(sal_Int32 _par0
) ;
113 virtual void setUsingBookmarks(sal_Bool _bUseBookmark
) ;
115 void reset () throw( ::com::sun::star::sdbc::SQLException
);
116 void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException
);
117 void setWarning (const ::com::sun::star::sdbc::SQLWarning
&ex
) throw( ::com::sun::star::sdbc::SQLException
);
118 sal_Bool
lockIfNecessary (const ::rtl::OUString
& sql
) throw( ::com::sun::star::sdbc::SQLException
);
119 sal_Int32
getColumnCount () throw( ::com::sun::star::sdbc::SQLException
);
121 //--------------------------------------------------------------------
123 // getResultSet returns the current result as a ResultSet. It
124 // returns NULL if the current result is not a ResultSet.
125 //--------------------------------------------------------------------
126 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> getResultSet (sal_Bool checkCount
) throw( ::com::sun::star::sdbc::SQLException
);
128 creates the driver specific resultset (factory)
130 virtual OResultSet
* createResulSet();
132 SQLLEN
getRowCount () throw( ::com::sun::star::sdbc::SQLException
);
135 void disposeResultSet();
137 // OPropertyArrayUsageHelper
138 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
139 // OPropertySetHelper
140 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
141 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
142 ::com::sun::star::uno::Any
& rConvertedValue
,
143 ::com::sun::star::uno::Any
& rOldValue
,
145 const ::com::sun::star::uno::Any
& rValue
)
146 throw (::com::sun::star::lang::IllegalArgumentException
);
147 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
149 const ::com::sun::star::uno::Any
& rValue
151 throw (::com::sun::star::uno::Exception
);
152 virtual void SAL_CALL
getFastPropertyValue(
153 ::com::sun::star::uno::Any
& rValue
,
156 virtual ~OStatement_Base();
159 OStatement_Base(OConnection
* _pConnection
);
160 using OStatement_BASE::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
162 inline oslGenericFunction
getOdbcFunction(sal_Int32 _nIndex
) const
164 return m_pConnection
->getOdbcFunction(_nIndex
);
167 virtual void SAL_CALL
disposing(void);
169 virtual void SAL_CALL
release() throw();
170 virtual void SAL_CALL
acquire() throw();
172 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
174 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
177 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
179 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
executeQuery( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
180 virtual sal_Int32 SAL_CALL
executeUpdate( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
181 virtual sal_Bool SAL_CALL
execute( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
182 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
) ;
184 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
185 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
187 virtual void SAL_CALL
cancel( ) throw(::com::sun::star::uno::RuntimeException
);
189 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
191 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
);
192 virtual sal_Int32 SAL_CALL
getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
193 virtual sal_Bool SAL_CALL
getMoreResults( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
194 //XGeneratedResultSet
195 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
);
198 SQLHANDLE
getConnectionHandle() { return m_pConnection
->getConnection(); }
199 OConnection
* getOwnConnection() const { return m_pConnection
;}
200 /** getCursorProperties return the properties for a specific cursor type
201 @param _nCursorType the CursorType
202 @param bFirst when true the first property set is returned
204 @return the cursor properties
206 SQLUINTEGER
getCursorProperties(SQLINTEGER _nCursorType
,sal_Bool bFirst
);
209 using OPropertySetHelper::getFastPropertyValue
;
212 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2
:
213 public OStatement_Base
214 ,public ::connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>
217 friend class OSubComponent
<OStatement_BASE2
, OStatement_BASE
>;
219 OStatement_BASE2(OConnection
* _pConnection
) : OStatement_Base(_pConnection
),
220 ::connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>((::cppu::OWeakObject
*)_pConnection
, this){}
222 virtual void SAL_CALL
disposing(void);
224 virtual void SAL_CALL
release() throw();
227 class OOO_DLLPUBLIC_ODBCBASE OStatement
:
228 public OStatement_BASE2
,
229 public ::com::sun::star::sdbc::XBatchExecution
,
230 public ::com::sun::star::lang::XServiceInfo
233 virtual ~OStatement(){}
235 // A ctor that is needed for returning the object
236 OStatement( OConnection
* _pConnection
) : OStatement_BASE2( _pConnection
){}
237 DECLARE_SERVICE_INFO();
239 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
240 virtual void SAL_CALL
acquire() throw();
241 virtual void SAL_CALL
release() throw();
243 virtual void SAL_CALL
addBatch( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
244 virtual void SAL_CALL
clearBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
245 virtual ::com::sun::star::uno::Sequence
< sal_Int32
> SAL_CALL
executeBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
249 #endif // _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */