update dev300-m58
[ooovba.git] / connectivity / source / drivers / macab / MacabResultSet.cxx
blob5a5d660c605d2f6d34ec37ebc69dab6d70626f2c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MacabResultSet.cxx,v $
10 * $Revision: 1.3.56.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "MacabResultSet.hxx"
35 #include "MacabAddressBook.hxx"
36 #include "MacabRecords.hxx"
37 #include "macabutilities.hxx"
38 #include "MacabResultSetMetaData.hxx"
39 #include "MacabConnection.hxx"
40 #include "macabcondition.hxx"
41 #include "macaborder.hxx"
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
44 #include "TConnection.hxx"
45 #include <connectivity/dbexception.hxx>
46 #include "resource/sharedresources.hxx"
47 #include "resource/macab_res.hrc"
49 using namespace connectivity::macab;
50 using namespace cppu;
51 using namespace com::sun::star::uno;
52 using namespace com::sun::star::lang;
53 using namespace com::sun::star::beans;
54 using namespace com::sun::star::sdbc;
55 using namespace com::sun::star::sdbcx;
56 using namespace com::sun::star::io;
57 using namespace com::sun::star::util;
59 IMPLEMENT_SERVICE_INFO(MacabResultSet, "com.sun.star.sdbc.drivers.MacabResultSet", "com.sun.star.sdbc.ResultSet");
60 // -------------------------------------------------------------------------
61 MacabResultSet::MacabResultSet(MacabCommonStatement* pStmt)
62 : MacabResultSet_BASE(m_aMutex),
63 OPropertySetHelper(MacabResultSet_BASE::rBHelper),
64 m_xStatement(pStmt),
65 m_xMetaData(NULL),
66 m_aMacabRecords(),
67 m_nRowPos(-1),
68 m_bWasNull(sal_True)
70 m_sTableName = MacabAddressBook::getDefaultTableName();
72 // -------------------------------------------------------------------------
73 MacabResultSet::~MacabResultSet()
76 // -------------------------------------------------------------------------
77 void MacabResultSet::allMacabRecords()
79 MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
81 m_aMacabRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
83 // -------------------------------------------------------------------------
84 void MacabResultSet::someMacabRecords(const MacabCondition *pCondition)
86 MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
87 MacabRecords* allRecords;
89 allRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
91 // Bad table!! Throw exception?
92 if(allRecords == NULL)
93 return;
95 if(m_aMacabRecords != NULL && m_aMacabRecords != allRecords)
96 delete m_aMacabRecords;
98 // The copy constructor copies everything but records (including the
99 // maximum alloted size, which means that we'll never have to resize)
100 m_aMacabRecords = new MacabRecords(allRecords);
102 MacabRecords::iterator iterator;
104 for (iterator = allRecords->begin();
105 iterator != allRecords->end();
106 ++iterator)
108 if (pCondition->eval(*iterator))
109 m_aMacabRecords->insertRecord(*iterator);
112 // -------------------------------------------------------------------------
113 void MacabResultSet::sortMacabRecords(const MacabOrder *pOrder)
115 // I do this with ints rather than an iterator because the ids will
116 // be changing when we change the order and ints are easier to deal
117 // with (for me).
118 sal_Int32 i, j, size, smallest;
119 size = m_aMacabRecords->size();
121 for(i = 0; i < size; i++)
123 smallest = i;
124 for( j = i + 1; j < size; j++)
126 // if smallest > j
127 if(pOrder->compare(m_aMacabRecords->getRecord(smallest),
128 m_aMacabRecords->getRecord(j) ) > 0)
130 smallest = j;
135 if(smallest != i)
137 m_aMacabRecords->swap(i,smallest);
142 // -------------------------------------------------------------------------
143 void MacabResultSet::setTableName(::rtl::OUString _sTableName)
145 m_sTableName = _sTableName;
147 // -------------------------------------------------------------------------
148 void MacabResultSet::disposing()
150 OPropertySetHelper::disposing();
152 ::osl::MutexGuard aGuard(m_aMutex);
154 m_xStatement.clear();
155 m_xMetaData.clear();
157 // -------------------------------------------------------------------------
158 Any SAL_CALL MacabResultSet::queryInterface(const Type & rType) throw(RuntimeException)
160 Any aRet = OPropertySetHelper::queryInterface(rType);
161 if (!aRet.hasValue())
162 aRet = MacabResultSet_BASE::queryInterface(rType);
163 return aRet;
165 // -------------------------------------------------------------------------
166 void SAL_CALL MacabResultSet::acquire() throw()
168 MacabResultSet_BASE::acquire();
170 // -------------------------------------------------------------------------
171 void SAL_CALL MacabResultSet::release() throw()
173 MacabResultSet_BASE::release();
175 // -------------------------------------------------------------------------
176 Sequence< Type > SAL_CALL MacabResultSet::getTypes() throw(RuntimeException)
178 OTypeCollection aTypes(
179 ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet >*) 0),
180 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet >*) 0),
181 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet >*) 0));
183 return comphelper::concatSequences(aTypes.getTypes(), MacabResultSet_BASE::getTypes());
185 // -------------------------------------------------------------------------
186 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL MacabResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
188 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
190 // -------------------------------------------------------------------------
191 sal_Int32 SAL_CALL MacabResultSet::findColumn(const ::rtl::OUString& columnName) throw(SQLException, RuntimeException)
193 ::osl::MutexGuard aGuard( m_aMutex );
194 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
196 // find the first column with the name columnName
197 Reference< XResultSetMetaData > xMeta = getMetaData();
198 sal_Int32 nLen = xMeta->getColumnCount();
200 for (sal_Int32 i = 1; i <= nLen; ++i)
201 if (xMeta->isCaseSensitive(i) ?
202 columnName == xMeta->getColumnName(i) :
203 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
204 return i;
206 ::connectivity::SharedResources aResources;
207 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
208 STR_NO_ELEMENT_NAME,
209 "$name$", columnName
210 ) );
211 ::dbtools::throwGenericSQLException(sError , *this);
212 // Unreachable:
213 OSL_ASSERT(false);
214 return 0;
216 // -------------------------------------------------------------------------
217 ::rtl::OUString SAL_CALL MacabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
219 ::osl::MutexGuard aGuard( m_aMutex );
220 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
222 ::rtl::OUString aRet;
223 sal_Int32 nRecords = m_aMacabRecords->size();
224 m_bWasNull = true;
226 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
228 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
229 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
230 if(aField != NULL)
232 if(aField->type == kABStringProperty)
234 aRet = CFStringToOUString( (CFStringRef) aField->value);
235 m_bWasNull = false;
240 // Trigger an exception if m_bWasNull is true?
241 return aRet;
243 // -------------------------------------------------------------------------
244 sal_Bool SAL_CALL MacabResultSet::getBoolean(sal_Int32) throw(SQLException, RuntimeException)
246 ::osl::MutexGuard aGuard( m_aMutex );
247 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
249 ::dbtools::throwFunctionNotSupportedException("getBoolean", NULL);
251 return sal_False;
253 // -------------------------------------------------------------------------
254 sal_Int8 SAL_CALL MacabResultSet::getByte(sal_Int32) throw(SQLException, RuntimeException)
256 ::osl::MutexGuard aGuard( m_aMutex );
257 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
259 ::dbtools::throwFunctionNotSupportedException("getByte", NULL);
261 sal_Int8 nRet = 0;
262 return nRet;
264 // -------------------------------------------------------------------------
265 sal_Int16 SAL_CALL MacabResultSet::getShort(sal_Int32) throw(SQLException, RuntimeException)
267 ::osl::MutexGuard aGuard( m_aMutex );
268 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
270 ::dbtools::throwFunctionNotSupportedException("getShort", NULL);
272 sal_Int16 nRet = 0;
273 return nRet;
275 // -------------------------------------------------------------------------
276 sal_Int32 SAL_CALL MacabResultSet::getInt(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
278 ::osl::MutexGuard aGuard( m_aMutex );
279 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
281 sal_Int32 nRet = 0;
282 sal_Int32 nRecords = m_aMacabRecords->size();
283 m_bWasNull = true;
285 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
287 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
288 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
289 if(aField != NULL)
291 if(aField->type == kABIntegerProperty)
293 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
294 // m_bWasNull now becomes whether getting the value was successful
295 // Should we check for the wrong type here, e.g., a float or a 64 bit int?
296 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
301 // Trigger an exception if m_bWasNull is true?
302 return nRet;
304 // -------------------------------------------------------------------------
305 sal_Int64 SAL_CALL MacabResultSet::getLong(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
307 ::osl::MutexGuard aGuard( m_aMutex );
308 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
310 sal_Int64 nRet = 0;
311 sal_Int32 nRecords = m_aMacabRecords->size();
312 m_bWasNull = true;
314 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
316 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
317 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
318 if(aField != NULL)
320 if(aField->type == kABIntegerProperty)
322 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
323 // m_bWasNull now becomes whether getting the value was successful
324 // Should we check for the wrong type here, e.g., a float or a 32 bit int?
325 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
330 // Trigger an exception if m_bWasNull is true?
331 return nRet;
333 // -------------------------------------------------------------------------
334 float SAL_CALL MacabResultSet::getFloat(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
336 ::osl::MutexGuard aGuard( m_aMutex );
337 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
339 float nVal = 0;
340 sal_Int32 nRecords = m_aMacabRecords->size();
341 m_bWasNull = true;
343 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
345 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
346 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
347 if(aField != NULL)
349 if(aField->type == kABRealProperty)
351 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
352 // m_bWasNull now becomes whether getting the value was successful
353 // Should we check for the wrong type here, e.g., an int or a double?
354 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
359 // Trigger an exception if m_bWasNull is true?
360 return nVal;
362 // -------------------------------------------------------------------------
363 double SAL_CALL MacabResultSet::getDouble(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
365 ::osl::MutexGuard aGuard( m_aMutex );
366 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
368 double nVal = 0;
369 sal_Int32 nRecords = m_aMacabRecords->size();
370 m_bWasNull = true;
372 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
374 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
375 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
376 if(aField != NULL)
378 if(aField->type == kABRealProperty)
380 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
381 // m_bWasNull now becomes whether getting the value was successful
382 // Should we check for the wrong type here, e.g., an int or a float?
383 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
388 // Trigger an exception if m_bWasNull is true?
389 return nVal;
391 // -------------------------------------------------------------------------
392 Sequence< sal_Int8 > SAL_CALL MacabResultSet::getBytes(sal_Int32) throw(SQLException, RuntimeException)
394 ::osl::MutexGuard aGuard( m_aMutex );
395 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
397 ::dbtools::throwFunctionNotSupportedException("getBytes", NULL);
399 return Sequence< sal_Int8 >();
401 // -------------------------------------------------------------------------
402 Date SAL_CALL MacabResultSet::getDate(sal_Int32) throw(SQLException, RuntimeException)
404 ::osl::MutexGuard aGuard( m_aMutex );
405 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
407 ::dbtools::throwFunctionNotSupportedException("getDate", NULL);
409 Date aRet;
410 return aRet;
412 // -------------------------------------------------------------------------
413 Time SAL_CALL MacabResultSet::getTime(sal_Int32) throw(SQLException, RuntimeException)
415 ::osl::MutexGuard aGuard( m_aMutex );
416 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
418 ::dbtools::throwFunctionNotSupportedException("getTime", NULL);
420 Time nRet;
421 return nRet;
423 // -------------------------------------------------------------------------
424 DateTime SAL_CALL MacabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
426 ::osl::MutexGuard aGuard( m_aMutex );
427 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
429 DateTime nRet;
430 sal_Int32 nRecords = m_aMacabRecords->size();
431 m_bWasNull = true;
433 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
435 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
436 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
437 if(aField != NULL)
439 if(aField->type == kABDateProperty)
441 nRet = CFDateToDateTime((CFDateRef) aField->value);
442 m_bWasNull = false;
447 // Trigger an exception if m_bWasNull is true?
448 return nRet;
450 // -------------------------------------------------------------------------
451 Reference< XInputStream > SAL_CALL MacabResultSet::getBinaryStream(sal_Int32) throw(SQLException, RuntimeException)
453 ::osl::MutexGuard aGuard( m_aMutex );
454 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
456 ::dbtools::throwFunctionNotSupportedException("getBinaryStream", NULL);
458 return NULL;
460 // -------------------------------------------------------------------------
461 Reference< XInputStream > SAL_CALL MacabResultSet::getCharacterStream(sal_Int32) throw(SQLException, RuntimeException)
463 ::osl::MutexGuard aGuard( m_aMutex );
464 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
466 ::dbtools::throwFunctionNotSupportedException("getCharacterStream", NULL);
468 return NULL;
470 // -------------------------------------------------------------------------
471 Any SAL_CALL MacabResultSet::getObject(sal_Int32, const Reference< ::com::sun::star::container::XNameAccess >&) throw(SQLException, RuntimeException)
473 ::osl::MutexGuard aGuard( m_aMutex );
474 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
476 ::dbtools::throwFunctionNotSupportedException("getObject", NULL);
478 return Any();
480 // -------------------------------------------------------------------------
481 Reference< XRef > SAL_CALL MacabResultSet::getRef(sal_Int32) throw(SQLException, RuntimeException)
483 ::osl::MutexGuard aGuard( m_aMutex );
484 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
486 ::dbtools::throwFunctionNotSupportedException("getRef", NULL);
488 return NULL;
490 // -------------------------------------------------------------------------
491 Reference< XBlob > SAL_CALL MacabResultSet::getBlob(sal_Int32) throw(SQLException, RuntimeException)
493 ::osl::MutexGuard aGuard( m_aMutex );
494 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
496 ::dbtools::throwFunctionNotSupportedException("getBlob", NULL);
498 return NULL;
500 // -------------------------------------------------------------------------
501 Reference< XClob > SAL_CALL MacabResultSet::getClob(sal_Int32) throw(SQLException, RuntimeException)
503 ::osl::MutexGuard aGuard( m_aMutex );
504 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
506 ::dbtools::throwFunctionNotSupportedException("getClob", NULL);
508 return NULL;
510 // -------------------------------------------------------------------------
511 Reference< XArray > SAL_CALL MacabResultSet::getArray(sal_Int32) throw(SQLException, RuntimeException)
513 ::osl::MutexGuard aGuard( m_aMutex );
514 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
516 ::dbtools::throwFunctionNotSupportedException("getArray", NULL);
518 return NULL;
520 // -------------------------------------------------------------------------
521 Reference< XResultSetMetaData > SAL_CALL MacabResultSet::getMetaData() throw(SQLException, RuntimeException)
523 ::osl::MutexGuard aGuard( m_aMutex );
524 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
526 if (!m_xMetaData.is())
527 m_xMetaData = new MacabResultSetMetaData(m_xStatement->getOwnConnection(), m_sTableName);
529 Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
530 return xMetaData;
532 // -------------------------------------------------------------------------
533 sal_Bool SAL_CALL MacabResultSet::isBeforeFirst() throw(SQLException, RuntimeException)
535 ::osl::MutexGuard aGuard( m_aMutex );
536 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
538 if (m_nRowPos == -1)
539 return sal_True;
541 return sal_False;
543 // -------------------------------------------------------------------------
544 sal_Bool SAL_CALL MacabResultSet::isAfterLast() throw(SQLException, RuntimeException)
546 ::osl::MutexGuard aGuard( m_aMutex );
547 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
549 sal_Int32 nRecords = m_aMacabRecords->size();
550 if (m_nRowPos == nRecords)
551 return sal_True;
553 return sal_False;
555 // -------------------------------------------------------------------------
556 sal_Bool SAL_CALL MacabResultSet::isFirst() throw(SQLException, RuntimeException)
558 ::osl::MutexGuard aGuard( m_aMutex );
559 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
561 if (m_nRowPos == 0)
562 return sal_True;
564 return sal_False;
566 // -------------------------------------------------------------------------
567 sal_Bool SAL_CALL MacabResultSet::isLast() throw(SQLException, RuntimeException)
569 ::osl::MutexGuard aGuard( m_aMutex );
570 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
572 sal_Int32 nRecords = m_aMacabRecords->size();
573 if (m_nRowPos == nRecords - 1)
574 return sal_True;
576 return sal_False;
578 // -------------------------------------------------------------------------
579 void SAL_CALL MacabResultSet::beforeFirst() throw(SQLException, RuntimeException)
581 ::osl::MutexGuard aGuard( m_aMutex );
582 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
584 // move before the first row
585 m_nRowPos = -1;
587 // -------------------------------------------------------------------------
588 void SAL_CALL MacabResultSet::afterLast() throw(SQLException, RuntimeException)
590 ::osl::MutexGuard aGuard( m_aMutex );
591 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
593 // move after the last row
594 sal_Int32 nRecords = m_aMacabRecords->size();
595 m_nRowPos = nRecords;
597 // -------------------------------------------------------------------------
598 void SAL_CALL MacabResultSet::close() throw(SQLException, RuntimeException)
601 ::osl::MutexGuard aGuard( m_aMutex );
602 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
604 dispose();
606 // -------------------------------------------------------------------------
607 sal_Bool SAL_CALL MacabResultSet::first() throw(SQLException, RuntimeException)
609 ::osl::MutexGuard aGuard( m_aMutex );
610 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
612 sal_Int32 nRecords = m_aMacabRecords->size();
613 if (nRecords == 0)
614 return sal_False;
616 m_nRowPos = 0;
617 return sal_True;
619 // -------------------------------------------------------------------------
620 sal_Bool SAL_CALL MacabResultSet::last() throw(SQLException, RuntimeException)
622 ::osl::MutexGuard aGuard( m_aMutex );
623 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
625 sal_Int32 nRecords = m_aMacabRecords->size();
626 if (nRecords == 0)
627 return sal_False;
629 m_nRowPos = nRecords - 1;
630 return sal_True;
632 // -------------------------------------------------------------------------
633 sal_Int32 SAL_CALL MacabResultSet::getRow() throw(SQLException, RuntimeException)
635 ::osl::MutexGuard aGuard( m_aMutex );
636 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
638 return m_nRowPos;
640 // -------------------------------------------------------------------------
641 sal_Bool SAL_CALL MacabResultSet::absolute(sal_Int32 row) throw(SQLException, RuntimeException)
643 ::osl::MutexGuard aGuard( m_aMutex );
644 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
646 sal_Int32 nRecords = m_aMacabRecords->size();
647 if (row <= -1 ||
648 row >= nRecords)
649 return sal_False;
651 m_nRowPos = row;
652 return sal_True;
654 // -------------------------------------------------------------------------
655 sal_Bool SAL_CALL MacabResultSet::relative(sal_Int32 row) throw(SQLException, RuntimeException)
657 ::osl::MutexGuard aGuard( m_aMutex );
658 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
660 return absolute(m_nRowPos + row);
662 // -------------------------------------------------------------------------
663 sal_Bool SAL_CALL MacabResultSet::next() throw(SQLException, RuntimeException)
665 ::osl::MutexGuard aGuard( m_aMutex );
666 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
668 return absolute(m_nRowPos + 1);
670 // -------------------------------------------------------------------------
671 sal_Bool SAL_CALL MacabResultSet::previous() throw(SQLException, RuntimeException)
673 ::osl::MutexGuard aGuard( m_aMutex );
674 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
676 return absolute(m_nRowPos - 1);
678 // -------------------------------------------------------------------------
679 Reference< XInterface > SAL_CALL MacabResultSet::getStatement() throw(SQLException, RuntimeException)
681 ::osl::MutexGuard aGuard( m_aMutex );
682 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
684 Reference< XStatement > xStatement = m_xStatement.get();
685 return xStatement;
687 // -------------------------------------------------------------------------
688 sal_Bool SAL_CALL MacabResultSet::rowDeleted() throw(SQLException, RuntimeException)
690 ::osl::MutexGuard aGuard( m_aMutex );
691 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
693 return sal_False;
695 // -------------------------------------------------------------------------
696 sal_Bool SAL_CALL MacabResultSet::rowInserted() throw(SQLException, RuntimeException)
698 ::osl::MutexGuard aGuard( m_aMutex );
699 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
701 return sal_False;
703 // -------------------------------------------------------------------------
704 sal_Bool SAL_CALL MacabResultSet::rowUpdated() throw(SQLException, RuntimeException)
706 ::osl::MutexGuard aGuard( m_aMutex );
707 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
709 return sal_False;
711 // -------------------------------------------------------------------------
712 sal_Bool SAL_CALL MacabResultSet::wasNull() throw(SQLException, RuntimeException)
714 ::osl::MutexGuard aGuard( m_aMutex );
715 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
717 return m_bWasNull;
719 // -------------------------------------------------------------------------
720 void SAL_CALL MacabResultSet::cancel() throw(RuntimeException)
722 ::osl::MutexGuard aGuard( m_aMutex );
723 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
725 // -------------------------------------------------------------------------
726 void SAL_CALL MacabResultSet::clearWarnings() throw(SQLException, RuntimeException)
729 // -------------------------------------------------------------------------
730 Any SAL_CALL MacabResultSet::getWarnings() throw(SQLException, RuntimeException)
732 return Any();
734 // -------------------------------------------------------------------------
735 void SAL_CALL MacabResultSet::insertRow() throw(SQLException, RuntimeException)
737 ::osl::MutexGuard aGuard( m_aMutex );
738 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
740 // you only have to implement this if you want to insert new rows
742 // -------------------------------------------------------------------------
743 void SAL_CALL MacabResultSet::updateRow() throw(SQLException, RuntimeException)
745 ::osl::MutexGuard aGuard( m_aMutex );
746 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
748 // only when you allow updates
750 // -------------------------------------------------------------------------
751 void SAL_CALL MacabResultSet::deleteRow() throw(SQLException, RuntimeException)
753 ::osl::MutexGuard aGuard( m_aMutex );
754 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
756 // -------------------------------------------------------------------------
757 void SAL_CALL MacabResultSet::cancelRowUpdates() throw(SQLException, RuntimeException)
759 ::osl::MutexGuard aGuard( m_aMutex );
760 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
762 // -------------------------------------------------------------------------
763 void SAL_CALL MacabResultSet::moveToInsertRow() throw(SQLException, RuntimeException)
765 ::osl::MutexGuard aGuard( m_aMutex );
766 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
768 // only when you allow inserts
770 // -------------------------------------------------------------------------
771 void SAL_CALL MacabResultSet::moveToCurrentRow() throw(SQLException, RuntimeException)
773 ::osl::MutexGuard aGuard( m_aMutex );
774 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
776 // -------------------------------------------------------------------------
777 void SAL_CALL MacabResultSet::updateNull(sal_Int32) throw(SQLException, RuntimeException)
779 ::osl::MutexGuard aGuard( m_aMutex );
780 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
782 // -------------------------------------------------------------------------
783 void SAL_CALL MacabResultSet::updateBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
785 ::osl::MutexGuard aGuard( m_aMutex );
786 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
788 // -------------------------------------------------------------------------
789 void SAL_CALL MacabResultSet::updateByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
791 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
792 ::osl::MutexGuard aGuard( m_aMutex );
794 // -------------------------------------------------------------------------
795 void SAL_CALL MacabResultSet::updateShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
797 ::osl::MutexGuard aGuard( m_aMutex );
798 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
800 // -------------------------------------------------------------------------
801 void SAL_CALL MacabResultSet::updateInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
803 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
804 ::osl::MutexGuard aGuard( m_aMutex );
806 // -------------------------------------------------------------------------
807 void SAL_CALL MacabResultSet::updateLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
809 ::osl::MutexGuard aGuard( m_aMutex );
810 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
812 // -----------------------------------------------------------------------
813 void SAL_CALL MacabResultSet::updateFloat(sal_Int32, float) throw(SQLException, RuntimeException)
815 ::osl::MutexGuard aGuard( m_aMutex );
816 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
818 // -------------------------------------------------------------------------
819 void SAL_CALL MacabResultSet::updateDouble(sal_Int32, double) throw(SQLException, RuntimeException)
821 ::osl::MutexGuard aGuard( m_aMutex );
822 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
824 // -------------------------------------------------------------------------
825 void SAL_CALL MacabResultSet::updateString(sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
827 ::osl::MutexGuard aGuard( m_aMutex );
828 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
830 // -------------------------------------------------------------------------
831 void SAL_CALL MacabResultSet::updateBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
833 ::osl::MutexGuard aGuard( m_aMutex );
834 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
836 // -------------------------------------------------------------------------
837 void SAL_CALL MacabResultSet::updateDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
839 ::osl::MutexGuard aGuard( m_aMutex );
840 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
842 // -------------------------------------------------------------------------
843 void SAL_CALL MacabResultSet::updateTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
845 ::osl::MutexGuard aGuard( m_aMutex );
846 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
848 // -------------------------------------------------------------------------
849 void SAL_CALL MacabResultSet::updateTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
851 ::osl::MutexGuard aGuard( m_aMutex );
852 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
854 // -------------------------------------------------------------------------
855 void SAL_CALL MacabResultSet::updateBinaryStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
857 ::osl::MutexGuard aGuard( m_aMutex );
858 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
860 // -------------------------------------------------------------------------
861 void SAL_CALL MacabResultSet::updateCharacterStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
863 ::osl::MutexGuard aGuard( m_aMutex );
864 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
866 // -------------------------------------------------------------------------
867 void SAL_CALL MacabResultSet::refreshRow() throw(SQLException, RuntimeException)
869 ::osl::MutexGuard aGuard( m_aMutex );
870 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
872 // -------------------------------------------------------------------------
873 void SAL_CALL MacabResultSet::updateObject(sal_Int32, const Any&) throw(SQLException, RuntimeException)
875 ::osl::MutexGuard aGuard( m_aMutex );
876 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
878 // -------------------------------------------------------------------------
879 void SAL_CALL MacabResultSet::updateNumericObject(sal_Int32, const Any&, sal_Int32) throw(SQLException, RuntimeException)
881 ::osl::MutexGuard aGuard( m_aMutex );
882 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
884 // -------------------------------------------------------------------------
885 // XRowLocate
886 Any SAL_CALL MacabResultSet::getBookmark() throw( SQLException, RuntimeException)
888 ::osl::MutexGuard aGuard( m_aMutex );
889 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
891 sal_Int32 nRecords = m_aMacabRecords->size();
893 if (m_nRowPos != -1 && m_nRowPos != nRecords)
895 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
896 if(uidField != NULL)
898 if(uidField->type == kABStringProperty)
900 return makeAny(CFStringToOUString( (CFStringRef) uidField->value ));
904 return Any();
906 // -------------------------------------------------------------------------
907 sal_Bool SAL_CALL MacabResultSet::moveToBookmark(const Any& bookmark) throw( SQLException, RuntimeException)
909 ::osl::MutexGuard aGuard( m_aMutex );
910 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
912 ::rtl::OUString sBookmark = comphelper::getString(bookmark);
913 sal_Int32 nRecords = m_aMacabRecords->size();
915 for (sal_Int32 nRow = 0; nRow < nRecords; nRow++)
917 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
918 if(uidField != NULL)
920 if(uidField->type == kABStringProperty)
922 ::rtl::OUString sUniqueIdentifier = CFStringToOUString( (CFStringRef) uidField->value );
923 if (sUniqueIdentifier == sBookmark)
925 m_nRowPos = nRow;
926 return sal_True;
931 return sal_False;
933 // -------------------------------------------------------------------------
934 sal_Bool SAL_CALL MacabResultSet::moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows) throw( SQLException, RuntimeException)
936 ::osl::MutexGuard aGuard( m_aMutex );
937 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
939 sal_Int32 nRowSave = m_nRowPos;
941 if (moveToBookmark(bookmark))
943 sal_Int32 nRecords = m_aMacabRecords->size();
945 m_nRowPos += rows;
947 if (-1 < m_nRowPos && m_nRowPos < nRecords)
948 return sal_True;
951 m_nRowPos = nRowSave;
952 return sal_False;
954 // -------------------------------------------------------------------------
955 sal_Int32 SAL_CALL MacabResultSet::compareBookmarks(const Any& firstItem, const Any& secondItem) throw( SQLException, RuntimeException)
957 ::osl::MutexGuard aGuard( m_aMutex );
958 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
960 ::rtl::OUString sFirst = comphelper::getString(firstItem);
961 ::rtl::OUString sSecond = comphelper::getString(secondItem);
963 if (sFirst < sSecond)
964 return CompareBookmark::LESS;
965 if (sFirst > sSecond)
966 return CompareBookmark::GREATER;
967 return CompareBookmark::EQUAL;
969 // -------------------------------------------------------------------------
970 sal_Bool SAL_CALL MacabResultSet::hasOrderedBookmarks() throw( SQLException, RuntimeException)
972 return sal_False;
974 // -------------------------------------------------------------------------
975 sal_Int32 SAL_CALL MacabResultSet::hashBookmark(const Any& bookmark) throw( SQLException, RuntimeException)
977 ::osl::MutexGuard aGuard( m_aMutex );
978 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
980 ::rtl::OUString sBookmark = comphelper::getString(bookmark);
982 return sBookmark.hashCode();
984 // -------------------------------------------------------------------------
985 // XDeleteRows
986 Sequence< sal_Int32 > SAL_CALL MacabResultSet::deleteRows(const Sequence< Any >&) throw( SQLException, RuntimeException)
988 ::osl::MutexGuard aGuard( m_aMutex );
989 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
991 return Sequence< sal_Int32 >();
993 // -------------------------------------------------------------------------
994 IPropertyArrayHelper* MacabResultSet::createArrayHelper() const
996 Sequence< Property > aProps(6);
997 Property* pProperties = aProps.getArray();
998 sal_Int32 nPos = 0;
999 DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY);
1000 DECL_PROP0(FETCHDIRECTION, sal_Int32);
1001 DECL_PROP0(FETCHSIZE, sal_Int32);
1002 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
1003 DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
1004 DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
1006 return new OPropertyArrayHelper(aProps);
1008 // -------------------------------------------------------------------------
1009 IPropertyArrayHelper & MacabResultSet::getInfoHelper()
1011 return *static_cast<MacabResultSet*>(this)->getArrayHelper();
1013 // -------------------------------------------------------------------------
1014 sal_Bool MacabResultSet::convertFastPropertyValue(
1015 Any &,
1016 Any &,
1017 sal_Int32 nHandle,
1018 const Any& )
1019 throw (::com::sun::star::lang::IllegalArgumentException)
1021 switch (nHandle)
1023 case PROPERTY_ID_ISBOOKMARKABLE:
1024 case PROPERTY_ID_CURSORNAME:
1025 case PROPERTY_ID_RESULTSETCONCURRENCY:
1026 case PROPERTY_ID_RESULTSETTYPE:
1027 throw ::com::sun::star::lang::IllegalArgumentException();
1028 break;
1029 case PROPERTY_ID_FETCHDIRECTION:
1030 case PROPERTY_ID_FETCHSIZE:
1031 default:
1034 return sal_False;
1036 // -------------------------------------------------------------------------
1037 void MacabResultSet::setFastPropertyValue_NoBroadcast(
1038 sal_Int32 nHandle,
1039 const Any& )
1040 throw (Exception)
1042 switch (nHandle)
1044 case PROPERTY_ID_ISBOOKMARKABLE:
1045 case PROPERTY_ID_CURSORNAME:
1046 case PROPERTY_ID_RESULTSETCONCURRENCY:
1047 case PROPERTY_ID_RESULTSETTYPE:
1048 throw Exception();
1049 break;
1050 case PROPERTY_ID_FETCHDIRECTION:
1051 break;
1052 case PROPERTY_ID_FETCHSIZE:
1053 break;
1054 default:
1058 // -------------------------------------------------------------------------
1059 void MacabResultSet::getFastPropertyValue(
1060 Any& _rValue,
1061 sal_Int32 nHandle) const
1063 switch (nHandle)
1065 case PROPERTY_ID_ISBOOKMARKABLE:
1066 _rValue <<= (sal_Bool)sal_False;
1067 break;
1068 case PROPERTY_ID_CURSORNAME:
1069 case PROPERTY_ID_RESULTSETCONCURRENCY:
1070 case PROPERTY_ID_RESULTSETTYPE:
1071 case PROPERTY_ID_FETCHDIRECTION:
1072 case PROPERTY_ID_FETCHSIZE:
1076 // -----------------------------------------------------------------------------