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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "ado/AStatement.hxx" 27 #include "ado/AConnection.hxx" 28 #include "ado/AResultSet.hxx" 29 #include <comphelper/property.hxx> 30 #include <comphelper/uno3.hxx> 31 #include <osl/thread.h> 32 #include <cppuhelper/typeprovider.hxx> 33 #include <comphelper/sequence.hxx> 34 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> 35 #include <com/sun/star/sdbc/ResultSetType.hpp> 36 #include <com/sun/star/sdbc/FetchDirection.hpp> 37 #include "connectivity/dbexception.hxx" 38 #include <comphelper/types.hxx> 39 40 #undef max 41 42 #include <algorithm> 43 44 using namespace ::comphelper; 45 46 #define CHECK_RETURN(x) \ 47 if(!x) \ 48 ADOS::ThrowException(*m_pConnection->getConnection(),*this); 49 50 51 52 using namespace connectivity::ado; 53 54 //------------------------------------------------------------------------------ 55 using namespace com::sun::star::uno; 56 using namespace com::sun::star::lang; 57 using namespace com::sun::star::beans; 58 using namespace com::sun::star::sdbc; 59 using namespace ::std; 60 //------------------------------------------------------------------------------ 61 OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex) 62 ,OPropertySetHelper(OStatement_BASE::rBHelper) 63 ,OSubComponent<OStatement_Base, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this) 64 ,m_pConnection(_pConnection) 65 ,m_nFetchSize(1) 66 ,m_nMaxRows(0) 67 ,m_eLockType(adLockReadOnly) 68 ,m_eCursorType(adOpenForwardOnly) 69 { 70 osl_incrementInterlockedCount( &m_refCount ); 71 72 m_Command.Create(); 73 if(m_Command.IsValid()) 74 m_Command.putref_ActiveConnection(m_pConnection->getConnection()); 75 else 76 ADOS::ThrowException(*m_pConnection->getConnection(),*this); 77 78 m_RecordsAffected.setNoArg(); 79 m_Parameters.setNoArg(); 80 81 m_pConnection->acquire(); 82 83 osl_decrementInterlockedCount( &m_refCount ); 84 } 85 //------------------------------------------------------------------------------ 86 void OStatement_Base::disposeResultSet() 87 { 88 // free the cursor if alive 89 Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); 90 if (xComp.is()) 91 xComp->dispose(); 92 m_xResultSet = Reference< XResultSet>(); 93 } 94 95 //------------------------------------------------------------------------------ 96 void OStatement_Base::disposing() 97 { 98 ::osl::MutexGuard aGuard(m_aMutex); 99 100 101 disposeResultSet(); 102 103 if ( m_Command.IsValid() ) 104 m_Command.putref_ActiveConnection( NULL ); 105 m_Command.clear(); 106 107 if ( m_RecordSet.IsValid() ) 108 m_RecordSet.PutRefDataSource( NULL ); 109 m_RecordSet.clear(); 110 111 if (m_pConnection) 112 m_pConnection->release(); 113 114 dispose_ChildImpl(); 115 OStatement_BASE::disposing(); 116 } 117 //----------------------------------------------------------------------------- 118 void SAL_CALL OStatement_Base::release() throw() 119 { 120 relase_ChildImpl(); 121 } 122 //----------------------------------------------------------------------------- 123 Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) 124 { 125 Any aRet = OStatement_BASE::queryInterface(rType); 126 return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType); 127 } 128 // ------------------------------------------------------------------------- 129 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OStatement_Base::getTypes( ) throw(::com::sun::star::uno::RuntimeException) 130 { 131 ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), 132 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), 133 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); 134 135 return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes()); 136 } 137 138 // ------------------------------------------------------------------------- 139 140 void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) 141 { 142 ::osl::MutexGuard aGuard( m_aMutex ); 143 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 144 145 146 CHECK_RETURN(m_Command.Cancel()) 147 } 148 // ------------------------------------------------------------------------- 149 150 void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) 151 { 152 { 153 ::osl::MutexGuard aGuard( m_aMutex ); 154 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 155 156 } 157 dispose(); 158 } 159 // ------------------------------------------------------------------------- 160 161 void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException) 162 { 163 164 } 165 // ------------------------------------------------------------------------- 166 167 void OStatement_Base::reset() throw (SQLException) 168 { 169 ::osl::MutexGuard aGuard( m_aMutex ); 170 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 171 172 173 clearWarnings (); 174 175 if (m_xResultSet.get().is()) 176 clearMyResultSet(); 177 } 178 //-------------------------------------------------------------------- 179 // clearMyResultSet 180 // If a ResultSet was created for this Statement, close it 181 //-------------------------------------------------------------------- 182 183 void OStatement_Base::clearMyResultSet () throw (SQLException) 184 { 185 ::osl::MutexGuard aGuard( m_aMutex ); 186 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 187 188 try 189 { 190 Reference<XCloseable> xCloseable; 191 if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) ) 192 xCloseable->close(); 193 } 194 catch( const DisposedException& ) { } 195 196 m_xResultSet = Reference< XResultSet >(); 197 } 198 //-------------------------------------------------------------------- 199 sal_Int32 OStatement_Base::getRowCount () throw( SQLException) 200 { 201 ::osl::MutexGuard aGuard( m_aMutex ); 202 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 203 204 205 return m_RecordsAffected; 206 } 207 //-------------------------------------------------------------------- 208 // getPrecision 209 // Given a SQL type, return the maximum precision for the column. 210 // Returns -1 if not known 211 //-------------------------------------------------------------------- 212 213 sal_Int32 OStatement_Base::getPrecision ( sal_Int32 sqlType) 214 { 215 ::osl::MutexGuard aGuard( m_aMutex ); 216 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 217 218 219 sal_Int32 prec = -1; 220 OTypeInfo aInfo; 221 aInfo.nType = (sal_Int16)sqlType; 222 if (!m_aTypeInfo.empty()) 223 { 224 ::std::vector<OTypeInfo>::const_iterator aIter = ::std::find(m_aTypeInfo.begin(),m_aTypeInfo.end(),aInfo); 225 for(;aIter != m_aTypeInfo.end();++aIter) 226 { 227 prec = ::std::max(prec,(*aIter).nPrecision); 228 } 229 } 230 231 return prec; 232 } 233 //-------------------------------------------------------------------- 234 // setWarning 235 // Sets the warning 236 //-------------------------------------------------------------------- 237 238 void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException) 239 { 240 ::osl::MutexGuard aGuard( m_aMutex ); 241 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 242 243 244 m_aLastWarning = ex; 245 } 246 // ------------------------------------------------------------------------- 247 void OStatement_Base::assignRecordSet( ADORecordset* _pRS ) 248 { 249 WpADORecordset aOldRS( m_RecordSet ); 250 m_RecordSet = WpADORecordset( _pRS ); 251 252 if ( aOldRS.IsValid() ) 253 aOldRS.PutRefDataSource( NULL ); 254 255 if ( m_RecordSet.IsValid() ) 256 m_RecordSet.PutRefDataSource( (IDispatch*)m_Command ); 257 } 258 // ------------------------------------------------------------------------- 259 sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 260 { 261 ::osl::MutexGuard aGuard( m_aMutex ); 262 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 263 264 265 // Reset the statement handle and warning 266 267 reset(); 268 269 try 270 { 271 ADORecordset* pSet = NULL; 272 CHECK_RETURN(m_Command.put_CommandText(sql)) 273 CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText,&pSet)) 274 275 assignRecordSet( pSet ); 276 } 277 catch (SQLWarning& ex) 278 { 279 280 // Save pointer to warning and save with ResultSet 281 // object once it is created. 282 283 m_aLastWarning = ex; 284 } 285 286 return m_RecordSet.IsValid(); 287 } 288 // ------------------------------------------------------------------------- 289 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 290 { 291 ::osl::MutexGuard aGuard( m_aMutex ); 292 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 293 294 295 reset(); 296 297 m_xResultSet = WeakReference<XResultSet>(NULL); 298 299 WpADORecordset aSet; 300 aSet.Create(); 301 CHECK_RETURN(m_Command.put_CommandText(sql)) 302 OLEVariant aCmd; 303 aCmd.setIDispatch(m_Command); 304 OLEVariant aCon; 305 aCon.setNoArg(); 306 CHECK_RETURN(aSet.put_CacheSize(m_nFetchSize)) 307 CHECK_RETURN(aSet.put_MaxRecords(m_nMaxRows)) 308 CHECK_RETURN(aSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified)) 309 310 311 CHECK_RETURN(aSet.get_CacheSize(m_nFetchSize)) 312 CHECK_RETURN(aSet.get_MaxRecords(m_nMaxRows)) 313 CHECK_RETURN(aSet.get_CursorType(m_eCursorType)) 314 CHECK_RETURN(aSet.get_LockType(m_eLockType)) 315 316 OResultSet* pSet = new OResultSet(aSet,this); 317 Reference< XResultSet > xRs = pSet; 318 pSet->construct(); 319 320 m_xResultSet = WeakReference<XResultSet>(xRs); 321 322 return xRs; 323 } 324 // ------------------------------------------------------------------------- 325 326 Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) 327 { 328 ::osl::MutexGuard aGuard( m_aMutex ); 329 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 330 331 332 return (Reference< XConnection >)m_pConnection; 333 } 334 // ------------------------------------------------------------------------- 335 336 Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException) 337 { 338 Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this)); 339 return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType); 340 } 341 // ------------------------------------------------------------------------- 342 343 void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 344 { 345 ::osl::MutexGuard aGuard( m_aMutex ); 346 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 347 348 349 m_aBatchList.push_back(sql); 350 } 351 // ------------------------------------------------------------------------- 352 Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException) 353 { 354 ::osl::MutexGuard aGuard( m_aMutex ); 355 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 356 357 358 reset(); 359 360 ::rtl::OUString aBatchSql; 361 sal_Int32 nLen = 0; 362 for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen) 363 aBatchSql = aBatchSql + *i + ::rtl::OUString::createFromAscii(";"); 364 365 366 if ( m_RecordSet.IsValid() ) 367 m_RecordSet.PutRefDataSource( NULL ); 368 m_RecordSet.clear(); 369 m_RecordSet.Create(); 370 371 CHECK_RETURN(m_Command.put_CommandText(aBatchSql)) 372 if ( m_RecordSet.IsValid() ) 373 m_RecordSet.PutRefDataSource((IDispatch*)m_Command); 374 375 CHECK_RETURN(m_RecordSet.UpdateBatch(adAffectAll)) 376 377 ADORecordset* pSet=NULL; 378 Sequence< sal_Int32 > aRet(nLen); 379 sal_Int32* pArray = aRet.getArray(); 380 for(sal_Int32 j=0;j<nLen;++j) 381 { 382 pSet = NULL; 383 OLEVariant aRecordsAffected; 384 if(m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet) 385 { 386 assignRecordSet( pSet ); 387 388 sal_Int32 nValue; 389 if(m_RecordSet.get_RecordCount(nValue)) 390 pArray[j] = nValue; 391 } 392 } 393 return aRet; 394 } 395 // ------------------------------------------------------------------------- 396 397 398 sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 399 { 400 ::osl::MutexGuard aGuard( m_aMutex ); 401 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 402 403 404 reset(); 405 406 try { 407 ADORecordset* pSet = NULL; 408 CHECK_RETURN(m_Command.put_CommandText(sql)) 409 CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText|adExecuteNoRecords,&pSet)) 410 } 411 catch (SQLWarning& ex) { 412 413 // Save pointer to warning and save with ResultSet 414 // object once it is created. 415 416 m_aLastWarning = ex; 417 } 418 if(!m_RecordsAffected.isEmpty() && !m_RecordsAffected.isNull() && m_RecordsAffected.getType() != VT_ERROR) 419 return m_RecordsAffected; 420 421 return 0; 422 } 423 // ------------------------------------------------------------------------- 424 425 Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException) 426 { 427 ::osl::MutexGuard aGuard( m_aMutex ); 428 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 429 430 431 return m_xResultSet; 432 } 433 // ------------------------------------------------------------------------- 434 435 sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(SQLException, RuntimeException) 436 { 437 ::osl::MutexGuard aGuard( m_aMutex ); 438 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 439 440 441 sal_Int32 nRet; 442 if(m_RecordSet.IsValid() && m_RecordSet.get_RecordCount(nRet)) 443 return nRet; 444 return -1; 445 } 446 // ------------------------------------------------------------------------- 447 448 sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException) 449 { 450 ::osl::MutexGuard aGuard( m_aMutex ); 451 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 452 453 454 SQLWarning warning; 455 456 // clear previous warnings 457 458 clearWarnings (); 459 460 // Call SQLMoreResults 461 462 try 463 { 464 ADORecordset* pSet=NULL; 465 OLEVariant aRecordsAffected; 466 if(m_RecordSet.IsValid() && m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet) 467 assignRecordSet( pSet ); 468 } 469 catch (SQLWarning &ex) 470 { 471 472 // Save pointer to warning and save with ResultSet 473 // object once it is created. 474 475 warning = ex; 476 } 477 return m_RecordSet.IsValid(); 478 } 479 // ------------------------------------------------------------------------- 480 481 // ------------------------------------------------------------------------- 482 Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) 483 { 484 ::osl::MutexGuard aGuard( m_aMutex ); 485 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 486 487 488 return makeAny(m_aLastWarning); 489 } 490 // ------------------------------------------------------------------------- 491 492 // ------------------------------------------------------------------------- 493 void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) 494 { 495 ::osl::MutexGuard aGuard( m_aMutex ); 496 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 497 498 499 m_aLastWarning = SQLWarning(); 500 } 501 // ------------------------------------------------------------------------- 502 //------------------------------------------------------------------------------ 503 sal_Int32 OStatement_Base::getQueryTimeOut() const throw(SQLException, RuntimeException) 504 { 505 return m_Command.get_CommandTimeout(); 506 } 507 //------------------------------------------------------------------------------ 508 sal_Int32 OStatement_Base::getMaxRows() const throw(SQLException, RuntimeException) 509 { 510 sal_Int32 nRet=-1; 511 if(!(m_RecordSet.IsValid() && m_RecordSet.get_MaxRecords(nRet))) 512 ::dbtools::throwFunctionSequenceException(NULL); 513 return nRet; 514 } 515 //------------------------------------------------------------------------------ 516 sal_Int32 OStatement_Base::getResultSetConcurrency() const throw(SQLException, RuntimeException) 517 { 518 return m_eLockType; 519 sal_Int32 nValue=0; 520 switch(m_eLockType) 521 { 522 case adLockReadOnly: 523 nValue = ResultSetConcurrency::READ_ONLY; 524 break; 525 default: 526 nValue = ResultSetConcurrency::UPDATABLE; 527 break; 528 } 529 530 return nValue; 531 } 532 //------------------------------------------------------------------------------ 533 sal_Int32 OStatement_Base::getResultSetType() const throw(SQLException, RuntimeException) 534 { 535 sal_Int32 nValue=0; 536 switch(m_eCursorType) 537 { 538 case adOpenUnspecified: 539 case adOpenForwardOnly: 540 nValue = ResultSetType::FORWARD_ONLY; 541 break; 542 case adOpenStatic: 543 case adOpenKeyset: 544 nValue = ResultSetType::SCROLL_INSENSITIVE; 545 break; 546 case adOpenDynamic: 547 nValue = ResultSetType::SCROLL_SENSITIVE; 548 break; 549 } 550 return nValue; 551 } 552 //------------------------------------------------------------------------------ 553 sal_Int32 OStatement_Base::getFetchDirection() const throw(SQLException, RuntimeException) 554 { 555 return FetchDirection::FORWARD; 556 } 557 //------------------------------------------------------------------------------ 558 sal_Int32 OStatement_Base::getFetchSize() const throw(SQLException, RuntimeException) 559 { 560 return m_nFetchSize; 561 } 562 //------------------------------------------------------------------------------ 563 sal_Int32 OStatement_Base::getMaxFieldSize() const throw(SQLException, RuntimeException) 564 { 565 return 0; 566 } 567 //------------------------------------------------------------------------------ 568 ::rtl::OUString OStatement_Base::getCursorName() const throw(SQLException, RuntimeException) 569 { 570 return m_Command.GetName(); 571 } 572 //------------------------------------------------------------------------------ 573 void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) throw(SQLException, RuntimeException) 574 { 575 ::osl::MutexGuard aGuard( m_aMutex ); 576 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 577 578 579 m_Command.put_CommandTimeout(seconds); 580 } 581 //------------------------------------------------------------------------------ 582 void OStatement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException) 583 { 584 ::osl::MutexGuard aGuard( m_aMutex ); 585 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 586 587 m_nMaxRows = _par0; 588 } 589 //------------------------------------------------------------------------------ 590 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException) 591 { 592 ::osl::MutexGuard aGuard( m_aMutex ); 593 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 594 595 switch(_par0) 596 { 597 case ResultSetConcurrency::READ_ONLY: 598 m_eLockType = adLockReadOnly; 599 break; 600 default: 601 m_eLockType = adLockOptimistic; 602 break; 603 } 604 } 605 //------------------------------------------------------------------------------ 606 void OStatement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException) 607 { 608 ::osl::MutexGuard aGuard( m_aMutex ); 609 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 610 611 612 switch(_par0) 613 { 614 case ResultSetType::FORWARD_ONLY: 615 m_eCursorType = adOpenForwardOnly; 616 break; 617 case ResultSetType::SCROLL_INSENSITIVE: 618 m_eCursorType = adOpenKeyset; 619 break; 620 case ResultSetType::SCROLL_SENSITIVE: 621 m_eCursorType = adOpenDynamic; 622 break; 623 } 624 } 625 //------------------------------------------------------------------------------ 626 void OStatement_Base::setFetchDirection(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException) 627 { 628 ::osl::MutexGuard aGuard( m_aMutex ); 629 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 630 ::dbtools::throwFeatureNotImplementedException( "Statement::FetchDirection", *this ); 631 } 632 //------------------------------------------------------------------------------ 633 void OStatement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException) 634 { 635 ::osl::MutexGuard aGuard( m_aMutex ); 636 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 637 638 639 m_nFetchSize = _par0; 640 // m_RecordSet.put_CacheSize(_par0); 641 } 642 //------------------------------------------------------------------------------ 643 void OStatement_Base::setMaxFieldSize(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException) 644 { 645 ::osl::MutexGuard aGuard( m_aMutex ); 646 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 647 ::dbtools::throwFeatureNotImplementedException( "Statement::MaxFieldSize", *this ); 648 } 649 //------------------------------------------------------------------------------ 650 void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException) 651 { 652 ::osl::MutexGuard aGuard( m_aMutex ); 653 checkDisposed(OStatement_BASE::rBHelper.bDisposed); 654 655 m_Command.put_Name(_par0); 656 } 657 658 // ------------------------------------------------------------------------- 659 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const 660 { 661 Sequence< com::sun::star::beans::Property > aProps(10); 662 com::sun::star::beans::Property* pProperties = aProps.getArray(); 663 sal_Int32 nPos = 0; 664 DECL_PROP0(CURSORNAME, ::rtl::OUString); 665 DECL_BOOL_PROP0(ESCAPEPROCESSING); 666 DECL_PROP0(FETCHDIRECTION,sal_Int32); 667 DECL_PROP0(FETCHSIZE, sal_Int32); 668 DECL_PROP0(MAXFIELDSIZE,sal_Int32); 669 DECL_PROP0(MAXROWS, sal_Int32); 670 DECL_PROP0(QUERYTIMEOUT,sal_Int32); 671 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); 672 DECL_PROP0(RESULTSETTYPE,sal_Int32); 673 DECL_BOOL_PROP0(USEBOOKMARKS); 674 675 676 return new ::cppu::OPropertyArrayHelper(aProps); 677 } 678 679 // ------------------------------------------------------------------------- 680 ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() 681 { 682 return *const_cast<OStatement_Base*>(this)->getArrayHelper(); 683 } 684 // ------------------------------------------------------------------------- 685 sal_Bool OStatement_Base::convertFastPropertyValue( 686 Any & rConvertedValue, 687 Any & rOldValue, 688 sal_Int32 nHandle, 689 const Any& rValue ) 690 throw (::com::sun::star::lang::IllegalArgumentException) 691 { 692 sal_Bool bModified = sal_False; 693 694 sal_Bool bValidAdoRS = m_RecordSet.IsValid(); 695 // some of the properties below, when set, are remembered in a member, and applied in the next execute 696 // For these properties, the record set does not need to be valid to allow setting them. 697 // For all others (where the values are forwarded to the ADO RS directly), the recordset must be valid. 698 699 try 700 { 701 switch(nHandle) 702 { 703 case PROPERTY_ID_MAXROWS: 704 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, bValidAdoRS ? getMaxRows() : m_nMaxRows ); 705 break; 706 707 case PROPERTY_ID_RESULTSETTYPE: 708 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType()); 709 break; 710 case PROPERTY_ID_FETCHSIZE: 711 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); 712 break; 713 case PROPERTY_ID_RESULTSETCONCURRENCY: 714 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency()); 715 break; 716 case PROPERTY_ID_QUERYTIMEOUT: 717 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut()); 718 break; 719 case PROPERTY_ID_MAXFIELDSIZE: 720 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize()); 721 break; 722 case PROPERTY_ID_CURSORNAME: 723 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName()); 724 break; 725 case PROPERTY_ID_FETCHDIRECTION: 726 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); 727 break; 728 } 729 } 730 catch( const Exception& e ) 731 { 732 bModified = sal_True; // will ensure that the property is set 733 OSL_ENSURE( sal_False, "OStatement_Base::convertFastPropertyValue: caught something strange!" ); 734 (void)e; 735 } 736 return bModified; 737 } 738 // ------------------------------------------------------------------------- 739 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) 740 { 741 switch(nHandle) 742 { 743 case PROPERTY_ID_QUERYTIMEOUT: 744 setQueryTimeOut(comphelper::getINT32(rValue)); 745 break; 746 case PROPERTY_ID_MAXFIELDSIZE: 747 setMaxFieldSize(comphelper::getINT32(rValue)); 748 break; 749 case PROPERTY_ID_MAXROWS: 750 setMaxRows(comphelper::getINT32(rValue)); 751 break; 752 case PROPERTY_ID_CURSORNAME: 753 setCursorName(comphelper::getString(rValue)); 754 break; 755 case PROPERTY_ID_RESULTSETCONCURRENCY: 756 setResultSetConcurrency(comphelper::getINT32(rValue)); 757 break; 758 case PROPERTY_ID_RESULTSETTYPE: 759 setResultSetType(comphelper::getINT32(rValue)); 760 break; 761 case PROPERTY_ID_FETCHDIRECTION: 762 setFetchDirection(comphelper::getINT32(rValue)); 763 break; 764 case PROPERTY_ID_FETCHSIZE: 765 setFetchSize(comphelper::getINT32(rValue)); 766 break; 767 case PROPERTY_ID_ESCAPEPROCESSING: 768 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); 769 case PROPERTY_ID_USEBOOKMARKS: 770 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); 771 default: 772 ; 773 } 774 } 775 // ------------------------------------------------------------------------- 776 void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const 777 { 778 switch(nHandle) 779 { 780 case PROPERTY_ID_QUERYTIMEOUT: 781 rValue <<= getQueryTimeOut(); 782 break; 783 case PROPERTY_ID_MAXFIELDSIZE: 784 rValue <<= getMaxFieldSize(); 785 break; 786 case PROPERTY_ID_MAXROWS: 787 rValue <<= getMaxRows(); 788 break; 789 case PROPERTY_ID_CURSORNAME: 790 rValue <<= getCursorName(); 791 break; 792 case PROPERTY_ID_RESULTSETCONCURRENCY: 793 rValue <<= getResultSetConcurrency(); 794 break; 795 case PROPERTY_ID_RESULTSETTYPE: 796 rValue <<= getResultSetType(); 797 break; 798 case PROPERTY_ID_FETCHDIRECTION: 799 rValue <<= getFetchDirection(); 800 break; 801 case PROPERTY_ID_FETCHSIZE: 802 rValue <<= getFetchSize(); 803 break; 804 case PROPERTY_ID_ESCAPEPROCESSING: 805 rValue <<= sal_True; 806 break; 807 case PROPERTY_ID_USEBOOKMARKS: 808 default: 809 ; 810 } 811 } 812 // ------------------------------------------------------------------------- 813 OStatement::~OStatement() 814 { 815 } 816 IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.AStatement","com.sun.star.sdbc.Statement"); 817 // ----------------------------------------------------------------------------- 818 void SAL_CALL OStatement_Base::acquire() throw() 819 { 820 OStatement_BASE::acquire(); 821 } 822 // ----------------------------------------------------------------------------- 823 void SAL_CALL OStatement::acquire() throw() 824 { 825 OStatement_Base::acquire(); 826 } 827 // ----------------------------------------------------------------------------- 828 void SAL_CALL OStatement::release() throw() 829 { 830 OStatement_Base::release(); 831 } 832 // ----------------------------------------------------------------------------- 833 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) 834 { 835 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 836 } 837 // ----------------------------------------------------------------------------- 838