Use correct object
[LibreOffice.git] / connectivity / source / drivers / dbase / DResultSet.cxx
blob99357a01fcc8dba92bd9e610bc05eab57758a764
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
21 #include <dbase/DResultSet.hxx>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <comphelper/sequence.hxx>
24 #include <comphelper/servicehelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <dbase/DIndex.hxx>
27 #include <dbase/DIndexIter.hxx>
28 #include <comphelper/types.hxx>
29 #include <connectivity/dbexception.hxx>
30 #include <strings.hrc>
32 using namespace ::comphelper;
34 using namespace connectivity::dbase;
35 using namespace connectivity::file;
36 using namespace ::cppu;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::beans;
40 using namespace com::sun::star::sdbc;
41 using namespace com::sun::star::sdbcx;
43 ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator)
44 : file::OResultSet(pStmt,_aSQLIterator)
45 ,m_bBookmarkable(true)
47 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, cppu::UnoType<bool>::get());
50 OUString SAL_CALL ODbaseResultSet::getImplementationName( )
52 return u"com.sun.star.sdbcx.dbase.ResultSet"_ustr;
55 Sequence< OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( )
57 return { u"com.sun.star.sdbc.ResultSet"_ustr, u"com.sun.star.sdbcx.ResultSet"_ustr };
60 sal_Bool SAL_CALL ODbaseResultSet::supportsService( const OUString& _rServiceName )
62 return cppu::supportsService(this, _rServiceName);
65 Any SAL_CALL ODbaseResultSet::queryInterface( const Type & rType )
67 Any aRet = ODbaseResultSet_BASE::queryInterface(rType);
68 return aRet.hasValue() ? aRet : OResultSet::queryInterface(rType);
71 Sequence< Type > SAL_CALL ODbaseResultSet::getTypes( )
73 return ::comphelper::concatSequences(OResultSet::getTypes(),ODbaseResultSet_BASE::getTypes());
77 // XRowLocate
78 Any SAL_CALL ODbaseResultSet::getBookmark( )
80 ::osl::MutexGuard aGuard( m_aMutex );
81 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
82 OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row");
84 return Any((*m_aRow)[0]->getValue().getInt32());
87 sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark )
89 ::osl::MutexGuard aGuard( m_aMutex );
90 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
93 m_bRowDeleted = m_bRowInserted = m_bRowUpdated = false;
95 return m_pTable.is() && Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),true);
98 sal_Bool SAL_CALL ODbaseResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows )
100 ::osl::MutexGuard aGuard( m_aMutex );
101 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
102 if(!m_pTable.is())
103 return false;
106 Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),false);
108 return relative(rows);
112 sal_Int32 SAL_CALL ODbaseResultSet::compareBookmarks( const Any& lhs, const Any& rhs )
114 sal_Int32 nFirst(0),nSecond(0),nResult(0);
115 if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
117 ::connectivity::SharedResources aResources;
118 const OUString sMessage = aResources.getResourceString(STR_INVALID_BOOKMARK);
119 ::dbtools::throwGenericSQLException(sMessage ,*this);
120 } // if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
122 if(nFirst < nSecond)
123 nResult = CompareBookmark::LESS;
124 else if(nFirst > nSecond)
125 nResult = CompareBookmark::GREATER;
126 else
127 nResult = CompareBookmark::EQUAL;
129 return nResult;
132 sal_Bool SAL_CALL ODbaseResultSet::hasOrderedBookmarks( )
134 return true;
137 sal_Int32 SAL_CALL ODbaseResultSet::hashBookmark( const Any& bookmark )
139 ::osl::MutexGuard aGuard( m_aMutex );
140 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
143 return comphelper::getINT32(bookmark);
146 // XDeleteRows
147 Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< Any >& /*rows*/ )
149 ::osl::MutexGuard aGuard( m_aMutex );
150 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
152 ::dbtools::throwFeatureNotImplementedSQLException( u"XDeleteRows::deleteRows"_ustr, *this );
155 bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex)
157 auto pIndex = dynamic_cast<dbase::ODbaseIndex*>(_xIndex.get());
158 if(pIndex)
160 std::unique_ptr<dbase::OIndexIterator> pIter = pIndex->createIterator();
162 if (pIter)
164 sal_uInt32 nRec = pIter->First();
165 while (nRec != NODE_NOTFOUND)
167 m_pFileSet->push_back(nRec);
168 nRec = pIter->Next();
170 m_pFileSet->setFrozen();
171 return true;
174 return false;
177 ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper()
179 return *ODbaseResultSet_BASE3::getArrayHelper();
182 ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const
184 Sequence< Property > aProps;
185 describeProperties(aProps);
186 return new ::cppu::OPropertyArrayHelper(aProps);
189 void SAL_CALL ODbaseResultSet::acquire() noexcept
191 ODbaseResultSet_BASE2::acquire();
194 void SAL_CALL ODbaseResultSet::release() noexcept
196 ODbaseResultSet_BASE2::release();
199 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo( )
201 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
204 sal_Int32 ODbaseResultSet::getCurrentFilePos() const
206 return m_pTable->getFilePos();
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */