Update git submodules
[LibreOffice.git] / odk / examples / DevelopersGuide / Database / DriverSkeleton / SPreparedStatement.cxx
blob588883f84f9e2f2aa90d5cd52c444bd68130e352
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
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 *************************************************************************/
36 #include <stdio.h>
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)
60 ,m_sSqlStatement(sql)
61 ,m_nNumParams(0)
65 OPreparedStatement::~OPreparedStatement()
69 void SAL_CALL OPreparedStatement::acquire() SAL_NOEXCEPT
71 OStatement_BASE2::acquire();
74 void SAL_CALL OPreparedStatement::release() SAL_NOEXCEPT
76 OStatement_BASE2::release();
79 Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType )
81 Any aRet = OStatement_BASE2::queryInterface(rType);
82 if(!aRet.hasValue())
83 aRet = OPreparedStatement_BASE::queryInterface(rType);
84 return aRet;
87 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( )
89 return concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes());
93 Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( )
95 ::osl::MutexGuard aGuard( m_aMutex );
96 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
98 if(!m_xMetaData.is())
99 m_xMetaData = new OResultSetMetaData(getOwnConnection());
100 return m_xMetaData;
104 void SAL_CALL OPreparedStatement::close( )
106 ::osl::MutexGuard aGuard( m_aMutex );
107 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
110 // Reset last warning message
112 try {
113 clearWarnings ();
114 OStatement_BASE2::close();
116 catch (SQLException &) {
117 // If we get an error, ignore
120 // Remove this Statement object from the Connection object's
121 // list
125 sal_Bool SAL_CALL OPreparedStatement::execute( )
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
132 return sal_False;
136 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( )
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
142 return 0;
146 void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x )
148 ::osl::MutexGuard aGuard( m_aMutex );
149 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
153 Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( )
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( )
164 ::osl::MutexGuard aGuard( m_aMutex );
165 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
167 Reference< XResultSet > rs = NULL;
170 return rs;
174 void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x )
176 ::osl::MutexGuard aGuard( m_aMutex );
177 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
181 void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x )
183 ::osl::MutexGuard aGuard( m_aMutex );
184 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
190 void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData )
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 )
200 ::osl::MutexGuard aGuard( m_aMutex );
201 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
206 void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal )
208 ::osl::MutexGuard aGuard( m_aMutex );
209 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
214 void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x )
216 ::osl::MutexGuard aGuard( m_aMutex );
217 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
222 void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x )
224 ::osl::MutexGuard aGuard( m_aMutex );
225 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
230 void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x )
232 ::osl::MutexGuard aGuard( m_aMutex );
233 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
238 void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 aVal )
240 ::osl::MutexGuard aGuard( m_aMutex );
241 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
246 void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType )
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 )
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 )
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 )
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 )
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 )
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 )
296 ::osl::MutexGuard aGuard( m_aMutex );
297 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
302 void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x )
304 ::osl::MutexGuard aGuard( m_aMutex );
305 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
310 void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x )
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 )
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 )
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 )
336 ::osl::MutexGuard aGuard( m_aMutex );
337 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
342 void SAL_CALL OPreparedStatement::clearParameters( )
346 void SAL_CALL OPreparedStatement::clearBatch( )
351 void SAL_CALL OPreparedStatement::addBatch( )
356 Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch( )
358 return Sequence< sal_Int32 > ();
361 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
363 switch(nHandle)
365 case PROPERTY_ID_RESULTSETCONCURRENCY:
366 break;
367 case PROPERTY_ID_RESULTSETTYPE:
368 break;
369 case PROPERTY_ID_FETCHDIRECTION:
370 break;
371 case PROPERTY_ID_USEBOOKMARKS:
372 break;
373 default:
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: */