Use correct object
[LibreOffice.git] / connectivity / source / drivers / macab / MacabResultSet.cxx
blobe8784ba3a8a8c282e211b2ea264dc2fed670bcf1
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 .
21 #include "MacabResultSet.hxx"
22 #include "MacabAddressBook.hxx"
23 #include "MacabRecords.hxx"
24 #include "macabutilities.hxx"
25 #include "MacabResultSetMetaData.hxx"
26 #include "MacabConnection.hxx"
27 #include "macabcondition.hxx"
28 #include "macaborder.hxx"
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
31 #include <TConnection.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <comphelper/types.hxx>
34 #include <connectivity/dbexception.hxx>
35 #include <resource/sharedresources.hxx>
36 #include <rtl/ref.hxx>
37 #include <strings.hrc>
39 using namespace connectivity::macab;
40 using namespace cppu;
41 using namespace css::uno;
42 using namespace css::lang;
43 using namespace css::beans;
44 using namespace css::sdbc;
45 using namespace css::sdbcx;
46 using namespace css::io;
47 using namespace css::util;
49 IMPLEMENT_SERVICE_INFO(MacabResultSet, "com.sun.star.sdbc.drivers.MacabResultSet", "com.sun.star.sdbc.ResultSet");
51 MacabResultSet::MacabResultSet(MacabCommonStatement* pStmt)
52 : MacabResultSet_BASE(m_aMutex),
53 OPropertySetHelper(MacabResultSet_BASE::rBHelper),
54 m_xStatement(pStmt),
55 m_aMacabRecords(),
56 m_nRowPos(-1),
57 m_bWasNull(true),
58 m_sTableName(MacabAddressBook::getDefaultTableName())
62 MacabResultSet::~MacabResultSet()
66 void MacabResultSet::allMacabRecords()
68 rtl::Reference<MacabConnection> pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
70 m_aMacabRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
73 void MacabResultSet::someMacabRecords(const MacabCondition *pCondition)
75 rtl::Reference<MacabConnection> pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
76 MacabRecords* allRecords;
78 allRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
80 // Bad table!! Throw exception?
81 if(allRecords == nullptr)
82 return;
84 if(m_aMacabRecords != nullptr && m_aMacabRecords != allRecords)
85 delete m_aMacabRecords;
87 // The copy constructor copies everything but records (including the
88 // maximum allocated size, which means that we'll never have to resize)
89 m_aMacabRecords = new MacabRecords(allRecords);
91 if(pCondition->isAlwaysFalse())
93 return;
96 MacabRecords::iterator iterator;
98 for (iterator = allRecords->begin();
99 iterator != allRecords->end();
100 ++iterator)
102 if (pCondition->eval(*iterator))
103 m_aMacabRecords->insertRecord(*iterator);
107 void MacabResultSet::sortMacabRecords(const MacabOrder *pOrder)
109 // I do this with ints rather than an iterator because the ids will
110 // be changing when we change the order and ints are easier to deal
111 // with (for me).
112 sal_Int32 i, j, size, smallest;
113 size = m_aMacabRecords->size();
115 for(i = 0; i < size; i++)
117 smallest = i;
118 for( j = i + 1; j < size; j++)
120 // if smallest > j
121 if(pOrder->compare(m_aMacabRecords->getRecord(smallest),
122 m_aMacabRecords->getRecord(j) ) > 0)
124 smallest = j;
129 if(smallest != i)
131 m_aMacabRecords->swap(i,smallest);
137 void MacabResultSet::setTableName(OUString const & _sTableName)
139 m_sTableName = _sTableName;
142 void MacabResultSet::disposing()
144 OPropertySetHelper::disposing();
146 ::osl::MutexGuard aGuard(m_aMutex);
148 m_xStatement.clear();
149 m_xMetaData.clear();
152 Any SAL_CALL MacabResultSet::queryInterface(const Type & rType)
154 Any aRet = OPropertySetHelper::queryInterface(rType);
155 if (!aRet.hasValue())
156 aRet = MacabResultSet_BASE::queryInterface(rType);
157 return aRet;
160 void SAL_CALL MacabResultSet::acquire() noexcept
162 MacabResultSet_BASE::acquire();
165 void SAL_CALL MacabResultSet::release() noexcept
167 MacabResultSet_BASE::release();
170 Sequence< Type > SAL_CALL MacabResultSet::getTypes()
172 OTypeCollection aTypes(
173 cppu::UnoType<css::beans::XMultiPropertySet>::get(),
174 cppu::UnoType<css::beans::XFastPropertySet>::get(),
175 cppu::UnoType<css::beans::XPropertySet>::get());
177 return comphelper::concatSequences(aTypes.getTypes(), MacabResultSet_BASE::getTypes());
180 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL MacabResultSet::getPropertySetInfo( )
182 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
185 sal_Int32 SAL_CALL MacabResultSet::findColumn(const OUString& columnName)
187 ::osl::MutexGuard aGuard( m_aMutex );
188 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
190 // find the first column with the name columnName
191 Reference< XResultSetMetaData > xMeta = getMetaData();
192 sal_Int32 nLen = xMeta->getColumnCount();
194 for (sal_Int32 i = 1; i <= nLen; ++i)
196 if (xMeta->isCaseSensitive(i) ?
197 columnName == xMeta->getColumnName(i) :
198 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
199 return i;
202 ::dbtools::throwInvalidColumnException( columnName, *this );
203 assert(false);
204 return 0; // Never reached
207 OUString SAL_CALL MacabResultSet::getString(sal_Int32 columnIndex)
209 ::osl::MutexGuard aGuard( m_aMutex );
210 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
212 OUString aRet;
213 sal_Int32 nRecords = m_aMacabRecords->size();
214 m_bWasNull = true;
216 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
218 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
219 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
220 if(aField != nullptr)
222 if(aField->type == kABStringProperty)
224 aRet = CFStringToOUString(static_cast<CFStringRef>(aField->value));
225 m_bWasNull = false;
230 // Trigger an exception if m_bWasNull is true?
231 return aRet;
234 sal_Bool SAL_CALL MacabResultSet::getBoolean(sal_Int32)
236 ::osl::MutexGuard aGuard( m_aMutex );
237 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
239 ::dbtools::throwFunctionNotSupportedSQLException("getBoolean", nullptr);
241 return false;
244 sal_Int8 SAL_CALL MacabResultSet::getByte(sal_Int32)
246 ::osl::MutexGuard aGuard( m_aMutex );
247 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
249 ::dbtools::throwFunctionNotSupportedSQLException("getByte", nullptr);
251 return 0;
254 sal_Int16 SAL_CALL MacabResultSet::getShort(sal_Int32)
256 ::osl::MutexGuard aGuard( m_aMutex );
257 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
259 ::dbtools::throwFunctionNotSupportedSQLException("getShort", nullptr);
261 return 0;
264 sal_Int32 SAL_CALL MacabResultSet::getInt(sal_Int32 columnIndex)
266 ::osl::MutexGuard aGuard( m_aMutex );
267 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
269 sal_Int32 nRet = 0;
270 sal_Int32 nRecords = m_aMacabRecords->size();
271 m_bWasNull = true;
273 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
275 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
276 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
277 if(aField != nullptr)
279 if(aField->type == kABIntegerProperty)
281 CFNumberType numberType = CFNumberGetType( static_cast<CFNumberRef>(aField->value) );
282 // m_bWasNull now becomes whether getting the value was successful
283 // Should we check for the wrong type here, e.g., a float or a 64 bit int?
284 m_bWasNull = !CFNumberGetValue(static_cast<CFNumberRef>(aField->value), numberType, &nRet);
289 // Trigger an exception if m_bWasNull is true?
290 return nRet;
293 sal_Int64 SAL_CALL MacabResultSet::getLong(sal_Int32 columnIndex)
295 ::osl::MutexGuard aGuard( m_aMutex );
296 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
298 sal_Int64 nRet = 0;
299 sal_Int32 nRecords = m_aMacabRecords->size();
300 m_bWasNull = true;
302 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
304 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
305 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
306 if(aField != nullptr)
308 if(aField->type == kABIntegerProperty)
310 CFNumberType numberType = CFNumberGetType( static_cast<CFNumberRef>(aField->value) );
311 // m_bWasNull now becomes whether getting the value was successful
312 // Should we check for the wrong type here, e.g., a float or a 32 bit int?
313 m_bWasNull = !CFNumberGetValue(static_cast<CFNumberRef>(aField->value), numberType, &nRet);
318 // Trigger an exception if m_bWasNull is true?
319 return nRet;
322 float SAL_CALL MacabResultSet::getFloat(sal_Int32 columnIndex)
324 ::osl::MutexGuard aGuard( m_aMutex );
325 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
327 float nVal = 0;
328 sal_Int32 nRecords = m_aMacabRecords->size();
329 m_bWasNull = true;
331 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
333 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
334 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
335 if(aField != nullptr)
337 if(aField->type == kABRealProperty)
339 CFNumberType numberType = CFNumberGetType( static_cast<CFNumberRef>(aField->value) );
340 // m_bWasNull now becomes whether getting the value was successful
341 // Should we check for the wrong type here, e.g., an int or a double?
342 m_bWasNull = !CFNumberGetValue(static_cast<CFNumberRef>(aField->value), numberType, &nVal);
347 // Trigger an exception if m_bWasNull is true?
348 return nVal;
351 double SAL_CALL MacabResultSet::getDouble(sal_Int32 columnIndex)
353 ::osl::MutexGuard aGuard( m_aMutex );
354 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
356 double nVal = 0;
357 sal_Int32 nRecords = m_aMacabRecords->size();
358 m_bWasNull = true;
360 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
362 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
363 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
364 if(aField != nullptr)
366 if(aField->type == kABRealProperty)
368 CFNumberType numberType = CFNumberGetType( static_cast<CFNumberRef>(aField->value) );
369 // m_bWasNull now becomes whether getting the value was successful
370 // Should we check for the wrong type here, e.g., an int or a float?
371 m_bWasNull = !CFNumberGetValue(static_cast<CFNumberRef>(aField->value), numberType, &nVal);
376 // Trigger an exception if m_bWasNull is true?
377 return nVal;
380 Sequence< sal_Int8 > SAL_CALL MacabResultSet::getBytes(sal_Int32)
382 ::osl::MutexGuard aGuard( m_aMutex );
383 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
385 ::dbtools::throwFunctionNotSupportedSQLException("getBytes", nullptr);
387 return Sequence< sal_Int8 >();
390 Date SAL_CALL MacabResultSet::getDate(sal_Int32)
392 ::osl::MutexGuard aGuard( m_aMutex );
393 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
395 ::dbtools::throwFunctionNotSupportedSQLException("getDate", nullptr);
397 return Date();
400 Time SAL_CALL MacabResultSet::getTime(sal_Int32)
402 ::osl::MutexGuard aGuard( m_aMutex );
403 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
405 ::dbtools::throwFunctionNotSupportedSQLException("getTime", nullptr);
407 return css::util::Time();
410 DateTime SAL_CALL MacabResultSet::getTimestamp(sal_Int32 columnIndex)
412 ::osl::MutexGuard aGuard( m_aMutex );
413 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
415 DateTime nRet;
416 sal_Int32 nRecords = m_aMacabRecords->size();
417 m_bWasNull = true;
419 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
421 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
422 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
423 if(aField != nullptr)
425 if(aField->type == kABDateProperty)
427 nRet = CFDateToDateTime(static_cast<CFDateRef>(aField->value));
428 m_bWasNull = false;
433 // Trigger an exception if m_bWasNull is true?
434 return nRet;
437 Reference< XInputStream > SAL_CALL MacabResultSet::getBinaryStream(sal_Int32)
439 ::osl::MutexGuard aGuard( m_aMutex );
440 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
442 ::dbtools::throwFunctionNotSupportedSQLException("getBinaryStream", nullptr);
444 return nullptr;
447 Reference< XInputStream > SAL_CALL MacabResultSet::getCharacterStream(sal_Int32)
449 ::osl::MutexGuard aGuard( m_aMutex );
450 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
452 ::dbtools::throwFunctionNotSupportedSQLException("getCharacterStream", nullptr);
454 return nullptr;
457 Any SAL_CALL MacabResultSet::getObject(sal_Int32, const Reference< css::container::XNameAccess >&)
459 ::osl::MutexGuard aGuard( m_aMutex );
460 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
462 ::dbtools::throwFunctionNotSupportedSQLException("getObject", nullptr);
464 return Any();
467 Reference< XRef > SAL_CALL MacabResultSet::getRef(sal_Int32)
469 ::osl::MutexGuard aGuard( m_aMutex );
470 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
472 ::dbtools::throwFunctionNotSupportedSQLException("getRef", nullptr);
474 return nullptr;
477 Reference< XBlob > SAL_CALL MacabResultSet::getBlob(sal_Int32)
479 ::osl::MutexGuard aGuard( m_aMutex );
480 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
482 ::dbtools::throwFunctionNotSupportedSQLException("getBlob", nullptr);
484 return nullptr;
487 Reference< XClob > SAL_CALL MacabResultSet::getClob(sal_Int32)
489 ::osl::MutexGuard aGuard( m_aMutex );
490 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
492 ::dbtools::throwFunctionNotSupportedSQLException("getClob", nullptr);
494 return nullptr;
497 Reference< XArray > SAL_CALL MacabResultSet::getArray(sal_Int32)
499 ::osl::MutexGuard aGuard( m_aMutex );
500 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
502 ::dbtools::throwFunctionNotSupportedSQLException("getArray", nullptr);
504 return nullptr;
507 Reference< XResultSetMetaData > SAL_CALL MacabResultSet::getMetaData()
509 ::osl::MutexGuard aGuard( m_aMutex );
510 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
512 if (!m_xMetaData.is())
513 m_xMetaData = new MacabResultSetMetaData(m_xStatement->getOwnConnection(), m_sTableName);
515 Reference< XResultSetMetaData > xMetaData = m_xMetaData;
516 return xMetaData;
519 sal_Bool SAL_CALL MacabResultSet::isBeforeFirst()
521 ::osl::MutexGuard aGuard( m_aMutex );
522 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
524 if (m_nRowPos == -1)
525 return true;
527 return false;
530 sal_Bool SAL_CALL MacabResultSet::isAfterLast()
532 ::osl::MutexGuard aGuard( m_aMutex );
533 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
535 sal_Int32 nRecords = m_aMacabRecords->size();
536 if (m_nRowPos == nRecords)
537 return true;
539 return false;
542 sal_Bool SAL_CALL MacabResultSet::isFirst()
544 ::osl::MutexGuard aGuard( m_aMutex );
545 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
547 if (m_nRowPos == 0)
548 return true;
550 return false;
553 sal_Bool SAL_CALL MacabResultSet::isLast()
555 ::osl::MutexGuard aGuard( m_aMutex );
556 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
558 sal_Int32 nRecords = m_aMacabRecords->size();
559 if (m_nRowPos == nRecords - 1)
560 return true;
562 return false;
565 void SAL_CALL MacabResultSet::beforeFirst()
567 ::osl::MutexGuard aGuard( m_aMutex );
568 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
570 // move before the first row
571 m_nRowPos = -1;
574 void SAL_CALL MacabResultSet::afterLast()
576 ::osl::MutexGuard aGuard( m_aMutex );
577 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
579 // move after the last row
580 sal_Int32 nRecords = m_aMacabRecords->size();
581 m_nRowPos = nRecords;
584 void SAL_CALL MacabResultSet::close()
587 ::osl::MutexGuard aGuard( m_aMutex );
588 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
590 dispose();
593 sal_Bool SAL_CALL MacabResultSet::first()
595 ::osl::MutexGuard aGuard( m_aMutex );
596 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
598 sal_Int32 nRecords = m_aMacabRecords->size();
599 if (nRecords == 0)
600 return false;
602 m_nRowPos = 0;
603 return true;
606 sal_Bool SAL_CALL MacabResultSet::last()
608 ::osl::MutexGuard aGuard( m_aMutex );
609 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
611 sal_Int32 nRecords = m_aMacabRecords->size();
612 if (nRecords == 0)
613 return false;
615 m_nRowPos = nRecords - 1;
616 return true;
619 sal_Int32 SAL_CALL MacabResultSet::getRow()
621 ::osl::MutexGuard aGuard( m_aMutex );
622 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
624 return m_nRowPos;
627 sal_Bool SAL_CALL MacabResultSet::absolute(sal_Int32 row)
629 ::osl::MutexGuard aGuard( m_aMutex );
630 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
632 sal_Int32 nRecords = m_aMacabRecords->size();
633 if (row <= -1 ||
634 row >= nRecords)
635 return false;
637 m_nRowPos = row;
638 return true;
641 sal_Bool SAL_CALL MacabResultSet::relative(sal_Int32 row)
643 ::osl::MutexGuard aGuard( m_aMutex );
644 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
646 return absolute(m_nRowPos + row);
649 sal_Bool SAL_CALL MacabResultSet::next()
651 ::osl::MutexGuard aGuard( m_aMutex );
652 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
654 return absolute(m_nRowPos + 1);
657 sal_Bool SAL_CALL MacabResultSet::previous()
659 ::osl::MutexGuard aGuard( m_aMutex );
660 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
662 return absolute(m_nRowPos - 1);
665 Reference< XInterface > SAL_CALL MacabResultSet::getStatement()
667 ::osl::MutexGuard aGuard( m_aMutex );
668 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
670 Reference< XStatement > xStatement = m_xStatement;
671 return xStatement;
674 sal_Bool SAL_CALL MacabResultSet::rowDeleted()
676 ::osl::MutexGuard aGuard( m_aMutex );
677 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
679 return false;
682 sal_Bool SAL_CALL MacabResultSet::rowInserted()
684 ::osl::MutexGuard aGuard( m_aMutex );
685 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
687 return false;
690 sal_Bool SAL_CALL MacabResultSet::rowUpdated()
692 ::osl::MutexGuard aGuard( m_aMutex );
693 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
695 return false;
698 sal_Bool SAL_CALL MacabResultSet::wasNull()
700 ::osl::MutexGuard aGuard( m_aMutex );
701 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
703 return m_bWasNull;
706 void SAL_CALL MacabResultSet::cancel()
708 ::osl::MutexGuard aGuard( m_aMutex );
709 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
712 void SAL_CALL MacabResultSet::clearWarnings()
716 Any SAL_CALL MacabResultSet::getWarnings()
718 return Any();
721 void SAL_CALL MacabResultSet::insertRow()
723 ::osl::MutexGuard aGuard( m_aMutex );
724 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
726 // you only have to implement this if you want to insert new rows
729 void SAL_CALL MacabResultSet::updateRow()
731 ::osl::MutexGuard aGuard( m_aMutex );
732 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
734 // only when you allow updates
737 void SAL_CALL MacabResultSet::deleteRow()
739 ::osl::MutexGuard aGuard( m_aMutex );
740 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
743 void SAL_CALL MacabResultSet::cancelRowUpdates()
745 ::osl::MutexGuard aGuard( m_aMutex );
746 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
749 void SAL_CALL MacabResultSet::moveToInsertRow()
751 ::osl::MutexGuard aGuard( m_aMutex );
752 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
754 // only when you allow inserts
757 void SAL_CALL MacabResultSet::moveToCurrentRow()
759 ::osl::MutexGuard aGuard( m_aMutex );
760 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
763 void SAL_CALL MacabResultSet::updateNull(sal_Int32)
765 ::osl::MutexGuard aGuard( m_aMutex );
766 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
769 void SAL_CALL MacabResultSet::updateBoolean(sal_Int32, sal_Bool)
771 ::osl::MutexGuard aGuard( m_aMutex );
772 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
775 void SAL_CALL MacabResultSet::updateByte(sal_Int32, sal_Int8)
777 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
778 ::osl::MutexGuard aGuard( m_aMutex );
781 void SAL_CALL MacabResultSet::updateShort(sal_Int32, sal_Int16)
783 ::osl::MutexGuard aGuard( m_aMutex );
784 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
787 void SAL_CALL MacabResultSet::updateInt(sal_Int32, sal_Int32)
789 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
790 ::osl::MutexGuard aGuard( m_aMutex );
793 void SAL_CALL MacabResultSet::updateLong(sal_Int32, sal_Int64)
795 ::osl::MutexGuard aGuard( m_aMutex );
796 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
799 void SAL_CALL MacabResultSet::updateFloat(sal_Int32, float)
801 ::osl::MutexGuard aGuard( m_aMutex );
802 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
805 void SAL_CALL MacabResultSet::updateDouble(sal_Int32, double)
807 ::osl::MutexGuard aGuard( m_aMutex );
808 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
811 void SAL_CALL MacabResultSet::updateString(sal_Int32, const OUString&)
813 ::osl::MutexGuard aGuard( m_aMutex );
814 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
817 void SAL_CALL MacabResultSet::updateBytes(sal_Int32, const Sequence< sal_Int8 >&)
819 ::osl::MutexGuard aGuard( m_aMutex );
820 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
823 void SAL_CALL MacabResultSet::updateDate(sal_Int32, const Date&)
825 ::osl::MutexGuard aGuard( m_aMutex );
826 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
829 void SAL_CALL MacabResultSet::updateTime(sal_Int32, const css::util::Time&)
831 ::osl::MutexGuard aGuard( m_aMutex );
832 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
835 void SAL_CALL MacabResultSet::updateTimestamp(sal_Int32, const DateTime&)
837 ::osl::MutexGuard aGuard( m_aMutex );
838 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
841 void SAL_CALL MacabResultSet::updateBinaryStream(sal_Int32, const Reference< XInputStream >&, sal_Int32)
843 ::osl::MutexGuard aGuard( m_aMutex );
844 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
847 void SAL_CALL MacabResultSet::updateCharacterStream(sal_Int32, const Reference< XInputStream >&, sal_Int32)
849 ::osl::MutexGuard aGuard( m_aMutex );
850 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
853 void SAL_CALL MacabResultSet::refreshRow()
855 ::osl::MutexGuard aGuard( m_aMutex );
856 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
859 void SAL_CALL MacabResultSet::updateObject(sal_Int32, const Any&)
861 ::osl::MutexGuard aGuard( m_aMutex );
862 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
865 void SAL_CALL MacabResultSet::updateNumericObject(sal_Int32, const Any&, sal_Int32)
867 ::osl::MutexGuard aGuard( m_aMutex );
868 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
871 // XRowLocate
872 Any SAL_CALL MacabResultSet::getBookmark()
874 ::osl::MutexGuard aGuard( m_aMutex );
875 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
877 sal_Int32 nRecords = m_aMacabRecords->size();
879 if (m_nRowPos != -1 && m_nRowPos != nRecords)
881 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,u"UID");
882 if(uidField != nullptr)
884 if(uidField->type == kABStringProperty)
886 return Any(CFStringToOUString( static_cast<CFStringRef>(uidField->value) ));
890 return Any();
893 sal_Bool SAL_CALL MacabResultSet::moveToBookmark(const Any& bookmark)
895 ::osl::MutexGuard aGuard( m_aMutex );
896 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
898 OUString sBookmark = comphelper::getString(bookmark);
899 sal_Int32 nRecords = m_aMacabRecords->size();
901 for (sal_Int32 nRow = 0; nRow < nRecords; nRow++)
903 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,u"UID");
904 if(uidField != nullptr)
906 if(uidField->type == kABStringProperty)
908 OUString sUniqueIdentifier = CFStringToOUString( static_cast<CFStringRef>(uidField->value) );
909 if (sUniqueIdentifier == sBookmark)
911 m_nRowPos = nRow;
912 return true;
917 return false;
920 sal_Bool SAL_CALL MacabResultSet::moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows)
922 ::osl::MutexGuard aGuard( m_aMutex );
923 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
925 sal_Int32 nRowSave = m_nRowPos;
927 if (moveToBookmark(bookmark))
929 sal_Int32 nRecords = m_aMacabRecords->size();
931 m_nRowPos += rows;
933 if (-1 < m_nRowPos && m_nRowPos < nRecords)
934 return true;
937 m_nRowPos = nRowSave;
938 return false;
941 sal_Int32 SAL_CALL MacabResultSet::compareBookmarks(const Any& firstItem, const Any& secondItem)
943 ::osl::MutexGuard aGuard( m_aMutex );
944 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
946 OUString sFirst = comphelper::getString(firstItem);
947 OUString sSecond = comphelper::getString(secondItem);
949 if (sFirst < sSecond)
950 return CompareBookmark::LESS;
951 if (sFirst > sSecond)
952 return CompareBookmark::GREATER;
953 return CompareBookmark::EQUAL;
956 sal_Bool SAL_CALL MacabResultSet::hasOrderedBookmarks()
958 return false;
961 sal_Int32 SAL_CALL MacabResultSet::hashBookmark(const Any& bookmark)
963 ::osl::MutexGuard aGuard( m_aMutex );
964 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
966 OUString sBookmark = comphelper::getString(bookmark);
968 return sBookmark.hashCode();
971 // XDeleteRows
972 Sequence< sal_Int32 > SAL_CALL MacabResultSet::deleteRows(const Sequence< Any >&)
974 ::osl::MutexGuard aGuard( m_aMutex );
975 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
977 return Sequence< sal_Int32 >();
980 IPropertyArrayHelper* MacabResultSet::createArrayHelper() const
982 return new OPropertyArrayHelper
986 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME),
987 PROPERTY_ID_CURSORNAME,
988 cppu::UnoType<OUString>::get(),
989 PropertyAttribute::READONLY
992 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),
993 PROPERTY_ID_FETCHDIRECTION,
994 cppu::UnoType<sal_Int32>::get(),
998 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
999 PROPERTY_ID_FETCHSIZE,
1000 cppu::UnoType<sal_Int32>::get(),
1004 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE),
1005 PROPERTY_ID_ISBOOKMARKABLE,
1006 cppu::UnoType<bool>::get(),
1007 PropertyAttribute::READONLY
1010 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY),
1011 PROPERTY_ID_RESULTSETCONCURRENCY,
1012 cppu::UnoType<sal_Int32>::get(),
1013 PropertyAttribute::READONLY
1016 ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),
1017 PROPERTY_ID_RESULTSETTYPE,
1018 cppu::UnoType<sal_Int32>::get(),
1019 PropertyAttribute::READONLY
1025 IPropertyArrayHelper & MacabResultSet::getInfoHelper()
1027 return *getArrayHelper();
1030 sal_Bool MacabResultSet::convertFastPropertyValue(
1031 Any &,
1032 Any &,
1033 sal_Int32 nHandle,
1034 const Any& )
1036 switch (nHandle)
1038 case PROPERTY_ID_ISBOOKMARKABLE:
1039 case PROPERTY_ID_CURSORNAME:
1040 case PROPERTY_ID_RESULTSETCONCURRENCY:
1041 case PROPERTY_ID_RESULTSETTYPE:
1042 throw css::lang::IllegalArgumentException();
1043 break;
1044 case PROPERTY_ID_FETCHDIRECTION:
1045 case PROPERTY_ID_FETCHSIZE:
1046 default:
1049 return false;
1052 void MacabResultSet::setFastPropertyValue_NoBroadcast(
1053 sal_Int32 nHandle,
1054 const Any& )
1056 switch (nHandle)
1058 case PROPERTY_ID_ISBOOKMARKABLE:
1059 case PROPERTY_ID_CURSORNAME:
1060 case PROPERTY_ID_RESULTSETCONCURRENCY:
1061 case PROPERTY_ID_RESULTSETTYPE:
1062 throw Exception("cannot set prop " + OUString::number(nHandle), nullptr);
1063 break;
1064 case PROPERTY_ID_FETCHDIRECTION:
1065 break;
1066 case PROPERTY_ID_FETCHSIZE:
1067 break;
1068 default:
1073 void MacabResultSet::getFastPropertyValue(
1074 Any& _rValue,
1075 sal_Int32 nHandle) const
1077 switch (nHandle)
1079 case PROPERTY_ID_ISBOOKMARKABLE:
1080 _rValue <<= false;
1081 break;
1082 case PROPERTY_ID_CURSORNAME:
1083 case PROPERTY_ID_RESULTSETCONCURRENCY:
1084 case PROPERTY_ID_RESULTSETTYPE:
1085 case PROPERTY_ID_FETCHDIRECTION:
1086 case PROPERTY_ID_FETCHSIZE:
1092 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */