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