1 /*************************************************************************
3 * $RCSfile: SPreparedStatement.cxx,v $
7 * last change: $Author: rt $ $Date: 2008-04-10 16:34:02 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
42 #include <osl/diagnose.h>
43 #include "SPreparedStatement.hxx"
44 #include <com/sun/star/sdbc/DataType.hpp>
45 #include "SResultSetMetaData.hxx"
46 #include <cppuhelper/typeprovider.hxx>
47 #include <com/sun/star/lang/DisposedException.hpp>
48 #include "propertyids.hxx"
50 using namespace connectivity::skeleton
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::lang
;
53 using namespace com::sun::star::beans
;
54 using namespace com::sun::star::sdbc
;
55 using namespace com::sun::star::container
;
56 using namespace com::sun::star::io
;
57 using namespace com::sun::star::util
;
59 IMPLEMENT_SERVICE_INFO(OPreparedStatement
,"com.sun.star.sdbcx.skeleton.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
62 OPreparedStatement::OPreparedStatement( OConnection
* _pConnection
,const TTypeInfoVector
& _TypeInfo
,const ::rtl::OUString
& sql
)
63 :OStatement_BASE2(_pConnection
)
64 ,m_aTypeInfo(_TypeInfo
)
65 ,m_bPrepared(sal_False
)
70 // -----------------------------------------------------------------------------
71 OPreparedStatement::~OPreparedStatement()
74 // -----------------------------------------------------------------------------
75 void SAL_CALL
OPreparedStatement::acquire() throw()
77 OStatement_BASE2::acquire();
79 // -----------------------------------------------------------------------------
80 void SAL_CALL
OPreparedStatement::release() throw()
82 OStatement_BASE2::release();
84 // -----------------------------------------------------------------------------
85 Any SAL_CALL
OPreparedStatement::queryInterface( const Type
& rType
) throw(RuntimeException
)
87 Any aRet
= OStatement_BASE2::queryInterface(rType
);
89 aRet
= OPreparedStatement_BASE::queryInterface(rType
);
92 // -------------------------------------------------------------------------
93 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException
)
95 return concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes());
97 // -------------------------------------------------------------------------
99 Reference
< XResultSetMetaData
> SAL_CALL
OPreparedStatement::getMetaData( ) throw(SQLException
, RuntimeException
)
101 ::osl::MutexGuard
aGuard( m_aMutex
);
102 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
104 if(!m_xMetaData
.is())
105 m_xMetaData
= new OResultSetMetaData(getOwnConnection());
108 // -------------------------------------------------------------------------
110 void SAL_CALL
OPreparedStatement::close( ) throw(SQLException
, RuntimeException
)
112 ::osl::MutexGuard
aGuard( m_aMutex
);
113 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
116 // Reset last warning message
120 OStatement_BASE2::close();
122 catch (SQLException
&) {
123 // If we get an error, ignore
126 // Remove this Statement object from the Connection object's
129 // -------------------------------------------------------------------------
131 sal_Bool SAL_CALL
OPreparedStatement::execute( ) throw(SQLException
, RuntimeException
)
133 ::osl::MutexGuard
aGuard( m_aMutex
);
134 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
137 // same as in statement with the difference that this statement also can contain parameter
140 // -------------------------------------------------------------------------
142 sal_Int32 SAL_CALL
OPreparedStatement::executeUpdate( ) throw(SQLException
, RuntimeException
)
144 ::osl::MutexGuard
aGuard( m_aMutex
);
145 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
147 // same as in statement with the difference that this statement also can contain parameter
150 // -------------------------------------------------------------------------
152 void SAL_CALL
OPreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
) throw(SQLException
, RuntimeException
)
154 ::osl::MutexGuard
aGuard( m_aMutex
);
155 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
157 // -------------------------------------------------------------------------
159 Reference
< XConnection
> SAL_CALL
OPreparedStatement::getConnection( ) throw(SQLException
, RuntimeException
)
161 ::osl::MutexGuard
aGuard( m_aMutex
);
162 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
164 return (Reference
< XConnection
>)m_pConnection
;
166 // -------------------------------------------------------------------------
168 Reference
< XResultSet
> SAL_CALL
OPreparedStatement::executeQuery( ) throw(SQLException
, RuntimeException
)
170 ::osl::MutexGuard
aGuard( m_aMutex
);
171 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
173 Reference
< XResultSet
> rs
= NULL
;
178 // -------------------------------------------------------------------------
180 void SAL_CALL
OPreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
182 ::osl::MutexGuard
aGuard( m_aMutex
);
183 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
186 // -------------------------------------------------------------------------
187 void SAL_CALL
OPreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
189 ::osl::MutexGuard
aGuard( m_aMutex
);
190 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
194 // -------------------------------------------------------------------------
196 void SAL_CALL
OPreparedStatement::setDate( sal_Int32 parameterIndex
, const Date
& aData
) throw(SQLException
, RuntimeException
)
198 ::osl::MutexGuard
aGuard( m_aMutex
);
199 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
202 // -------------------------------------------------------------------------
205 void SAL_CALL
OPreparedStatement::setTime( sal_Int32 parameterIndex
, const Time
& aVal
) throw(SQLException
, RuntimeException
)
207 ::osl::MutexGuard
aGuard( m_aMutex
);
208 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
211 // -------------------------------------------------------------------------
213 void SAL_CALL
OPreparedStatement::setTimestamp( sal_Int32 parameterIndex
, const DateTime
& aVal
) throw(SQLException
, RuntimeException
)
215 ::osl::MutexGuard
aGuard( m_aMutex
);
216 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
219 // -------------------------------------------------------------------------
221 void SAL_CALL
OPreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
) throw(SQLException
, RuntimeException
)
223 ::osl::MutexGuard
aGuard( m_aMutex
);
224 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
228 // -------------------------------------------------------------------------
230 void SAL_CALL
OPreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
) throw(SQLException
, RuntimeException
)
232 ::osl::MutexGuard
aGuard( m_aMutex
);
233 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
236 // -------------------------------------------------------------------------
238 void SAL_CALL
OPreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
240 ::osl::MutexGuard
aGuard( m_aMutex
);
241 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
244 // -------------------------------------------------------------------------
246 void SAL_CALL
OPreparedStatement::setLong( sal_Int32 parameterIndex
, sal_Int64 aVal
) throw(SQLException
, RuntimeException
)
248 ::osl::MutexGuard
aGuard( m_aMutex
);
249 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
252 // -------------------------------------------------------------------------
254 void SAL_CALL
OPreparedStatement::setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
) throw(SQLException
, RuntimeException
)
256 ::osl::MutexGuard
aGuard( m_aMutex
);
257 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
260 // -------------------------------------------------------------------------
262 void SAL_CALL
OPreparedStatement::setClob( sal_Int32 parameterIndex
, const Reference
< XClob
>& x
) throw(SQLException
, RuntimeException
)
264 ::osl::MutexGuard
aGuard( m_aMutex
);
265 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
268 // -------------------------------------------------------------------------
270 void SAL_CALL
OPreparedStatement::setBlob( sal_Int32 parameterIndex
, const Reference
< XBlob
>& x
) throw(SQLException
, RuntimeException
)
272 ::osl::MutexGuard
aGuard( m_aMutex
);
273 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
276 // -------------------------------------------------------------------------
278 void SAL_CALL
OPreparedStatement::setArray( sal_Int32 parameterIndex
, const Reference
< XArray
>& x
) throw(SQLException
, RuntimeException
)
280 ::osl::MutexGuard
aGuard( m_aMutex
);
281 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
284 // -------------------------------------------------------------------------
286 void SAL_CALL
OPreparedStatement::setRef( sal_Int32 parameterIndex
, const Reference
< XRef
>& x
) throw(SQLException
, RuntimeException
)
288 ::osl::MutexGuard
aGuard( m_aMutex
);
289 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
292 // -------------------------------------------------------------------------
294 void SAL_CALL
OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex
, const Any
& x
, sal_Int32 sqlType
, sal_Int32 scale
) throw(SQLException
, RuntimeException
)
296 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
297 ::osl::MutexGuard
aGuard( m_aMutex
);
300 // -------------------------------------------------------------------------
302 void SAL_CALL
OPreparedStatement::setObjectNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& typeName
) throw(SQLException
, RuntimeException
)
304 ::osl::MutexGuard
aGuard( m_aMutex
);
305 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
308 // -------------------------------------------------------------------------
310 void SAL_CALL
OPreparedStatement::setObject( sal_Int32 parameterIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
312 ::osl::MutexGuard
aGuard( m_aMutex
);
313 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
316 // -------------------------------------------------------------------------
318 void SAL_CALL
OPreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
320 ::osl::MutexGuard
aGuard( m_aMutex
);
321 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
324 // -------------------------------------------------------------------------
326 void SAL_CALL
OPreparedStatement::setBytes( sal_Int32 parameterIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
328 ::osl::MutexGuard
aGuard( m_aMutex
);
329 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
332 // -------------------------------------------------------------------------
335 void SAL_CALL
OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
337 ::osl::MutexGuard
aGuard( m_aMutex
);
338 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
341 // -------------------------------------------------------------------------
343 void SAL_CALL
OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
345 ::osl::MutexGuard
aGuard( m_aMutex
);
346 checkDisposed(OStatement_BASE::rBHelper
.bDisposed
);
349 // -------------------------------------------------------------------------
351 void SAL_CALL
OPreparedStatement::clearParameters( ) throw(SQLException
, RuntimeException
)
354 // -------------------------------------------------------------------------
355 void SAL_CALL
OPreparedStatement::clearBatch( ) throw(SQLException
, RuntimeException
)
358 // -------------------------------------------------------------------------
360 void SAL_CALL
OPreparedStatement::addBatch( ) throw(SQLException
, RuntimeException
)
363 // -------------------------------------------------------------------------
365 Sequence
< sal_Int32
> SAL_CALL
OPreparedStatement::executeBatch( ) throw(SQLException
, RuntimeException
)
367 return Sequence
< sal_Int32
> ();
369 // -------------------------------------------------------------------------
370 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
374 case PROPERTY_ID_RESULTSETCONCURRENCY
:
376 case PROPERTY_ID_RESULTSETTYPE
:
378 case PROPERTY_ID_FETCHDIRECTION
:
380 case PROPERTY_ID_USEBOOKMARKS
:
383 OStatement_Base::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
386 // -----------------------------------------------------------------------------
387 void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex
)
389 if( !_parameterIndex
|| _parameterIndex
> m_nNumParams
)
390 throw SQLException();
392 // -----------------------------------------------------------------------------