1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <stdio.h> 25cdf0e10cSrcweir #include <osl/diagnose.h> 26cdf0e10cSrcweir #include "SStatement.hxx" 27cdf0e10cSrcweir #include "SConnection.hxx" 28cdf0e10cSrcweir #include "SResultSet.hxx" 29cdf0e10cSrcweir #include <osl/thread.h> 30cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> 31cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp> 32cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 34cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 35cdf0e10cSrcweir #include "propertyids.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir using namespace connectivity::skeleton; 38cdf0e10cSrcweir //------------------------------------------------------------------------------ 39cdf0e10cSrcweir using namespace com::sun::star::uno; 40cdf0e10cSrcweir using namespace com::sun::star::lang; 41cdf0e10cSrcweir using namespace com::sun::star::beans; 42cdf0e10cSrcweir using namespace com::sun::star::sdbc; 43cdf0e10cSrcweir using namespace com::sun::star::sdbcx; 44cdf0e10cSrcweir using namespace com::sun::star::container; 45cdf0e10cSrcweir using namespace com::sun::star::io; 46cdf0e10cSrcweir using namespace com::sun::star::util; 47cdf0e10cSrcweir //------------------------------------------------------------------------------ 48cdf0e10cSrcweir OStatement_Base::OStatement_Base(OConnection* _pConnection ) 49cdf0e10cSrcweir : OStatement_BASE(m_aMutex), 50cdf0e10cSrcweir OPropertySetHelper(OStatement_BASE::rBHelper), 51cdf0e10cSrcweir rBHelper(OStatement_BASE::rBHelper), 52cdf0e10cSrcweir m_pConnection(_pConnection) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir m_pConnection->acquire(); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir // ----------------------------------------------------------------------------- 57cdf0e10cSrcweir OStatement_Base::~OStatement_Base() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir //------------------------------------------------------------------------------ 61cdf0e10cSrcweir void OStatement_Base::disposeResultSet() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir // free the cursor if alive 64cdf0e10cSrcweir Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); 65cdf0e10cSrcweir if (xComp.is()) 66cdf0e10cSrcweir xComp->dispose(); 67cdf0e10cSrcweir m_xResultSet = Reference< XResultSet>(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir //------------------------------------------------------------------------------ 70cdf0e10cSrcweir void OStatement_BASE2::disposing() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 73cdf0e10cSrcweir 74cdf0e10cSrcweir disposeResultSet(); 75cdf0e10cSrcweir 76cdf0e10cSrcweir if (m_pConnection) 77cdf0e10cSrcweir m_pConnection->release(); 78cdf0e10cSrcweir m_pConnection = NULL; 79cdf0e10cSrcweir 80cdf0e10cSrcweir dispose_ChildImpl(); 81cdf0e10cSrcweir OStatement_Base::disposing(); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir //----------------------------------------------------------------------------- 84cdf0e10cSrcweir void SAL_CALL OStatement_BASE2::release() throw() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir relase_ChildImpl(); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir //----------------------------------------------------------------------------- 89cdf0e10cSrcweir Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Any aRet = OStatement_BASE::queryInterface(rType); 92cdf0e10cSrcweir if(!aRet.hasValue()) 93cdf0e10cSrcweir aRet = OPropertySetHelper::queryInterface(rType); 94cdf0e10cSrcweir return aRet; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir // ------------------------------------------------------------------------- 97cdf0e10cSrcweir Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir ::cppu::OTypeCollection aTypes( 100cdf0e10cSrcweir ::cppu::UnoType< Reference< XMultiPropertySet > >::get(), 101cdf0e10cSrcweir ::cppu::UnoType< Reference< XFastPropertySet > >::get(), 102cdf0e10cSrcweir ::cppu::UnoType< Reference< XPropertySet > >::get()); 103cdf0e10cSrcweir 104cdf0e10cSrcweir return concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes()); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir // ------------------------------------------------------------------------- 107cdf0e10cSrcweir 108cdf0e10cSrcweir void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 111cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 112cdf0e10cSrcweir // cancel the current sql statement 113cdf0e10cSrcweir } 114cdf0e10cSrcweir // ------------------------------------------------------------------------- 115cdf0e10cSrcweir 116cdf0e10cSrcweir void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir { 119cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 120cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 121cdf0e10cSrcweir 122cdf0e10cSrcweir } 123cdf0e10cSrcweir dispose(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir // ------------------------------------------------------------------------- 126cdf0e10cSrcweir 127cdf0e10cSrcweir void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir // if you support batches clear it here 130cdf0e10cSrcweir } 131cdf0e10cSrcweir // ------------------------------------------------------------------------- 132cdf0e10cSrcweir sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 135cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 136cdf0e10cSrcweir 137cdf0e10cSrcweir // returns true when a resultset is available 138cdf0e10cSrcweir return sal_False; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir // ------------------------------------------------------------------------- 141cdf0e10cSrcweir 142cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 145cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 146cdf0e10cSrcweir 147cdf0e10cSrcweir 148cdf0e10cSrcweir Reference< XResultSet > xRS = NULL; 149cdf0e10cSrcweir // create a resultset as result of executing the sql statement 150cdf0e10cSrcweir // you have to here something :-) 151cdf0e10cSrcweir m_xResultSet = xRS; // we nedd a reference to it for later use 152cdf0e10cSrcweir return xRS; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir // ------------------------------------------------------------------------- 155cdf0e10cSrcweir 156cdf0e10cSrcweir Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 159cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 160cdf0e10cSrcweir 161cdf0e10cSrcweir // just return our connection here 162cdf0e10cSrcweir return (Reference< XConnection >)m_pConnection; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir // ----------------------------------------------------------------------------- 165cdf0e10cSrcweir sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir return 0; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir // ------------------------------------------------------------------------- 170cdf0e10cSrcweir 171cdf0e10cSrcweir Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this)); 174cdf0e10cSrcweir if(!aRet.hasValue()) 175cdf0e10cSrcweir aRet = OStatement_Base::queryInterface(rType); 176cdf0e10cSrcweir return aRet; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir // ------------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 183cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir m_aBatchList.push_back(sql); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir // ------------------------------------------------------------------------- 189cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 192cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 193cdf0e10cSrcweir 194cdf0e10cSrcweir return Sequence< sal_Int32 >(); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir // ------------------------------------------------------------------------- 197cdf0e10cSrcweir 198cdf0e10cSrcweir 199cdf0e10cSrcweir sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 202cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 203cdf0e10cSrcweir 204cdf0e10cSrcweir // the return values gives information about how many rows are affected by executing the sql statement 205cdf0e10cSrcweir return 0; 206cdf0e10cSrcweir 207cdf0e10cSrcweir } 208cdf0e10cSrcweir // ------------------------------------------------------------------------- 209cdf0e10cSrcweir 210cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 213cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 214cdf0e10cSrcweir 215cdf0e10cSrcweir // return our save resultset here 216cdf0e10cSrcweir return m_xResultSet; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir // ------------------------------------------------------------------------- 219cdf0e10cSrcweir 220cdf0e10cSrcweir sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 223cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 224cdf0e10cSrcweir 225cdf0e10cSrcweir // if your driver supports more than only one resultset 226cdf0e10cSrcweir // and has one more at this moment return true 227cdf0e10cSrcweir return sal_False; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir // ------------------------------------------------------------------------- 230cdf0e10cSrcweir 231cdf0e10cSrcweir // ------------------------------------------------------------------------- 232cdf0e10cSrcweir Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 235cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 236cdf0e10cSrcweir 237cdf0e10cSrcweir 238cdf0e10cSrcweir return makeAny(m_aLastWarning); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir // ------------------------------------------------------------------------- 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ------------------------------------------------------------------------- 243cdf0e10cSrcweir void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 246cdf0e10cSrcweir checkDisposed(OStatement_BASE::rBHelper.bDisposed); 247cdf0e10cSrcweir 248cdf0e10cSrcweir 249cdf0e10cSrcweir m_aLastWarning = SQLWarning(); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir // ------------------------------------------------------------------------- 252cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const 253cdf0e10cSrcweir { 254cdf0e10cSrcweir // this properties are define by the service statement 255cdf0e10cSrcweir // they must in alphabetic order 256cdf0e10cSrcweir Sequence< Property > aProps(10); 257cdf0e10cSrcweir Property* pProperties = aProps.getArray(); 258cdf0e10cSrcweir sal_Int32 nPos = 0; 259cdf0e10cSrcweir DECL_PROP0(CURSORNAME, ::rtl::OUString); 260cdf0e10cSrcweir DECL_BOOL_PROP0(ESCAPEPROCESSING); 261cdf0e10cSrcweir DECL_PROP0(FETCHDIRECTION,sal_Int32); 262cdf0e10cSrcweir DECL_PROP0(FETCHSIZE, sal_Int32); 263cdf0e10cSrcweir DECL_PROP0(MAXFIELDSIZE,sal_Int32); 264cdf0e10cSrcweir DECL_PROP0(MAXROWS, sal_Int32); 265cdf0e10cSrcweir DECL_PROP0(QUERYTIMEOUT,sal_Int32); 266cdf0e10cSrcweir DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); 267cdf0e10cSrcweir DECL_PROP0(RESULTSETTYPE,sal_Int32); 268cdf0e10cSrcweir DECL_BOOL_PROP0(USEBOOKMARKS); 269cdf0e10cSrcweir 270cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir // ------------------------------------------------------------------------- 274cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() 275cdf0e10cSrcweir { 276cdf0e10cSrcweir return *const_cast<OStatement_Base*>(this)->getArrayHelper(); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir // ------------------------------------------------------------------------- 279cdf0e10cSrcweir sal_Bool OStatement_Base::convertFastPropertyValue( 280cdf0e10cSrcweir Any & rConvertedValue, 281cdf0e10cSrcweir Any & rOldValue, 282cdf0e10cSrcweir sal_Int32 nHandle, 283cdf0e10cSrcweir const Any& rValue ) 284cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir sal_Bool bConverted = sal_False; 287cdf0e10cSrcweir // here we have to try to convert 288cdf0e10cSrcweir return bConverted; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir // ------------------------------------------------------------------------- 291cdf0e10cSrcweir void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir // set the value to what ever is nescessary 294cdf0e10cSrcweir switch(nHandle) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 297cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 298cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 299cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 300cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 301cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 302cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 303cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 304cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 305cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 306cdf0e10cSrcweir default: 307cdf0e10cSrcweir ; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir // ------------------------------------------------------------------------- 311cdf0e10cSrcweir void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const 312cdf0e10cSrcweir { 313cdf0e10cSrcweir switch(nHandle) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 316cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 317cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 318cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 319cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 320cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 321cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 322cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 323cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 324cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 325cdf0e10cSrcweir default: 326cdf0e10cSrcweir ; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir } 329cdf0e10cSrcweir // ------------------------------------------------------------------------- 330cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); 331cdf0e10cSrcweir // ----------------------------------------------------------------------------- 332cdf0e10cSrcweir void SAL_CALL OStatement_Base::acquire() throw() 333cdf0e10cSrcweir { 334cdf0e10cSrcweir OStatement_BASE::acquire(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir // ----------------------------------------------------------------------------- 337cdf0e10cSrcweir void SAL_CALL OStatement_Base::release() throw() 338cdf0e10cSrcweir { 339cdf0e10cSrcweir OStatement_BASE::release(); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir // ----------------------------------------------------------------------------- 342cdf0e10cSrcweir void SAL_CALL OStatement::acquire() throw() 343cdf0e10cSrcweir { 344cdf0e10cSrcweir OStatement_BASE2::acquire(); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir // ----------------------------------------------------------------------------- 347cdf0e10cSrcweir void SAL_CALL OStatement::release() throw() 348cdf0e10cSrcweir { 349cdf0e10cSrcweir OStatement_BASE2::release(); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir // ----------------------------------------------------------------------------- 352cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(RuntimeException) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir // ----------------------------------------------------------------------------- 357cdf0e10cSrcweir 358