1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
37 #include "SPreparedStatement.hxx"
38 #include <com/sun/star/sdbc/DataType.hpp>
39 #include "SResultSetMetaData.hxx"
40 #include <cppuhelper/typeprovider.hxx>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include "propertyids.hxx"
44 using namespace connectivity::skeleton
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::beans
;
48 using namespace com::sun::star::sdbc
;
49 using namespace com::sun::star::container
;
50 using namespace com::sun::star::io
;
51 using namespace com::sun::star::util
;
53 IMPLEMENT_SERVICE_INFO(OPreparedStatement
,"com.sun.star.sdbcx.skeleton.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
56 OPreparedStatement::OPreparedStatement( OConnection
* _pConnection
,const TTypeInfoVector
& _TypeInfo
,const ::rtl::OUString
& sql
)
57 :OStatement_BASE2(_pConnection
)
58 ,m_aTypeInfo(_TypeInfo
)
59 ,m_bPrepared(sal_False
)
65 OPreparedStatement::~OPreparedStatement()
69 void SAL_CALL
OPreparedStatement::acquire() throw()
71 OStatement_BASE2::acquire();
74 void SAL_CALL
OPreparedStatement::release() throw()
76 OStatement_BASE2::release();
79 Any SAL_CALL
OPreparedStatement::queryInterface( const Type
& rType
) throw(RuntimeException
)
81 Any aRet
= OStatement_BASE2::queryInterface(rType
);
83 aRet
= OPreparedStatement_BASE::queryInterface(rType
);
87 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException
)
89 return concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes());
93 Reference
< XResultSetMetaData
> SAL_CALL
OPreparedStatement::getMetaData( ) throw(SQLException
, RuntimeException
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
96 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
99 m_xMetaData
= new OResultSetMetaData(getOwnConnection());
104 void SAL_CALL
OPreparedStatement::close( ) throw(SQLException
, RuntimeException
)
106 ::osl::MutexGuard
aGuard( m_aMutex
);
107 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
110 // Reset last warning message
114 OStatement_BASE2::close();
116 catch (SQLException
&) {
117 // If we get an error, ignore
120 // Remove this Statement object from the Connection object's
125 sal_Bool SAL_CALL
OPreparedStatement::execute( ) throw(SQLException
, RuntimeException
)
127 ::osl::MutexGuard
aGuard( m_aMutex
);
128 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
131 // same as in statement with the difference that this statement also can contain parameter
136 sal_Int32 SAL_CALL
OPreparedStatement::executeUpdate( ) throw(SQLException
, RuntimeException
)
138 ::osl::MutexGuard
aGuard( m_aMutex
);
139 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
141 // same as in statement with the difference that this statement also can contain parameter
146 void SAL_CALL
OPreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
) throw(SQLException
, RuntimeException
)
148 ::osl::MutexGuard
aGuard( m_aMutex
);
149 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
153 Reference
< XConnection
> SAL_CALL
OPreparedStatement::getConnection( ) throw(SQLException
, RuntimeException
)
155 ::osl::MutexGuard
aGuard( m_aMutex
);
156 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
158 return (Reference
< XConnection
>)m_pConnection
;
162 Reference
< XResultSet
> SAL_CALL
OPreparedStatement::executeQuery( ) throw(SQLException
, RuntimeException
)
164 ::osl::MutexGuard
aGuard( m_aMutex
);
165 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
167 Reference
< XResultSet
> rs
= NULL
;
174 void SAL_CALL
OPreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
176 ::osl::MutexGuard
aGuard( m_aMutex
);
177 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
181 void SAL_CALL
OPreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
183 ::osl::MutexGuard
aGuard( m_aMutex
);
184 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
190 void SAL_CALL
OPreparedStatement::setDate( sal_Int32 parameterIndex
, const Date
& aData
) throw(SQLException
, RuntimeException
)
192 ::osl::MutexGuard
aGuard( m_aMutex
);
193 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
198 void SAL_CALL
OPreparedStatement::setTime( sal_Int32 parameterIndex
, const css::util::Time
& aVal
) throw(SQLException
, RuntimeException
)
200 ::osl::MutexGuard
aGuard( m_aMutex
);
201 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
206 void SAL_CALL
OPreparedStatement::setTimestamp( sal_Int32 parameterIndex
, const DateTime
& aVal
) throw(SQLException
, RuntimeException
)
208 ::osl::MutexGuard
aGuard( m_aMutex
);
209 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
214 void SAL_CALL
OPreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
) throw(SQLException
, RuntimeException
)
216 ::osl::MutexGuard
aGuard( m_aMutex
);
217 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
222 void SAL_CALL
OPreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
) throw(SQLException
, RuntimeException
)
224 ::osl::MutexGuard
aGuard( m_aMutex
);
225 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
230 void SAL_CALL
OPreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
232 ::osl::MutexGuard
aGuard( m_aMutex
);
233 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
238 void SAL_CALL
OPreparedStatement::setLong( sal_Int32 parameterIndex
, sal_Int64 aVal
) throw(SQLException
, RuntimeException
)
240 ::osl::MutexGuard
aGuard( m_aMutex
);
241 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
246 void SAL_CALL
OPreparedStatement::setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
) throw(SQLException
, RuntimeException
)
248 ::osl::MutexGuard
aGuard( m_aMutex
);
249 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
254 void SAL_CALL
OPreparedStatement::setClob( sal_Int32 parameterIndex
, const Reference
< XClob
>& x
) throw(SQLException
, RuntimeException
)
256 ::osl::MutexGuard
aGuard( m_aMutex
);
257 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
262 void SAL_CALL
OPreparedStatement::setBlob( sal_Int32 parameterIndex
, const Reference
< XBlob
>& x
) throw(SQLException
, RuntimeException
)
264 ::osl::MutexGuard
aGuard( m_aMutex
);
265 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
270 void SAL_CALL
OPreparedStatement::setArray( sal_Int32 parameterIndex
, const Reference
< XArray
>& x
) throw(SQLException
, RuntimeException
)
272 ::osl::MutexGuard
aGuard( m_aMutex
);
273 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
278 void SAL_CALL
OPreparedStatement::setRef( sal_Int32 parameterIndex
, const Reference
< XRef
>& x
) throw(SQLException
, RuntimeException
)
280 ::osl::MutexGuard
aGuard( m_aMutex
);
281 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
286 void SAL_CALL
OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex
, const Any
& x
, sal_Int32 sqlType
, sal_Int32 scale
) throw(SQLException
, RuntimeException
)
288 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
289 ::osl::MutexGuard
aGuard( m_aMutex
);
294 void SAL_CALL
OPreparedStatement::setObjectNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& typeName
) throw(SQLException
, RuntimeException
)
296 ::osl::MutexGuard
aGuard( m_aMutex
);
297 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
302 void SAL_CALL
OPreparedStatement::setObject( sal_Int32 parameterIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
304 ::osl::MutexGuard
aGuard( m_aMutex
);
305 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
310 void SAL_CALL
OPreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
312 ::osl::MutexGuard
aGuard( m_aMutex
);
313 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
318 void SAL_CALL
OPreparedStatement::setBytes( sal_Int32 parameterIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
320 ::osl::MutexGuard
aGuard( m_aMutex
);
321 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
326 void SAL_CALL
OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
328 ::osl::MutexGuard
aGuard( m_aMutex
);
329 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
334 void SAL_CALL
OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
336 ::osl::MutexGuard
aGuard( m_aMutex
);
337 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
342 void SAL_CALL
OPreparedStatement::clearParameters( ) throw(SQLException
, RuntimeException
)
346 void SAL_CALL
OPreparedStatement::clearBatch( ) throw(SQLException
, RuntimeException
)
351 void SAL_CALL
OPreparedStatement::addBatch( ) throw(SQLException
, RuntimeException
)
356 Sequence
< sal_Int32
> SAL_CALL
OPreparedStatement::executeBatch( ) throw(SQLException
, RuntimeException
)
358 return Sequence
< sal_Int32
> ();
361 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
365 case PROPERTY_ID_RESULTSETCONCURRENCY
:
367 case PROPERTY_ID_RESULTSETTYPE
:
369 case PROPERTY_ID_FETCHDIRECTION
:
371 case PROPERTY_ID_USEBOOKMARKS
:
374 OStatement_Base::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
378 void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex
)
380 if( !_parameterIndex
|| _parameterIndex
> m_nNumParams
)
381 throw SQLException();
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */