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