merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Database / DriverSkeleton / SStatement.cxx
blobf372699f259b6676738e0b9591e759dbd1227481
1 /*************************************************************************
3 * $RCSfile: SStatement.cxx,v $
5 * $Revision: 1.7 $
7 * last change: $Author: rt $ $Date: 2008-04-10 16:37:21 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
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
17 * are met:
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 *************************************************************************/
41 #include <stdio.h>
42 #include <osl/diagnose.h>
43 #include "SStatement.hxx"
44 #include "SConnection.hxx"
45 #include "SResultSet.hxx"
46 #include <osl/thread.h>
47 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
48 #include <com/sun/star/sdbc/ResultSetType.hpp>
49 #include <com/sun/star/sdbc/FetchDirection.hpp>
50 #include <com/sun/star/lang/DisposedException.hpp>
51 #include <cppuhelper/typeprovider.hxx>
52 #include "propertyids.hxx"
54 using namespace connectivity::skeleton;
55 //------------------------------------------------------------------------------
56 using namespace com::sun::star::uno;
57 using namespace com::sun::star::lang;
58 using namespace com::sun::star::beans;
59 using namespace com::sun::star::sdbc;
60 using namespace com::sun::star::sdbcx;
61 using namespace com::sun::star::container;
62 using namespace com::sun::star::io;
63 using namespace com::sun::star::util;
64 //------------------------------------------------------------------------------
65 OStatement_Base::OStatement_Base(OConnection* _pConnection )
66 : OStatement_BASE(m_aMutex),
67 OPropertySetHelper(OStatement_BASE::rBHelper),
68 rBHelper(OStatement_BASE::rBHelper),
69 m_pConnection(_pConnection)
71 m_pConnection->acquire();
73 // -----------------------------------------------------------------------------
74 OStatement_Base::~OStatement_Base()
77 //------------------------------------------------------------------------------
78 void OStatement_Base::disposeResultSet()
80 // free the cursor if alive
81 Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
82 if (xComp.is())
83 xComp->dispose();
84 m_xResultSet = Reference< XResultSet>();
86 //------------------------------------------------------------------------------
87 void OStatement_BASE2::disposing()
89 ::osl::MutexGuard aGuard(m_aMutex);
91 disposeResultSet();
93 if (m_pConnection)
94 m_pConnection->release();
95 m_pConnection = NULL;
97 dispose_ChildImpl();
98 OStatement_Base::disposing();
100 //-----------------------------------------------------------------------------
101 void SAL_CALL OStatement_BASE2::release() throw()
103 relase_ChildImpl();
105 //-----------------------------------------------------------------------------
106 Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
108 Any aRet = OStatement_BASE::queryInterface(rType);
109 if(!aRet.hasValue())
110 aRet = OPropertySetHelper::queryInterface(rType);
111 return aRet;
113 // -------------------------------------------------------------------------
114 Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException)
116 ::cppu::OTypeCollection aTypes(
117 ::cppu::UnoType< Reference< XMultiPropertySet > >::get(),
118 ::cppu::UnoType< Reference< XFastPropertySet > >::get(),
119 ::cppu::UnoType< Reference< XPropertySet > >::get());
121 return concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes());
123 // -------------------------------------------------------------------------
125 void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException)
127 ::osl::MutexGuard aGuard( m_aMutex );
128 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
129 // cancel the current sql statement
131 // -------------------------------------------------------------------------
133 void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException)
136 ::osl::MutexGuard aGuard( m_aMutex );
137 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
140 dispose();
142 // -------------------------------------------------------------------------
144 void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException)
146 // if you support batches clear it here
148 // -------------------------------------------------------------------------
149 sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
151 ::osl::MutexGuard aGuard( m_aMutex );
152 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
154 // returns true when a resultset is available
155 return sal_False;
157 // -------------------------------------------------------------------------
159 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
161 ::osl::MutexGuard aGuard( m_aMutex );
162 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
165 Reference< XResultSet > xRS = NULL;
166 // create a resultset as result of executing the sql statement
167 // you have to here something :-)
168 m_xResultSet = xRS; // we nedd a reference to it for later use
169 return xRS;
171 // -------------------------------------------------------------------------
173 Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException)
175 ::osl::MutexGuard aGuard( m_aMutex );
176 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
178 // just return our connection here
179 return (Reference< XConnection >)m_pConnection;
181 // -----------------------------------------------------------------------------
182 sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
184 return 0;
186 // -------------------------------------------------------------------------
188 Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
190 Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
191 if(!aRet.hasValue())
192 aRet = OStatement_Base::queryInterface(rType);
193 return aRet;
195 // -------------------------------------------------------------------------
197 void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
199 ::osl::MutexGuard aGuard( m_aMutex );
200 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
203 m_aBatchList.push_back(sql);
205 // -------------------------------------------------------------------------
206 Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException)
208 ::osl::MutexGuard aGuard( m_aMutex );
209 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
211 return Sequence< sal_Int32 >();
213 // -------------------------------------------------------------------------
216 sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
218 ::osl::MutexGuard aGuard( m_aMutex );
219 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
221 // the return values gives information about how many rows are affected by executing the sql statement
222 return 0;
225 // -------------------------------------------------------------------------
227 Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException)
229 ::osl::MutexGuard aGuard( m_aMutex );
230 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
232 // return our save resultset here
233 return m_xResultSet;
235 // -------------------------------------------------------------------------
237 sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException)
239 ::osl::MutexGuard aGuard( m_aMutex );
240 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
242 // if your driver supports more than only one resultset
243 // and has one more at this moment return true
244 return sal_False;
246 // -------------------------------------------------------------------------
248 // -------------------------------------------------------------------------
249 Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException)
251 ::osl::MutexGuard aGuard( m_aMutex );
252 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
255 return makeAny(m_aLastWarning);
257 // -------------------------------------------------------------------------
259 // -------------------------------------------------------------------------
260 void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException)
262 ::osl::MutexGuard aGuard( m_aMutex );
263 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
266 m_aLastWarning = SQLWarning();
268 // -------------------------------------------------------------------------
269 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
271 // this properties are define by the service statement
272 // they must in alphabetic order
273 Sequence< Property > aProps(10);
274 Property* pProperties = aProps.getArray();
275 sal_Int32 nPos = 0;
276 DECL_PROP0(CURSORNAME, ::rtl::OUString);
277 DECL_BOOL_PROP0(ESCAPEPROCESSING);
278 DECL_PROP0(FETCHDIRECTION,sal_Int32);
279 DECL_PROP0(FETCHSIZE, sal_Int32);
280 DECL_PROP0(MAXFIELDSIZE,sal_Int32);
281 DECL_PROP0(MAXROWS, sal_Int32);
282 DECL_PROP0(QUERYTIMEOUT,sal_Int32);
283 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
284 DECL_PROP0(RESULTSETTYPE,sal_Int32);
285 DECL_BOOL_PROP0(USEBOOKMARKS);
287 return new ::cppu::OPropertyArrayHelper(aProps);
290 // -------------------------------------------------------------------------
291 ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
293 return *const_cast<OStatement_Base*>(this)->getArrayHelper();
295 // -------------------------------------------------------------------------
296 sal_Bool OStatement_Base::convertFastPropertyValue(
297 Any & rConvertedValue,
298 Any & rOldValue,
299 sal_Int32 nHandle,
300 const Any& rValue )
301 throw (::com::sun::star::lang::IllegalArgumentException)
303 sal_Bool bConverted = sal_False;
304 // here we have to try to convert
305 return bConverted;
307 // -------------------------------------------------------------------------
308 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
310 // set the value to what ever is nescessary
311 switch(nHandle)
313 case PROPERTY_ID_QUERYTIMEOUT:
314 case PROPERTY_ID_MAXFIELDSIZE:
315 case PROPERTY_ID_MAXROWS:
316 case PROPERTY_ID_CURSORNAME:
317 case PROPERTY_ID_RESULTSETCONCURRENCY:
318 case PROPERTY_ID_RESULTSETTYPE:
319 case PROPERTY_ID_FETCHDIRECTION:
320 case PROPERTY_ID_FETCHSIZE:
321 case PROPERTY_ID_ESCAPEPROCESSING:
322 case PROPERTY_ID_USEBOOKMARKS:
323 default:
327 // -------------------------------------------------------------------------
328 void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
330 switch(nHandle)
332 case PROPERTY_ID_QUERYTIMEOUT:
333 case PROPERTY_ID_MAXFIELDSIZE:
334 case PROPERTY_ID_MAXROWS:
335 case PROPERTY_ID_CURSORNAME:
336 case PROPERTY_ID_RESULTSETCONCURRENCY:
337 case PROPERTY_ID_RESULTSETTYPE:
338 case PROPERTY_ID_FETCHDIRECTION:
339 case PROPERTY_ID_FETCHSIZE:
340 case PROPERTY_ID_ESCAPEPROCESSING:
341 case PROPERTY_ID_USEBOOKMARKS:
342 default:
346 // -------------------------------------------------------------------------
347 IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
348 // -----------------------------------------------------------------------------
349 void SAL_CALL OStatement_Base::acquire() throw()
351 OStatement_BASE::acquire();
353 // -----------------------------------------------------------------------------
354 void SAL_CALL OStatement_Base::release() throw()
356 OStatement_BASE::release();
358 // -----------------------------------------------------------------------------
359 void SAL_CALL OStatement::acquire() throw()
361 OStatement_BASE2::acquire();
363 // -----------------------------------------------------------------------------
364 void SAL_CALL OStatement::release() throw()
366 OStatement_BASE2::release();
368 // -----------------------------------------------------------------------------
369 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(RuntimeException)
371 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
373 // -----------------------------------------------------------------------------