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