bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / dbase / DResultSet.cxx
blob17cbac2e41aba009d5f362001a50ce7a33d61a7a
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 "com.sun.star.sdbcx.dbase.ResultSet";
55 Sequence< OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( )
57 return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
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 makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue()));
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( "XDeleteRows::deleteRows", *this );
153 return Sequence< sal_Int32 >();
156 bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex)
158 auto pIndex = comphelper::getUnoTunnelImplementation<dbase::ODbaseIndex>(_xIndex);
159 if(pIndex)
161 std::unique_ptr<dbase::OIndexIterator> pIter = pIndex->createIterator();
163 if (pIter)
165 sal_uInt32 nRec = pIter->First();
166 while (nRec != NODE_NOTFOUND)
168 m_pFileSet->push_back(nRec);
169 nRec = pIter->Next();
171 m_pFileSet->setFrozen();
172 return true;
175 return false;
178 ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper()
180 return *ODbaseResultSet_BASE3::getArrayHelper();
183 ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const
185 Sequence< Property > aProps;
186 describeProperties(aProps);
187 return new ::cppu::OPropertyArrayHelper(aProps);
190 void SAL_CALL ODbaseResultSet::acquire() noexcept
192 ODbaseResultSet_BASE2::acquire();
195 void SAL_CALL ODbaseResultSet::release() noexcept
197 ODbaseResultSet_BASE2::release();
200 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo( )
202 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
205 sal_Int32 ODbaseResultSet::getCurrentFilePos() const
207 return m_pTable->getFilePos();
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */