1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/sdbcx/CompareBookmark.hpp> 31*cdf0e10cSrcweir #include "dbase/DResultSet.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 33*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 34*cdf0e10cSrcweir #include "dbase/DIndex.hxx" 35*cdf0e10cSrcweir #include "dbase/DIndexIter.hxx" 36*cdf0e10cSrcweir #include "dbase/DCode.hxx" 37*cdf0e10cSrcweir #include <comphelper/types.hxx> 38*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 39*cdf0e10cSrcweir #include "resource/dbase_res.hrc" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::comphelper; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace connectivity::dbase; 44*cdf0e10cSrcweir using namespace connectivity::file; 45*cdf0e10cSrcweir using namespace ::cppu; 46*cdf0e10cSrcweir using namespace com::sun::star::uno; 47*cdf0e10cSrcweir using namespace com::sun::star::lang; 48*cdf0e10cSrcweir using namespace com::sun::star::beans; 49*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 50*cdf0e10cSrcweir using namespace com::sun::star::sdbcx; 51*cdf0e10cSrcweir // using namespace com::sun::star::container; 52*cdf0e10cSrcweir // using namespace com::sun::star::util; 53*cdf0e10cSrcweir //------------------------------------------------------------------------------ 54*cdf0e10cSrcweir ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator) 55*cdf0e10cSrcweir : file::OResultSet(pStmt,_aSQLIterator) 56*cdf0e10cSrcweir ,m_bBookmarkable(sal_True) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, ::getBooleanCppuType()); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir // ------------------------------------------------------------------------- 61*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODbaseResultSet::getImplementationName( ) throw ( RuntimeException) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.dbase.ResultSet"); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir // ------------------------------------------------------------------------- 66*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( ) throw( RuntimeException) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(2); 69*cdf0e10cSrcweir aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet"); 70*cdf0e10cSrcweir aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet"); 71*cdf0e10cSrcweir return aSupported; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir // ------------------------------------------------------------------------- 74*cdf0e10cSrcweir sal_Bool SAL_CALL ODbaseResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); 77*cdf0e10cSrcweir const ::rtl::OUString* pSupported = aSupported.getConstArray(); 78*cdf0e10cSrcweir const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 79*cdf0e10cSrcweir for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 80*cdf0e10cSrcweir ; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir return pSupported != pEnd; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir // ------------------------------------------------------------------------- 85*cdf0e10cSrcweir Any SAL_CALL ODbaseResultSet::queryInterface( const Type & rType ) throw(RuntimeException) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir Any aRet = ODbaseResultSet_BASE::queryInterface(rType); 88*cdf0e10cSrcweir return aRet.hasValue() ? aRet : OResultSet::queryInterface(rType); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir // ------------------------------------------------------------------------- 91*cdf0e10cSrcweir Sequence< Type > SAL_CALL ODbaseResultSet::getTypes( ) throw( RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir return ::comphelper::concatSequences(OResultSet::getTypes(),ODbaseResultSet_BASE::getTypes()); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // ------------------------------------------------------------------------- 97*cdf0e10cSrcweir // XRowLocate 98*cdf0e10cSrcweir Any SAL_CALL ODbaseResultSet::getBookmark( ) throw( SQLException, RuntimeException) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 101*cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed); 102*cdf0e10cSrcweir OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row"); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir return makeAny((sal_Int32)(m_aRow->get())[0]->getValue()); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir // ------------------------------------------------------------------------- 107*cdf0e10cSrcweir sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 110*cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir return m_pTable ? Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True) : sal_False; 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir // ------------------------------------------------------------------------- 118*cdf0e10cSrcweir sal_Bool SAL_CALL ODbaseResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 121*cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed); 122*cdf0e10cSrcweir if(!m_pTable) 123*cdf0e10cSrcweir return sal_False; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir return relative(rows); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ------------------------------------------------------------------------- 132*cdf0e10cSrcweir sal_Int32 SAL_CALL ODbaseResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir sal_Int32 nFirst(0),nSecond(0),nResult(0); 135*cdf0e10cSrcweir if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 138*cdf0e10cSrcweir const ::rtl::OUString sMessage = aResources.getResourceString(STR_INVALID_BOOKMARK); 139*cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sMessage ,*this); 140*cdf0e10cSrcweir } // if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) ) 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // have a look at CompareBookmark 143*cdf0e10cSrcweir // we can't use the names there because we already have defines with the same name from the parser 144*cdf0e10cSrcweir if(nFirst < nSecond) 145*cdf0e10cSrcweir nResult = -1; 146*cdf0e10cSrcweir else if(nFirst > nSecond) 147*cdf0e10cSrcweir nResult = 1; 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir nResult = 0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir return nResult; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir // ------------------------------------------------------------------------- 154*cdf0e10cSrcweir sal_Bool SAL_CALL ODbaseResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return sal_True; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir // ------------------------------------------------------------------------- 159*cdf0e10cSrcweir sal_Int32 SAL_CALL ODbaseResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 162*cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return comphelper::getINT32(bookmark); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir // ------------------------------------------------------------------------- 168*cdf0e10cSrcweir // XDeleteRows 169*cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw( SQLException, RuntimeException) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 172*cdf0e10cSrcweir checkDisposed(OResultSet_BASE::rBHelper.bDisposed); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir ::dbtools::throwFeatureNotImplementedException( "XDeleteRows::deleteRows", *this ); 175*cdf0e10cSrcweir return Sequence< sal_Int32 >(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir // ------------------------------------------------------------------------- 178*cdf0e10cSrcweir sal_Bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir Reference<XUnoTunnel> xTunnel(_xIndex,UNO_QUERY); 181*cdf0e10cSrcweir if(xTunnel.is()) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir dbase::ODbaseIndex* pIndex = reinterpret_cast< dbase::ODbaseIndex* >( xTunnel->getSomething(dbase::ODbaseIndex::getUnoTunnelImplementationId()) ); 184*cdf0e10cSrcweir if(pIndex) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir dbase::OIndexIterator* pIter = pIndex->createIterator(NULL,NULL); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if (pIter) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir sal_uInt32 nRec = pIter->First(); 191*cdf0e10cSrcweir while (nRec != SQL_COLUMN_NOTFOUND) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir if (m_aOrderbyAscending[0]) 194*cdf0e10cSrcweir m_pFileSet->get().push_back(nRec); 195*cdf0e10cSrcweir else 196*cdf0e10cSrcweir m_pFileSet->get().insert(m_pFileSet->get().begin(),nRec); 197*cdf0e10cSrcweir nRec = pIter->Next(); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir m_pFileSet->setFrozen(); 200*cdf0e10cSrcweir // if(!bDistinct) 201*cdf0e10cSrcweir // SetRowCount(pFileSet->count()); 202*cdf0e10cSrcweir delete pIter; 203*cdf0e10cSrcweir return sal_True; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir delete pIter; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir return sal_False; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir // ------------------------------------------------------------------------- 211*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper() 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir return *ODbaseResultSet_BASE3::getArrayHelper(); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 216*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir Sequence< Property > aProps; 219*cdf0e10cSrcweir describeProperties(aProps); 220*cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 223*cdf0e10cSrcweir void SAL_CALL ODbaseResultSet::acquire() throw() 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir ODbaseResultSet_BASE2::acquire(); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 228*cdf0e10cSrcweir void SAL_CALL ODbaseResultSet::release() throw() 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir ODbaseResultSet_BASE2::release(); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 233*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 238*cdf0e10cSrcweir OSQLAnalyzer* ODbaseResultSet::createAnalyzer() 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir return new OFILEAnalyzer(m_pTable->getConnection()); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 243*cdf0e10cSrcweir sal_Int32 ODbaseResultSet::getCurrentFilePos() const 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir return m_pTable->getFilePos(); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir 250