1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include "MacabResultSet.hxx"
32 #include "MacabAddressBook.hxx"
33 #include "MacabRecords.hxx"
34 #include "macabutilities.hxx"
35 #include "MacabResultSetMetaData.hxx"
36 #include "MacabConnection.hxx"
37 #include "macabcondition.hxx"
38 #include "macaborder.hxx"
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
41 #include "TConnection.hxx"
42 #include <connectivity/dbexception.hxx>
43 #include "resource/sharedresources.hxx"
44 #include "resource/macab_res.hrc"
45 
46 using namespace connectivity::macab;
47 using namespace cppu;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::beans;
51 using namespace com::sun::star::sdbc;
52 using namespace com::sun::star::sdbcx;
53 using namespace com::sun::star::io;
54 using namespace com::sun::star::util;
55 
56 IMPLEMENT_SERVICE_INFO(MacabResultSet, "com.sun.star.sdbc.drivers.MacabResultSet", "com.sun.star.sdbc.ResultSet");
57 // -------------------------------------------------------------------------
58 MacabResultSet::MacabResultSet(MacabCommonStatement* pStmt)
59 	: MacabResultSet_BASE(m_aMutex),
60 	  OPropertySetHelper(MacabResultSet_BASE::rBHelper),
61 	  m_xStatement(pStmt),
62 	  m_xMetaData(NULL),
63 	  m_aMacabRecords(),
64 	  m_nRowPos(-1),
65 	  m_bWasNull(sal_True)
66 {
67 	m_sTableName = MacabAddressBook::getDefaultTableName();
68 }
69 // -------------------------------------------------------------------------
70 MacabResultSet::~MacabResultSet()
71 {
72 }
73 // -------------------------------------------------------------------------
74 void MacabResultSet::allMacabRecords()
75 {
76 	MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
77 
78 	m_aMacabRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
79 }
80 // -------------------------------------------------------------------------
81 void MacabResultSet::someMacabRecords(const MacabCondition *pCondition)
82 {
83 	MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
84 	MacabRecords* allRecords;
85 
86 	allRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
87 
88 	// Bad table!! Throw exception?
89 	if(allRecords == NULL)
90 		return;
91 
92 	if(m_aMacabRecords != NULL && m_aMacabRecords != allRecords)
93 		delete m_aMacabRecords;
94 
95 	// The copy constructor copies everything but records (including the
96 	// maximum alloted size, which means that we'll never have to resize)
97 	m_aMacabRecords = new MacabRecords(allRecords);
98 
99 	MacabRecords::iterator iterator;
100 
101 	for (iterator = allRecords->begin();
102 	     iterator != allRecords->end();
103 	     ++iterator)
104 	{
105 		if (pCondition->eval(*iterator))
106 			m_aMacabRecords->insertRecord(*iterator);
107 	}
108 }
109 // -------------------------------------------------------------------------
110 void MacabResultSet::sortMacabRecords(const MacabOrder *pOrder)
111 {
112 	// I do this with ints rather than an iterator because the ids will
113 	// be changing when we change the order and ints are easier to deal
114 	// with (for me).
115 	sal_Int32 i, j, size, smallest;
116 	size = m_aMacabRecords->size();
117 
118 	for(i = 0; i < size; i++)
119 	{
120 		smallest = i;
121 		for( j = i + 1; j < size; j++)
122 		{
123 			// if smallest > j
124 			if(pOrder->compare(m_aMacabRecords->getRecord(smallest),
125 						m_aMacabRecords->getRecord(j) ) > 0)
126 			{
127 				smallest = j;
128 			}
129 
130 		}
131 
132 		if(smallest != i)
133 		{
134 			m_aMacabRecords->swap(i,smallest);
135 		}
136 	}
137 
138 }
139 // -------------------------------------------------------------------------
140 void MacabResultSet::setTableName(::rtl::OUString _sTableName)
141 {
142 	m_sTableName = _sTableName;
143 }
144 // -------------------------------------------------------------------------
145 void MacabResultSet::disposing()
146 {
147 	OPropertySetHelper::disposing();
148 
149 	::osl::MutexGuard aGuard(m_aMutex);
150 
151 m_xStatement.clear();
152 m_xMetaData.clear();
153 }
154 // -------------------------------------------------------------------------
155 Any SAL_CALL MacabResultSet::queryInterface(const Type & rType) throw(RuntimeException)
156 {
157 	Any aRet = OPropertySetHelper::queryInterface(rType);
158 	if (!aRet.hasValue())
159 		aRet = MacabResultSet_BASE::queryInterface(rType);
160 	return aRet;
161 }
162 // -------------------------------------------------------------------------
163 void SAL_CALL MacabResultSet::acquire() throw()
164 {
165 	MacabResultSet_BASE::acquire();
166 }
167 // -------------------------------------------------------------------------
168 void SAL_CALL MacabResultSet::release() throw()
169 {
170 	MacabResultSet_BASE::release();
171 }
172 // -------------------------------------------------------------------------
173 Sequence<  Type > SAL_CALL MacabResultSet::getTypes() throw(RuntimeException)
174 {
175 	OTypeCollection aTypes(
176 		::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet >*) 0),
177 		::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet >*) 0),
178 		::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet >*) 0));
179 
180 	return comphelper::concatSequences(aTypes.getTypes(), MacabResultSet_BASE::getTypes());
181 }
182 // -------------------------------------------------------------------------
183 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL MacabResultSet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
184 {
185 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
186 }
187 // -------------------------------------------------------------------------
188 sal_Int32 SAL_CALL MacabResultSet::findColumn(const ::rtl::OUString& columnName) throw(SQLException, RuntimeException)
189 {
190 	::osl::MutexGuard aGuard( m_aMutex );
191 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
192 
193 	// find the first column with the name columnName
194 	Reference< XResultSetMetaData > xMeta = getMetaData();
195 	sal_Int32 nLen = xMeta->getColumnCount();
196 
197 	for (sal_Int32 i = 1; i <= nLen; ++i)
198 		if (xMeta->isCaseSensitive(i) ?
199 			columnName == xMeta->getColumnName(i) :
200 			columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
201 				return i;
202 
203     ::connectivity::SharedResources aResources;
204     const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
205             STR_NO_ELEMENT_NAME,
206             "$name$", columnName
207          ) );
208 	::dbtools::throwGenericSQLException(sError , *this);
209     // Unreachable:
210     OSL_ASSERT(false);
211     return 0;
212 }
213 // -------------------------------------------------------------------------
214 ::rtl::OUString SAL_CALL MacabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
215 {
216 	::osl::MutexGuard aGuard( m_aMutex );
217 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
218 
219 	::rtl::OUString aRet;
220 	sal_Int32 nRecords = m_aMacabRecords->size();
221 	m_bWasNull = true;
222 
223 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
224 	{
225 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
226 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
227 		if(aField != NULL)
228 		{
229 			if(aField->type == kABStringProperty)
230 			{
231 				aRet = CFStringToOUString( (CFStringRef) aField->value);
232 				m_bWasNull = false;
233 			}
234 		}
235 	}
236 
237 // Trigger an exception if m_bWasNull is true?
238 	return aRet;
239 }
240 // -------------------------------------------------------------------------
241 sal_Bool SAL_CALL MacabResultSet::getBoolean(sal_Int32) throw(SQLException, RuntimeException)
242 {
243 	::osl::MutexGuard aGuard( m_aMutex );
244 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
245 
246 ::dbtools::throwFunctionNotSupportedException("getBoolean", NULL);
247 
248 	return sal_False;
249 }
250 // -------------------------------------------------------------------------
251 sal_Int8 SAL_CALL MacabResultSet::getByte(sal_Int32) throw(SQLException, RuntimeException)
252 {
253 	::osl::MutexGuard aGuard( m_aMutex );
254 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
255 
256 ::dbtools::throwFunctionNotSupportedException("getByte", NULL);
257 
258 	sal_Int8 nRet = 0;
259 	return nRet;
260 }
261 // -------------------------------------------------------------------------
262 sal_Int16 SAL_CALL MacabResultSet::getShort(sal_Int32) throw(SQLException, RuntimeException)
263 {
264 	::osl::MutexGuard aGuard( m_aMutex );
265 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
266 
267 ::dbtools::throwFunctionNotSupportedException("getShort", NULL);
268 
269 	sal_Int16 nRet = 0;
270 	return nRet;
271 }
272 // -------------------------------------------------------------------------
273 sal_Int32 SAL_CALL MacabResultSet::getInt(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
274 {
275 	::osl::MutexGuard aGuard( m_aMutex );
276 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
277 
278 	sal_Int32 nRet = 0;
279 	sal_Int32 nRecords = m_aMacabRecords->size();
280 	m_bWasNull = true;
281 
282 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
283 	{
284 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
285 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
286 		if(aField != NULL)
287 		{
288 			if(aField->type == kABIntegerProperty)
289 			{
290 				CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
291 				// m_bWasNull now becomes whether getting the value was successful
292 				// Should we check for the wrong type here, e.g., a float or a 64 bit int?
293 				m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
294 			}
295 		}
296 	}
297 
298 // Trigger an exception if m_bWasNull is true?
299 	return nRet;
300 }
301 // -------------------------------------------------------------------------
302 sal_Int64 SAL_CALL MacabResultSet::getLong(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
303 {
304 	::osl::MutexGuard aGuard( m_aMutex );
305 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
306 
307 	sal_Int64 nRet = 0;
308 	sal_Int32 nRecords = m_aMacabRecords->size();
309 	m_bWasNull = true;
310 
311 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
312 	{
313 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
314 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
315 		if(aField != NULL)
316 		{
317 			if(aField->type == kABIntegerProperty)
318 			{
319 				CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
320 				// m_bWasNull now becomes whether getting the value was successful
321 				// Should we check for the wrong type here, e.g., a float or a 32 bit int?
322 				m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
323 			}
324 		}
325 	}
326 
327 // Trigger an exception if m_bWasNull is true?
328 	return nRet;
329 }
330 // -------------------------------------------------------------------------
331 float SAL_CALL MacabResultSet::getFloat(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
332 {
333 	::osl::MutexGuard aGuard( m_aMutex );
334 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
335 
336 	float nVal = 0;
337 	sal_Int32 nRecords = m_aMacabRecords->size();
338 	m_bWasNull = true;
339 
340 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
341 	{
342 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
343 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
344 		if(aField != NULL)
345 		{
346 			if(aField->type == kABRealProperty)
347 			{
348 				CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
349 				// m_bWasNull now becomes whether getting the value was successful
350 				// Should we check for the wrong type here, e.g., an int or a double?
351 				m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
352 			}
353 		}
354 	}
355 
356 // Trigger an exception if m_bWasNull is true?
357 	return nVal;
358 }
359 // -------------------------------------------------------------------------
360 double SAL_CALL MacabResultSet::getDouble(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
361 {
362 	::osl::MutexGuard aGuard( m_aMutex );
363 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
364 
365 	double nVal = 0;
366 	sal_Int32 nRecords = m_aMacabRecords->size();
367 	m_bWasNull = true;
368 
369 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
370 	{
371 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
372 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
373 		if(aField != NULL)
374 		{
375 			if(aField->type == kABRealProperty)
376 			{
377 				CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
378 				// m_bWasNull now becomes whether getting the value was successful
379 				// Should we check for the wrong type here, e.g., an int or a float?
380 				m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
381 			}
382 		}
383 	}
384 
385 // Trigger an exception if m_bWasNull is true?
386 	return nVal;
387 }
388 // -------------------------------------------------------------------------
389 Sequence< sal_Int8 > SAL_CALL MacabResultSet::getBytes(sal_Int32) throw(SQLException, RuntimeException)
390 {
391 	::osl::MutexGuard aGuard( m_aMutex );
392 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
393 
394 ::dbtools::throwFunctionNotSupportedException("getBytes", NULL);
395 
396 	return Sequence< sal_Int8 >();
397 }
398 // -------------------------------------------------------------------------
399 Date SAL_CALL MacabResultSet::getDate(sal_Int32) throw(SQLException, RuntimeException)
400 {
401 	::osl::MutexGuard aGuard( m_aMutex );
402 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
403 
404 ::dbtools::throwFunctionNotSupportedException("getDate", NULL);
405 
406 	Date aRet;
407 	return aRet;
408 }
409 // -------------------------------------------------------------------------
410 Time SAL_CALL MacabResultSet::getTime(sal_Int32) throw(SQLException, RuntimeException)
411 {
412 	::osl::MutexGuard aGuard( m_aMutex );
413 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
414 
415 ::dbtools::throwFunctionNotSupportedException("getTime", NULL);
416 
417 	Time nRet;
418 	return nRet;
419 }
420 // -------------------------------------------------------------------------
421 DateTime SAL_CALL MacabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
422 {
423 	::osl::MutexGuard aGuard( m_aMutex );
424 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
425 
426 	DateTime nRet;
427 	sal_Int32 nRecords = m_aMacabRecords->size();
428 	m_bWasNull = true;
429 
430 	if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
431 	{
432 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
433 		macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
434 		if(aField != NULL)
435 		{
436 			if(aField->type == kABDateProperty)
437 			{
438 				nRet = CFDateToDateTime((CFDateRef) aField->value);
439 				m_bWasNull = false;
440 			}
441 		}
442 	}
443 
444 // Trigger an exception if m_bWasNull is true?
445 	return nRet;
446 }
447 // -------------------------------------------------------------------------
448 Reference< XInputStream > SAL_CALL MacabResultSet::getBinaryStream(sal_Int32) throw(SQLException, RuntimeException)
449 {
450 	::osl::MutexGuard aGuard( m_aMutex );
451 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
452 
453 ::dbtools::throwFunctionNotSupportedException("getBinaryStream", NULL);
454 
455 	return NULL;
456 }
457 // -------------------------------------------------------------------------
458 Reference< XInputStream > SAL_CALL MacabResultSet::getCharacterStream(sal_Int32) throw(SQLException, RuntimeException)
459 {
460 	::osl::MutexGuard aGuard( m_aMutex );
461 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
462 
463 ::dbtools::throwFunctionNotSupportedException("getCharacterStream", NULL);
464 
465 	return NULL;
466 }
467 // -------------------------------------------------------------------------
468 Any SAL_CALL MacabResultSet::getObject(sal_Int32, const Reference< ::com::sun::star::container::XNameAccess >&) throw(SQLException, RuntimeException)
469 {
470 	::osl::MutexGuard aGuard( m_aMutex );
471 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
472 
473 ::dbtools::throwFunctionNotSupportedException("getObject", NULL);
474 
475 	return Any();
476 }
477 // -------------------------------------------------------------------------
478 Reference< XRef > SAL_CALL MacabResultSet::getRef(sal_Int32) throw(SQLException, RuntimeException)
479 {
480 	::osl::MutexGuard aGuard( m_aMutex );
481 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
482 
483 ::dbtools::throwFunctionNotSupportedException("getRef", NULL);
484 
485 	return NULL;
486 }
487 // -------------------------------------------------------------------------
488 Reference< XBlob > SAL_CALL MacabResultSet::getBlob(sal_Int32) throw(SQLException, RuntimeException)
489 {
490 	::osl::MutexGuard aGuard( m_aMutex );
491 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
492 
493 ::dbtools::throwFunctionNotSupportedException("getBlob", NULL);
494 
495 	return NULL;
496 }
497 // -------------------------------------------------------------------------
498 Reference< XClob > SAL_CALL MacabResultSet::getClob(sal_Int32) throw(SQLException, RuntimeException)
499 {
500 	::osl::MutexGuard aGuard( m_aMutex );
501 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
502 
503 ::dbtools::throwFunctionNotSupportedException("getClob", NULL);
504 
505 	return NULL;
506 }
507 // -------------------------------------------------------------------------
508 Reference< XArray > SAL_CALL MacabResultSet::getArray(sal_Int32) throw(SQLException, RuntimeException)
509 {
510 	::osl::MutexGuard aGuard( m_aMutex );
511 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
512 
513 ::dbtools::throwFunctionNotSupportedException("getArray", NULL);
514 
515 	return NULL;
516 }
517 // -------------------------------------------------------------------------
518 Reference< XResultSetMetaData > SAL_CALL MacabResultSet::getMetaData() throw(SQLException, RuntimeException)
519 {
520 	::osl::MutexGuard aGuard( m_aMutex );
521 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
522 
523 	if (!m_xMetaData.is())
524 		m_xMetaData = new MacabResultSetMetaData(m_xStatement->getOwnConnection(), m_sTableName);
525 
526 	Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
527 	return xMetaData;
528 }
529 // -------------------------------------------------------------------------
530 sal_Bool SAL_CALL MacabResultSet::isBeforeFirst() throw(SQLException, RuntimeException)
531 {
532 	::osl::MutexGuard aGuard( m_aMutex );
533 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
534 
535 	if (m_nRowPos == -1)
536 		return sal_True;
537 
538 	return sal_False;
539 }
540 // -------------------------------------------------------------------------
541 sal_Bool SAL_CALL MacabResultSet::isAfterLast() throw(SQLException, RuntimeException)
542 {
543 	::osl::MutexGuard aGuard( m_aMutex );
544 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
545 
546 	sal_Int32 nRecords = m_aMacabRecords->size();
547 	if (m_nRowPos == nRecords)
548 		return sal_True;
549 
550 	return sal_False;
551 }
552 // -------------------------------------------------------------------------
553 sal_Bool SAL_CALL MacabResultSet::isFirst() throw(SQLException, RuntimeException)
554 {
555 	::osl::MutexGuard aGuard( m_aMutex );
556 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
557 
558 	if (m_nRowPos == 0)
559 		return sal_True;
560 
561 	return sal_False;
562 }
563 // -------------------------------------------------------------------------
564 sal_Bool SAL_CALL MacabResultSet::isLast() throw(SQLException, RuntimeException)
565 {
566 	::osl::MutexGuard aGuard( m_aMutex );
567 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
568 
569 	sal_Int32 nRecords = m_aMacabRecords->size();
570 	if (m_nRowPos == nRecords - 1)
571 		return sal_True;
572 
573 	return sal_False;
574 }
575 // -------------------------------------------------------------------------
576 void SAL_CALL MacabResultSet::beforeFirst() throw(SQLException, RuntimeException)
577 {
578 	::osl::MutexGuard aGuard( m_aMutex );
579 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
580 
581 	// move before the first row
582 	m_nRowPos = -1;
583 }
584 // -------------------------------------------------------------------------
585 void SAL_CALL MacabResultSet::afterLast() throw(SQLException, RuntimeException)
586 {
587 	::osl::MutexGuard aGuard( m_aMutex );
588 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
589 
590 	// move after the last row
591 	sal_Int32 nRecords = m_aMacabRecords->size();
592 	m_nRowPos = nRecords;
593 }
594 // -------------------------------------------------------------------------
595 void SAL_CALL MacabResultSet::close() throw(SQLException, RuntimeException)
596 {
597 	{
598 		::osl::MutexGuard aGuard( m_aMutex );
599 		checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
600 	}
601 	dispose();
602 }
603 // -------------------------------------------------------------------------
604 sal_Bool SAL_CALL MacabResultSet::first() throw(SQLException, RuntimeException)
605 {
606 	::osl::MutexGuard aGuard( m_aMutex );
607 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
608 
609 	sal_Int32 nRecords = m_aMacabRecords->size();
610 	if (nRecords == 0)
611 		return sal_False;
612 
613 	m_nRowPos = 0;
614 	return sal_True;
615 }
616 // -------------------------------------------------------------------------
617 sal_Bool SAL_CALL MacabResultSet::last() throw(SQLException, RuntimeException)
618 {
619 	::osl::MutexGuard aGuard( m_aMutex );
620 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
621 
622 	sal_Int32 nRecords = m_aMacabRecords->size();
623 	if (nRecords == 0)
624 		return sal_False;
625 
626 	m_nRowPos = nRecords - 1;
627 	return sal_True;
628 }
629 // -------------------------------------------------------------------------
630 sal_Int32 SAL_CALL MacabResultSet::getRow() throw(SQLException, RuntimeException)
631 {
632 	::osl::MutexGuard aGuard( m_aMutex );
633 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
634 
635 	return m_nRowPos;
636 }
637 // -------------------------------------------------------------------------
638 sal_Bool SAL_CALL MacabResultSet::absolute(sal_Int32 row) throw(SQLException, RuntimeException)
639 {
640 	::osl::MutexGuard aGuard( m_aMutex );
641 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
642 
643 	sal_Int32 nRecords = m_aMacabRecords->size();
644 	if (row <= -1 ||
645 	    row >= nRecords)
646 		return sal_False;
647 
648 	m_nRowPos = row;
649 	return sal_True;
650 }
651 // -------------------------------------------------------------------------
652 sal_Bool SAL_CALL MacabResultSet::relative(sal_Int32 row) throw(SQLException, RuntimeException)
653 {
654 	::osl::MutexGuard aGuard( m_aMutex );
655 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
656 
657 	return absolute(m_nRowPos + row);
658 }
659 // -------------------------------------------------------------------------
660 sal_Bool SAL_CALL MacabResultSet::next() throw(SQLException, RuntimeException)
661 {
662 	::osl::MutexGuard aGuard( m_aMutex );
663 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
664 
665 	return absolute(m_nRowPos + 1);
666 }
667 // -------------------------------------------------------------------------
668 sal_Bool SAL_CALL MacabResultSet::previous() throw(SQLException, RuntimeException)
669 {
670 	::osl::MutexGuard aGuard( m_aMutex );
671 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
672 
673 	return absolute(m_nRowPos - 1);
674 }
675 // -------------------------------------------------------------------------
676 Reference< XInterface > SAL_CALL MacabResultSet::getStatement() throw(SQLException, RuntimeException)
677 {
678 	::osl::MutexGuard aGuard( m_aMutex );
679 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
680 
681 	Reference< XStatement > xStatement = m_xStatement.get();
682 	return xStatement;
683 }
684 // -------------------------------------------------------------------------
685 sal_Bool SAL_CALL MacabResultSet::rowDeleted() throw(SQLException, RuntimeException)
686 {
687 	::osl::MutexGuard aGuard( m_aMutex );
688 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
689 
690 	return sal_False;
691 }
692 // -------------------------------------------------------------------------
693 sal_Bool SAL_CALL MacabResultSet::rowInserted() throw(SQLException, RuntimeException)
694 {
695 	::osl::MutexGuard aGuard( m_aMutex );
696 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
697 
698 	return sal_False;
699 }
700 // -------------------------------------------------------------------------
701 sal_Bool SAL_CALL MacabResultSet::rowUpdated() throw(SQLException, RuntimeException)
702 {
703 	::osl::MutexGuard aGuard( m_aMutex );
704 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
705 
706 	return sal_False;
707 }
708 // -------------------------------------------------------------------------
709 sal_Bool SAL_CALL MacabResultSet::wasNull() throw(SQLException, RuntimeException)
710 {
711 	::osl::MutexGuard aGuard( m_aMutex );
712 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
713 
714 	return m_bWasNull;
715 }
716 // -------------------------------------------------------------------------
717 void SAL_CALL MacabResultSet::cancel() throw(RuntimeException)
718 {
719 	::osl::MutexGuard aGuard( m_aMutex );
720 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
721 }
722 // -------------------------------------------------------------------------
723 void SAL_CALL MacabResultSet::clearWarnings() throw(SQLException, RuntimeException)
724 {
725 }
726 // -------------------------------------------------------------------------
727 Any SAL_CALL MacabResultSet::getWarnings() throw(SQLException, RuntimeException)
728 {
729 	return Any();
730 }
731 // -------------------------------------------------------------------------
732 void SAL_CALL MacabResultSet::insertRow() throw(SQLException, RuntimeException)
733 {
734 	::osl::MutexGuard aGuard( m_aMutex );
735 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
736 
737 	// you only have to implement this if you want to insert new rows
738 }
739 // -------------------------------------------------------------------------
740 void SAL_CALL MacabResultSet::updateRow() throw(SQLException, RuntimeException)
741 {
742 	::osl::MutexGuard aGuard( m_aMutex );
743 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
744 
745 	// only when you allow updates
746 }
747 // -------------------------------------------------------------------------
748 void SAL_CALL MacabResultSet::deleteRow() throw(SQLException, RuntimeException)
749 {
750 	::osl::MutexGuard aGuard( m_aMutex );
751 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
752 }
753 // -------------------------------------------------------------------------
754 void SAL_CALL MacabResultSet::cancelRowUpdates() throw(SQLException, RuntimeException)
755 {
756 	::osl::MutexGuard aGuard( m_aMutex );
757 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
758 }
759 // -------------------------------------------------------------------------
760 void SAL_CALL MacabResultSet::moveToInsertRow() throw(SQLException, RuntimeException)
761 {
762 	::osl::MutexGuard aGuard( m_aMutex );
763 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
764 
765 	// only when you allow inserts
766 }
767 // -------------------------------------------------------------------------
768 void SAL_CALL MacabResultSet::moveToCurrentRow() throw(SQLException, RuntimeException)
769 {
770 	::osl::MutexGuard aGuard( m_aMutex );
771 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
772 }
773 // -------------------------------------------------------------------------
774 void SAL_CALL MacabResultSet::updateNull(sal_Int32) throw(SQLException, RuntimeException)
775 {
776 	::osl::MutexGuard aGuard( m_aMutex );
777 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
778 }
779 // -------------------------------------------------------------------------
780 void SAL_CALL MacabResultSet::updateBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
781 {
782 	::osl::MutexGuard aGuard( m_aMutex );
783 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
784 }
785 // -------------------------------------------------------------------------
786 void SAL_CALL MacabResultSet::updateByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
787 {
788 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
789 	::osl::MutexGuard aGuard( m_aMutex );
790 }
791 // -------------------------------------------------------------------------
792 void SAL_CALL MacabResultSet::updateShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
793 {
794 	::osl::MutexGuard aGuard( m_aMutex );
795 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
796 }
797 // -------------------------------------------------------------------------
798 void SAL_CALL MacabResultSet::updateInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
799 {
800 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
801 	::osl::MutexGuard aGuard( m_aMutex );
802 }
803 // -------------------------------------------------------------------------
804 void SAL_CALL MacabResultSet::updateLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
805 {
806 	::osl::MutexGuard aGuard( m_aMutex );
807 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
808 }
809 // -----------------------------------------------------------------------
810 void SAL_CALL MacabResultSet::updateFloat(sal_Int32, float) throw(SQLException, RuntimeException)
811 {
812 	::osl::MutexGuard aGuard( m_aMutex );
813 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
814 }
815 // -------------------------------------------------------------------------
816 void SAL_CALL MacabResultSet::updateDouble(sal_Int32, double) throw(SQLException, RuntimeException)
817 {
818 	::osl::MutexGuard aGuard( m_aMutex );
819 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
820 }
821 // -------------------------------------------------------------------------
822 void SAL_CALL MacabResultSet::updateString(sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
823 {
824 	::osl::MutexGuard aGuard( m_aMutex );
825 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
826 }
827 // -------------------------------------------------------------------------
828 void SAL_CALL MacabResultSet::updateBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
829 {
830 	::osl::MutexGuard aGuard( m_aMutex );
831 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
832 }
833 // -------------------------------------------------------------------------
834 void SAL_CALL MacabResultSet::updateDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
835 {
836 	::osl::MutexGuard aGuard( m_aMutex );
837 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
838 }
839 // -------------------------------------------------------------------------
840 void SAL_CALL MacabResultSet::updateTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
841 {
842 	::osl::MutexGuard aGuard( m_aMutex );
843 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
844 }
845 // -------------------------------------------------------------------------
846 void SAL_CALL MacabResultSet::updateTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
847 {
848 	::osl::MutexGuard aGuard( m_aMutex );
849 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
850 }
851 // -------------------------------------------------------------------------
852 void SAL_CALL MacabResultSet::updateBinaryStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
853 {
854 	::osl::MutexGuard aGuard( m_aMutex );
855 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
856 }
857 // -------------------------------------------------------------------------
858 void SAL_CALL MacabResultSet::updateCharacterStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
859 {
860 	::osl::MutexGuard aGuard( m_aMutex );
861 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
862 }
863 // -------------------------------------------------------------------------
864 void SAL_CALL MacabResultSet::refreshRow() throw(SQLException, RuntimeException)
865 {
866 	::osl::MutexGuard aGuard( m_aMutex );
867 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
868 }
869 // -------------------------------------------------------------------------
870 void SAL_CALL MacabResultSet::updateObject(sal_Int32, const Any&) throw(SQLException, RuntimeException)
871 {
872 	::osl::MutexGuard aGuard( m_aMutex );
873 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
874 }
875 // -------------------------------------------------------------------------
876 void SAL_CALL MacabResultSet::updateNumericObject(sal_Int32, const Any&, sal_Int32) throw(SQLException, RuntimeException)
877 {
878 	::osl::MutexGuard aGuard( m_aMutex );
879 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
880 }
881 // -------------------------------------------------------------------------
882 // XRowLocate
883 Any SAL_CALL MacabResultSet::getBookmark() throw( SQLException,  RuntimeException)
884 {
885 	::osl::MutexGuard aGuard( m_aMutex );
886 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
887 
888 	sal_Int32 nRecords = m_aMacabRecords->size();
889 
890 	if (m_nRowPos != -1 && m_nRowPos != nRecords)
891 	{
892 		macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
893 		if(uidField != NULL)
894 		{
895 			if(uidField->type == kABStringProperty)
896 			{
897 				return makeAny(CFStringToOUString( (CFStringRef) uidField->value ));
898 			}
899 		}
900 	}
901 	return Any();
902 }
903 // -------------------------------------------------------------------------
904 sal_Bool SAL_CALL MacabResultSet::moveToBookmark(const  Any& bookmark) throw( SQLException,  RuntimeException)
905 {
906 	::osl::MutexGuard aGuard( m_aMutex );
907 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
908 
909 	::rtl::OUString sBookmark = comphelper::getString(bookmark);
910         sal_Int32 nRecords = m_aMacabRecords->size();
911 
912 	for (sal_Int32 nRow = 0; nRow < nRecords; nRow++)
913 	{
914 		macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
915 		if(uidField != NULL)
916 		{
917 			if(uidField->type == kABStringProperty)
918 			{
919 				::rtl::OUString sUniqueIdentifier = CFStringToOUString( (CFStringRef) uidField->value );
920 				if (sUniqueIdentifier == sBookmark)
921 				{
922 					m_nRowPos = nRow;
923 					return sal_True;
924 				}
925 			}
926 		}
927 	}
928 	return sal_False;
929 }
930 // -------------------------------------------------------------------------
931 sal_Bool SAL_CALL MacabResultSet::moveRelativeToBookmark(const  Any& bookmark, sal_Int32 rows) throw( SQLException,  RuntimeException)
932 {
933 	::osl::MutexGuard aGuard( m_aMutex );
934 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
935 
936 	sal_Int32 nRowSave = m_nRowPos;
937 
938 	if (moveToBookmark(bookmark))
939 	{
940 		sal_Int32 nRecords = m_aMacabRecords->size();
941 
942 		m_nRowPos += rows;
943 
944 		if (-1 < m_nRowPos && m_nRowPos < nRecords)
945 			return sal_True;
946 	}
947 
948 	m_nRowPos = nRowSave;
949 	return sal_False;
950 }
951 // -------------------------------------------------------------------------
952 sal_Int32 SAL_CALL MacabResultSet::compareBookmarks(const  Any& firstItem, const  Any& secondItem) throw( SQLException,  RuntimeException)
953 {
954 	::osl::MutexGuard aGuard( m_aMutex );
955 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
956 
957 	::rtl::OUString sFirst = comphelper::getString(firstItem);
958 	::rtl::OUString sSecond = comphelper::getString(secondItem);
959 
960 	if (sFirst < sSecond)
961 		return CompareBookmark::LESS;
962 	if (sFirst > sSecond)
963 		return CompareBookmark::GREATER;
964 	return CompareBookmark::EQUAL;
965 }
966 // -------------------------------------------------------------------------
967 sal_Bool SAL_CALL MacabResultSet::hasOrderedBookmarks() throw( SQLException,  RuntimeException)
968 {
969 	return sal_False;
970 }
971 // -------------------------------------------------------------------------
972 sal_Int32 SAL_CALL MacabResultSet::hashBookmark(const  Any& bookmark) throw( SQLException,  RuntimeException)
973 {
974 	::osl::MutexGuard aGuard( m_aMutex );
975 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
976 
977 	::rtl::OUString sBookmark = comphelper::getString(bookmark);
978 
979 	return sBookmark.hashCode();
980 }
981 // -------------------------------------------------------------------------
982 // XDeleteRows
983 Sequence< sal_Int32 > SAL_CALL MacabResultSet::deleteRows(const  Sequence<  Any >&) throw( SQLException,  RuntimeException)
984 {
985 	::osl::MutexGuard aGuard( m_aMutex );
986 	checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
987 
988 	return Sequence< sal_Int32 >();
989 }
990 // -------------------------------------------------------------------------
991 IPropertyArrayHelper* MacabResultSet::createArrayHelper() const
992 {
993 	Sequence< Property > aProps(6);
994 	Property* pProperties = aProps.getArray();
995 	sal_Int32 nPos = 0;
996 	DECL_PROP1IMPL(CURSORNAME,			::rtl::OUString) PropertyAttribute::READONLY);
997 	DECL_PROP0(FETCHDIRECTION,			sal_Int32);
998 	DECL_PROP0(FETCHSIZE,				sal_Int32);
999 	DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
1000 	DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
1001 	DECL_PROP1IMPL(RESULTSETTYPE,		sal_Int32) PropertyAttribute::READONLY);
1002 
1003 	return new OPropertyArrayHelper(aProps);
1004 }
1005 // -------------------------------------------------------------------------
1006 IPropertyArrayHelper & MacabResultSet::getInfoHelper()
1007 {
1008 	return *static_cast<MacabResultSet*>(this)->getArrayHelper();
1009 }
1010 // -------------------------------------------------------------------------
1011 sal_Bool MacabResultSet::convertFastPropertyValue(
1012 			Any &,
1013 			Any &,
1014 			sal_Int32 nHandle,
1015 			const Any& )
1016 				throw (::com::sun::star::lang::IllegalArgumentException)
1017 {
1018 	switch (nHandle)
1019 	{
1020 		case PROPERTY_ID_ISBOOKMARKABLE:
1021 		case PROPERTY_ID_CURSORNAME:
1022 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1023 		case PROPERTY_ID_RESULTSETTYPE:
1024 			throw ::com::sun::star::lang::IllegalArgumentException();
1025 			break;
1026 		case PROPERTY_ID_FETCHDIRECTION:
1027 		case PROPERTY_ID_FETCHSIZE:
1028 		default:
1029 			;
1030 	}
1031 	return sal_False;
1032 }
1033 // -------------------------------------------------------------------------
1034 void MacabResultSet::setFastPropertyValue_NoBroadcast(
1035 			sal_Int32 nHandle,
1036 			const Any& )
1037 				 throw (Exception)
1038 {
1039 	switch (nHandle)
1040 	{
1041 		case PROPERTY_ID_ISBOOKMARKABLE:
1042 		case PROPERTY_ID_CURSORNAME:
1043 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1044 		case PROPERTY_ID_RESULTSETTYPE:
1045 			throw Exception();
1046 			break;
1047 		case PROPERTY_ID_FETCHDIRECTION:
1048 			break;
1049 		case PROPERTY_ID_FETCHSIZE:
1050 			break;
1051 		default:
1052 			;
1053 	}
1054 }
1055 // -------------------------------------------------------------------------
1056 void MacabResultSet::getFastPropertyValue(
1057 			Any& _rValue,
1058 			sal_Int32 nHandle) const
1059 {
1060 	switch (nHandle)
1061 	{
1062 		case PROPERTY_ID_ISBOOKMARKABLE:
1063             _rValue <<= (sal_Bool)sal_False;
1064             break;
1065 		case PROPERTY_ID_CURSORNAME:
1066 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1067 		case PROPERTY_ID_RESULTSETTYPE:
1068 		case PROPERTY_ID_FETCHDIRECTION:
1069 		case PROPERTY_ID_FETCHSIZE:
1070 			;
1071 	}
1072 }
1073 // -----------------------------------------------------------------------------
1074