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 "KResultSet.hxx"
32 #include "KResultSetMetaData.hxx"
33 #include "KConnection.hxx"
34 #include "kcondition.hxx"
35 #include "korder.hxx"
36 #include "kfields.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
39 #include "TConnection.hxx"
40 #include <connectivity/dbexception.hxx>
41 #include "resource/kab_res.hrc"
42 #include "resource/sharedresources.hxx"
43 
44 using namespace connectivity::kab;
45 using namespace cppu;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::sdbc;
50 using namespace com::sun::star::sdbcx;
51 using namespace com::sun::star::io;
52 using namespace com::sun::star::util;
53 
54 IMPLEMENT_SERVICE_INFO(KabResultSet, "com.sun.star.sdbc.drivers.KabResultSet", "com.sun.star.sdbc.ResultSet");
55 // -------------------------------------------------------------------------
56 KabResultSet::KabResultSet(KabCommonStatement* pStmt)
57 	: KabResultSet_BASE(m_aMutex),
58 	  OPropertySetHelper(KabResultSet_BASE::rBHelper),
59 	  m_xStatement(pStmt),
60 	  m_xMetaData(NULL),
61 	  m_aKabAddressees(),
62 	  m_nRowPos(-1),
63 	  m_bWasNull(sal_True)
64 {
65 }
66 // -------------------------------------------------------------------------
67 KabResultSet::~KabResultSet()
68 {
69 }
70 // -------------------------------------------------------------------------
71 void KabResultSet::allKabAddressees()
72 {
73 	KabConnection* pConnection = static_cast< KabConnection *>(m_xStatement->getConnection().get());
74 	KABC::AddressBook* pAddressBook = pConnection->getAddressBook();
75 
76 	m_aKabAddressees = pAddressBook->allAddressees();
77 }
78 // -------------------------------------------------------------------------
79 void KabResultSet::someKabAddressees(const KabCondition *pCondition)
80 {
81 	KabConnection* pConnection = static_cast< KabConnection *>(m_xStatement->getConnection().get());
82 	KABC::AddressBook* pAddressBook = pConnection->getAddressBook();
83 
84 	KABC::AddressBook::Iterator iterator;
85 
86 	for (iterator = pAddressBook->begin();
87 	     iterator != pAddressBook->end();
88 	     ++iterator)
89 	{
90 		if (pCondition->eval(*iterator))
91 			m_aKabAddressees.push_back(*iterator);
92 	}
93 }
94 // -------------------------------------------------------------------------
95 void KabResultSet::sortKabAddressees(const KabOrder *pOrder)
96 {
97 	// We do not use class KAddresseeList, which has a sorting algorithm in it, because
98 	// it uses templates. It would expand to more or less the same code as the one
99 	// which follows, but it would need not be called in a much less convenient way.
100 
101 	KABC::Addressee::List::Iterator
102 		begin = m_aKabAddressees.begin(),
103 		end = m_aKabAddressees.end(),
104 		iterator;
105 
106 	// Bubble sort. Feel free to implement a better algorithm.
107 	while (begin != end)
108 	{
109 		end--;
110 		for (iterator = begin; iterator != end; ++iterator)
111 		{
112 			if (pOrder->compare(*iterator, *end) > 0)
113 				qSwap(*iterator, *end);
114 		}
115 	}
116 }
117 // -------------------------------------------------------------------------
118 void KabResultSet::disposing()
119 {
120 	OPropertySetHelper::disposing();
121 
122 	::osl::MutexGuard aGuard(m_aMutex);
123 
124 m_xStatement.clear();
125 m_xMetaData.clear();
126 }
127 // -------------------------------------------------------------------------
128 Any SAL_CALL KabResultSet::queryInterface(const Type & rType) throw(RuntimeException)
129 {
130 	Any aRet = OPropertySetHelper::queryInterface(rType);
131 	if (!aRet.hasValue())
132 		aRet = KabResultSet_BASE::queryInterface(rType);
133 	return aRet;
134 }
135 // -------------------------------------------------------------------------
136 void SAL_CALL KabResultSet::acquire() throw()
137 {
138 	KabResultSet_BASE::acquire();
139 }
140 // -------------------------------------------------------------------------
141 void SAL_CALL KabResultSet::release() throw()
142 {
143 	KabResultSet_BASE::release();
144 }
145 // -------------------------------------------------------------------------
146 Sequence<  Type > SAL_CALL KabResultSet::getTypes() throw(RuntimeException)
147 {
148 	OTypeCollection aTypes(
149 		::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet >*) 0),
150 		::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet >*) 0),
151 		::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet >*) 0));
152 
153 	return comphelper::concatSequences(aTypes.getTypes(), KabResultSet_BASE::getTypes());
154 }
155 // -------------------------------------------------------------------------
156 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL KabResultSet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
157 {
158 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
159 }
160 // -------------------------------------------------------------------------
161 sal_Int32 SAL_CALL KabResultSet::findColumn(const ::rtl::OUString& columnName) throw(SQLException, RuntimeException)
162 {
163 	::osl::MutexGuard aGuard( m_aMutex );
164 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
165 
166 	// find the first column with the name columnName
167 	Reference< XResultSetMetaData > xMeta = getMetaData();
168 	sal_Int32 nLen = xMeta->getColumnCount();
169 
170 	for (sal_Int32 i = 1; i <= nLen; ++i)
171 		if (xMeta->isCaseSensitive(i) ?
172 			columnName == xMeta->getColumnName(i) :
173 			columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
174 				return i;
175 
176     ::connectivity::SharedResources aResources;
177     const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
178             STR_INVALID_COLUMNNAME,
179             "$columnname$",columnName
180          ) );
181     ::dbtools::throwGenericSQLException(sError,NULL);
182 
183     // Unreachable:
184     OSL_ASSERT(false);
185     return 0;
186 }
187 // -------------------------------------------------------------------------
188 ::rtl::OUString SAL_CALL KabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
189 {
190 	::osl::MutexGuard aGuard( m_aMutex );
191 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
192 
193 	::rtl::OUString aRet;
194 	sal_Int32 nAddressees = m_aKabAddressees.size();
195 	::KABC::Field::List aFields = ::KABC::Field::allFields();
196 
197 	if (m_nRowPos != -1 && m_nRowPos != nAddressees && m_xMetaData.is())
198 	{
199 		sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
200 		QString aQtName;
201 
202 		switch (nFieldNumber)
203 		{
204 			case KAB_FIELD_REVISION:
205 // trigger an exception here
206 m_bWasNull = true;
207 return aRet;
208 			default:
209 				aQtName = aFields[nFieldNumber - KAB_DATA_FIELDS]->value(m_aKabAddressees[m_nRowPos]);
210 		}
211 // KDE address book currently does not use NULL values.
212 // But it might do it someday
213 		if (!aQtName.isNull())
214 		{
215 			m_bWasNull = false;
216 			aRet = ::rtl::OUString((const sal_Unicode *) aQtName.ucs2());
217 			return aRet;
218 		}
219 	}
220 // Trigger an exception ?
221 	m_bWasNull = true;
222 	return aRet;
223 }
224 // -------------------------------------------------------------------------
225 sal_Bool SAL_CALL KabResultSet::getBoolean(sal_Int32) throw(SQLException, RuntimeException)
226 {
227 	::osl::MutexGuard aGuard( m_aMutex );
228 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
229 
230 ::dbtools::throwFunctionNotSupportedException("getBoolean", NULL);
231 
232 	return sal_False;
233 }
234 // -------------------------------------------------------------------------
235 sal_Int8 SAL_CALL KabResultSet::getByte(sal_Int32) throw(SQLException, RuntimeException)
236 {
237 	::osl::MutexGuard aGuard( m_aMutex );
238 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
239 
240 ::dbtools::throwFunctionNotSupportedException("getByte", NULL);
241 
242 	sal_Int8 nRet = 0;
243 	return nRet;
244 }
245 // -------------------------------------------------------------------------
246 sal_Int16 SAL_CALL KabResultSet::getShort(sal_Int32) throw(SQLException, RuntimeException)
247 {
248 	::osl::MutexGuard aGuard( m_aMutex );
249 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
250 
251 ::dbtools::throwFunctionNotSupportedException("getShort", NULL);
252 
253 	sal_Int16 nRet = 0;
254 	return nRet;
255 }
256 // -------------------------------------------------------------------------
257 sal_Int32 SAL_CALL KabResultSet::getInt(sal_Int32) throw(SQLException, RuntimeException)
258 {
259 	::osl::MutexGuard aGuard( m_aMutex );
260 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
261 
262 ::dbtools::throwFunctionNotSupportedException("getInt", NULL);
263 
264 	sal_Int32 nRet = 0;
265 	return nRet;
266 }
267 // -------------------------------------------------------------------------
268 sal_Int64 SAL_CALL KabResultSet::getLong(sal_Int32) throw(SQLException, RuntimeException)
269 {
270 	::osl::MutexGuard aGuard( m_aMutex );
271 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
272 
273 ::dbtools::throwFunctionNotSupportedException("getLong", NULL);
274 
275 	return sal_Int64();
276 }
277 // -------------------------------------------------------------------------
278 float SAL_CALL KabResultSet::getFloat(sal_Int32) throw(SQLException, RuntimeException)
279 {
280 	::osl::MutexGuard aGuard( m_aMutex );
281 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
282 
283 ::dbtools::throwFunctionNotSupportedException("getFloat", NULL);
284 
285 	float nVal(0);
286 	return nVal;
287 }
288 // -------------------------------------------------------------------------
289 double SAL_CALL KabResultSet::getDouble(sal_Int32) throw(SQLException, RuntimeException)
290 {
291 	::osl::MutexGuard aGuard( m_aMutex );
292 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
293 
294 ::dbtools::throwFunctionNotSupportedException("getDouble", NULL);
295 
296 	double nRet = 0;
297 	return nRet;
298 }
299 // -------------------------------------------------------------------------
300 Sequence< sal_Int8 > SAL_CALL KabResultSet::getBytes(sal_Int32) throw(SQLException, RuntimeException)
301 {
302 	::osl::MutexGuard aGuard( m_aMutex );
303 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
304 
305 ::dbtools::throwFunctionNotSupportedException("", NULL);
306 
307 	return Sequence< sal_Int8 >();
308 }
309 // -------------------------------------------------------------------------
310 Date SAL_CALL KabResultSet::getDate(sal_Int32) throw(SQLException, RuntimeException)
311 {
312 	::osl::MutexGuard aGuard( m_aMutex );
313 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
314 
315 ::dbtools::throwFunctionNotSupportedException("getDate", NULL);
316 
317 	Date aRet;
318 	return aRet;
319 }
320 // -------------------------------------------------------------------------
321 Time SAL_CALL KabResultSet::getTime(sal_Int32) throw(SQLException, RuntimeException)
322 {
323 	::osl::MutexGuard aGuard( m_aMutex );
324 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
325 
326 ::dbtools::throwFunctionNotSupportedException("getTime", NULL);
327 
328 	Time nRet;
329 	return nRet;
330 }
331 // -------------------------------------------------------------------------
332 DateTime SAL_CALL KabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
333 {
334 	::osl::MutexGuard aGuard( m_aMutex );
335 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
336 
337 	DateTime nRet;
338 	sal_Int32 nAddressees = m_aKabAddressees.size();
339 
340 	if (m_nRowPos != -1 && m_nRowPos != nAddressees && m_xMetaData.is())
341 	{
342 		KabResultSetMetaData *pMeta = static_cast<KabResultSetMetaData *>(m_xMetaData.get());
343 		sal_Int32 nFieldNumber = pMeta->fieldAtColumn(columnIndex);
344 
345 		if (nFieldNumber == KAB_FIELD_REVISION)
346 		{
347 			QDateTime nRevision(m_aKabAddressees[m_nRowPos].revision());
348 
349 			if (!nRevision.isNull())
350 			{
351 				m_bWasNull = false;
352 				nRet.Year = nRevision.date().year();
353 				nRet.Month = nRevision.date().month();
354 				nRet.Day = nRevision.date().day();
355 				nRet.Hours = nRevision.time().hour();
356 				nRet.Minutes = nRevision.time().minute();
357 				nRet.Seconds = nRevision.time().second();
358 				nRet.HundredthSeconds = nRevision.time().msec() / 10;
359 				return nRet;
360 			}
361 		}
362 		else {
363 			;
364         }
365 // trigger an exception here
366 	}
367 // Trigger an exception ?
368 	m_bWasNull = true;
369 	return nRet;
370 }
371 // -------------------------------------------------------------------------
372 Reference< XInputStream > SAL_CALL KabResultSet::getBinaryStream(sal_Int32) throw(SQLException, RuntimeException)
373 {
374 	::osl::MutexGuard aGuard( m_aMutex );
375 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
376 
377 ::dbtools::throwFunctionNotSupportedException("getBinaryStream", NULL);
378 
379 	return NULL;
380 }
381 // -------------------------------------------------------------------------
382 Reference< XInputStream > SAL_CALL KabResultSet::getCharacterStream(sal_Int32) throw(SQLException, RuntimeException)
383 {
384 	::osl::MutexGuard aGuard( m_aMutex );
385 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
386 
387 ::dbtools::throwFunctionNotSupportedException("getCharacterStream", NULL);
388 
389 	return NULL;
390 }
391 // -------------------------------------------------------------------------
392 Any SAL_CALL KabResultSet::getObject(sal_Int32, const Reference< ::com::sun::star::container::XNameAccess >&) throw(SQLException, RuntimeException)
393 {
394 	::osl::MutexGuard aGuard( m_aMutex );
395 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
396 
397 ::dbtools::throwFunctionNotSupportedException("getObject", NULL);
398 
399 	return Any();
400 }
401 // -------------------------------------------------------------------------
402 Reference< XRef > SAL_CALL KabResultSet::getRef(sal_Int32) throw(SQLException, RuntimeException)
403 {
404 	::osl::MutexGuard aGuard( m_aMutex );
405 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
406 
407 ::dbtools::throwFunctionNotSupportedException("getRef", NULL);
408 
409 	return NULL;
410 }
411 // -------------------------------------------------------------------------
412 Reference< XBlob > SAL_CALL KabResultSet::getBlob(sal_Int32) throw(SQLException, RuntimeException)
413 {
414 	::osl::MutexGuard aGuard( m_aMutex );
415 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
416 
417 ::dbtools::throwFunctionNotSupportedException("getBlob", NULL);
418 
419 	return NULL;
420 }
421 // -------------------------------------------------------------------------
422 Reference< XClob > SAL_CALL KabResultSet::getClob(sal_Int32) throw(SQLException, RuntimeException)
423 {
424 	::osl::MutexGuard aGuard( m_aMutex );
425 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
426 
427 ::dbtools::throwFunctionNotSupportedException("getClob", NULL);
428 
429 	return NULL;
430 }
431 // -------------------------------------------------------------------------
432 Reference< XArray > SAL_CALL KabResultSet::getArray(sal_Int32) throw(SQLException, RuntimeException)
433 {
434 	::osl::MutexGuard aGuard( m_aMutex );
435 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
436 
437 ::dbtools::throwFunctionNotSupportedException("getArray", NULL);
438 
439 	return NULL;
440 }
441 // -------------------------------------------------------------------------
442 Reference< XResultSetMetaData > SAL_CALL KabResultSet::getMetaData() throw(SQLException, RuntimeException)
443 {
444 	::osl::MutexGuard aGuard( m_aMutex );
445 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
446 
447 	if (!m_xMetaData.is())
448 		m_xMetaData = new KabResultSetMetaData(m_xStatement->getOwnConnection());
449 
450 	Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
451 	return xMetaData;
452 }
453 // -------------------------------------------------------------------------
454 sal_Bool SAL_CALL KabResultSet::isBeforeFirst() throw(SQLException, RuntimeException)
455 {
456 	::osl::MutexGuard aGuard( m_aMutex );
457 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
458 
459 	if (m_nRowPos == -1)
460 		return sal_True;
461 
462 	return sal_False;
463 }
464 // -------------------------------------------------------------------------
465 sal_Bool SAL_CALL KabResultSet::isAfterLast() throw(SQLException, RuntimeException)
466 {
467 	::osl::MutexGuard aGuard( m_aMutex );
468 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
469 
470 	sal_Int32 nAddressees = m_aKabAddressees.size();
471 	if (m_nRowPos == nAddressees)
472 		return sal_True;
473 
474 	return sal_False;
475 }
476 // -------------------------------------------------------------------------
477 sal_Bool SAL_CALL KabResultSet::isFirst() throw(SQLException, RuntimeException)
478 {
479 	::osl::MutexGuard aGuard( m_aMutex );
480 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
481 
482 	if (m_nRowPos == 0)
483 		return sal_True;
484 
485 	return sal_False;
486 }
487 // -------------------------------------------------------------------------
488 sal_Bool SAL_CALL KabResultSet::isLast() throw(SQLException, RuntimeException)
489 {
490 	::osl::MutexGuard aGuard( m_aMutex );
491 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
492 
493 	sal_Int32 nAddressees = m_aKabAddressees.size();
494 	if (m_nRowPos == nAddressees - 1)
495 		return sal_True;
496 
497 	return sal_False;
498 }
499 // -------------------------------------------------------------------------
500 void SAL_CALL KabResultSet::beforeFirst() throw(SQLException, RuntimeException)
501 {
502 	::osl::MutexGuard aGuard( m_aMutex );
503 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
504 
505 	// move before the first row
506 	m_nRowPos = -1;
507 }
508 // -------------------------------------------------------------------------
509 void SAL_CALL KabResultSet::afterLast() throw(SQLException, RuntimeException)
510 {
511 	::osl::MutexGuard aGuard( m_aMutex );
512 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
513 
514 	// move after the last row
515 	sal_Int32 nAddressees = m_aKabAddressees.size();
516 	m_nRowPos = nAddressees;
517 }
518 // -------------------------------------------------------------------------
519 void SAL_CALL KabResultSet::close() throw(SQLException, RuntimeException)
520 {
521 	{
522 		::osl::MutexGuard aGuard( m_aMutex );
523 		checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
524 	}
525 	dispose();
526 }
527 // -------------------------------------------------------------------------
528 sal_Bool SAL_CALL KabResultSet::first() throw(SQLException, RuntimeException)
529 {
530 	::osl::MutexGuard aGuard( m_aMutex );
531 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
532 
533 	sal_Int32 nAddressees = m_aKabAddressees.size();
534 	if (nAddressees == 0)
535 		return sal_False;
536 
537 	m_nRowPos = 0;
538 	return sal_True;
539 }
540 // -------------------------------------------------------------------------
541 sal_Bool SAL_CALL KabResultSet::last() throw(SQLException, RuntimeException)
542 {
543 	::osl::MutexGuard aGuard( m_aMutex );
544 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
545 
546 	sal_Int32 nAddressees = m_aKabAddressees.size();
547 	if (nAddressees == 0)
548 		return sal_False;
549 
550 	m_nRowPos = nAddressees - 1;
551 	return sal_True;
552 }
553 // -------------------------------------------------------------------------
554 sal_Int32 SAL_CALL KabResultSet::getRow() throw(SQLException, RuntimeException)
555 {
556 	::osl::MutexGuard aGuard( m_aMutex );
557 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
558 
559 	return m_nRowPos;
560 }
561 // -------------------------------------------------------------------------
562 sal_Bool SAL_CALL KabResultSet::absolute(sal_Int32 row) throw(SQLException, RuntimeException)
563 {
564 	::osl::MutexGuard aGuard( m_aMutex );
565 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
566 
567 	sal_Int32 nAddressees = m_aKabAddressees.size();
568 	if (row <= -1 ||
569 	    row >= nAddressees)
570 		return sal_False;
571 
572 	m_nRowPos = row;
573 	return sal_True;
574 }
575 // -------------------------------------------------------------------------
576 sal_Bool SAL_CALL KabResultSet::relative(sal_Int32 row) throw(SQLException, RuntimeException)
577 {
578 	::osl::MutexGuard aGuard( m_aMutex );
579 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
580 
581 	return absolute(m_nRowPos + row);
582 }
583 // -------------------------------------------------------------------------
584 sal_Bool SAL_CALL KabResultSet::next() throw(SQLException, RuntimeException)
585 {
586 	::osl::MutexGuard aGuard( m_aMutex );
587 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
588 
589 	return absolute(m_nRowPos + 1);
590 }
591 // -------------------------------------------------------------------------
592 sal_Bool SAL_CALL KabResultSet::previous() throw(SQLException, RuntimeException)
593 {
594 	::osl::MutexGuard aGuard( m_aMutex );
595 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
596 
597 	return absolute(m_nRowPos - 1);
598 }
599 // -------------------------------------------------------------------------
600 Reference< XInterface > SAL_CALL KabResultSet::getStatement() throw(SQLException, RuntimeException)
601 {
602 	::osl::MutexGuard aGuard( m_aMutex );
603 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
604 
605 	Reference< XStatement > xStatement = m_xStatement.get();
606 	return xStatement;
607 }
608 // -------------------------------------------------------------------------
609 sal_Bool SAL_CALL KabResultSet::rowDeleted() throw(SQLException, RuntimeException)
610 {
611 	::osl::MutexGuard aGuard( m_aMutex );
612 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
613 
614 	return sal_False;
615 }
616 // -------------------------------------------------------------------------
617 sal_Bool SAL_CALL KabResultSet::rowInserted() throw(SQLException, RuntimeException)
618 {
619 	::osl::MutexGuard aGuard( m_aMutex );
620 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
621 
622 	return sal_False;
623 }
624 // -------------------------------------------------------------------------
625 sal_Bool SAL_CALL KabResultSet::rowUpdated() throw(SQLException, RuntimeException)
626 {
627 	::osl::MutexGuard aGuard( m_aMutex );
628 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
629 
630 	return sal_False;
631 }
632 // -------------------------------------------------------------------------
633 sal_Bool SAL_CALL KabResultSet::wasNull() throw(SQLException, RuntimeException)
634 {
635 	::osl::MutexGuard aGuard( m_aMutex );
636 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
637 
638 	return m_bWasNull;
639 }
640 // -------------------------------------------------------------------------
641 void SAL_CALL KabResultSet::cancel() throw(RuntimeException)
642 {
643 	::osl::MutexGuard aGuard( m_aMutex );
644 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
645 }
646 // -------------------------------------------------------------------------
647 void SAL_CALL KabResultSet::clearWarnings() throw(SQLException, RuntimeException)
648 {
649 }
650 // -------------------------------------------------------------------------
651 Any SAL_CALL KabResultSet::getWarnings() throw(SQLException, RuntimeException)
652 {
653 	return Any();
654 }
655 // -------------------------------------------------------------------------
656 void SAL_CALL KabResultSet::insertRow() throw(SQLException, RuntimeException)
657 {
658 	::osl::MutexGuard aGuard( m_aMutex );
659 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
660 
661 	// you only have to implement this if you want to insert new rows
662 }
663 // -------------------------------------------------------------------------
664 void SAL_CALL KabResultSet::updateRow() throw(SQLException, RuntimeException)
665 {
666 	::osl::MutexGuard aGuard( m_aMutex );
667 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
668 
669 	// only when you allow updates
670 }
671 // -------------------------------------------------------------------------
672 void SAL_CALL KabResultSet::deleteRow() throw(SQLException, RuntimeException)
673 {
674 	::osl::MutexGuard aGuard( m_aMutex );
675 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
676 }
677 // -------------------------------------------------------------------------
678 void SAL_CALL KabResultSet::cancelRowUpdates() throw(SQLException, RuntimeException)
679 {
680 	::osl::MutexGuard aGuard( m_aMutex );
681 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
682 }
683 // -------------------------------------------------------------------------
684 void SAL_CALL KabResultSet::moveToInsertRow() throw(SQLException, RuntimeException)
685 {
686 	::osl::MutexGuard aGuard( m_aMutex );
687 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
688 
689 	// only when you allow inserts
690 }
691 // -------------------------------------------------------------------------
692 void SAL_CALL KabResultSet::moveToCurrentRow() throw(SQLException, RuntimeException)
693 {
694 	::osl::MutexGuard aGuard( m_aMutex );
695 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
696 }
697 // -------------------------------------------------------------------------
698 void SAL_CALL KabResultSet::updateNull(sal_Int32) throw(SQLException, RuntimeException)
699 {
700 	::osl::MutexGuard aGuard( m_aMutex );
701 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
702 }
703 // -------------------------------------------------------------------------
704 void SAL_CALL KabResultSet::updateBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
705 {
706 	::osl::MutexGuard aGuard( m_aMutex );
707 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
708 }
709 // -------------------------------------------------------------------------
710 void SAL_CALL KabResultSet::updateByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
711 {
712 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
713 	::osl::MutexGuard aGuard( m_aMutex );
714 }
715 // -------------------------------------------------------------------------
716 void SAL_CALL KabResultSet::updateShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
717 {
718 	::osl::MutexGuard aGuard( m_aMutex );
719 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
720 }
721 // -------------------------------------------------------------------------
722 void SAL_CALL KabResultSet::updateInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
723 {
724 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
725 	::osl::MutexGuard aGuard( m_aMutex );
726 }
727 // -------------------------------------------------------------------------
728 void SAL_CALL KabResultSet::updateLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
729 {
730 	::osl::MutexGuard aGuard( m_aMutex );
731 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
732 }
733 // -----------------------------------------------------------------------
734 void SAL_CALL KabResultSet::updateFloat(sal_Int32, float) throw(SQLException, RuntimeException)
735 {
736 	::osl::MutexGuard aGuard( m_aMutex );
737 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
738 }
739 // -------------------------------------------------------------------------
740 void SAL_CALL KabResultSet::updateDouble(sal_Int32, double) throw(SQLException, RuntimeException)
741 {
742 	::osl::MutexGuard aGuard( m_aMutex );
743 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
744 }
745 // -------------------------------------------------------------------------
746 void SAL_CALL KabResultSet::updateString(sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
747 {
748 	::osl::MutexGuard aGuard( m_aMutex );
749 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
750 }
751 // -------------------------------------------------------------------------
752 void SAL_CALL KabResultSet::updateBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
753 {
754 	::osl::MutexGuard aGuard( m_aMutex );
755 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
756 }
757 // -------------------------------------------------------------------------
758 void SAL_CALL KabResultSet::updateDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
759 {
760 	::osl::MutexGuard aGuard( m_aMutex );
761 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
762 }
763 // -------------------------------------------------------------------------
764 void SAL_CALL KabResultSet::updateTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
765 {
766 	::osl::MutexGuard aGuard( m_aMutex );
767 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
768 }
769 // -------------------------------------------------------------------------
770 void SAL_CALL KabResultSet::updateTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
771 {
772 	::osl::MutexGuard aGuard( m_aMutex );
773 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
774 }
775 // -------------------------------------------------------------------------
776 void SAL_CALL KabResultSet::updateBinaryStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
777 {
778 	::osl::MutexGuard aGuard( m_aMutex );
779 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
780 }
781 // -------------------------------------------------------------------------
782 void SAL_CALL KabResultSet::updateCharacterStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
783 {
784 	::osl::MutexGuard aGuard( m_aMutex );
785 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
786 }
787 // -------------------------------------------------------------------------
788 void SAL_CALL KabResultSet::refreshRow() throw(SQLException, RuntimeException)
789 {
790 	::osl::MutexGuard aGuard( m_aMutex );
791 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
792 }
793 // -------------------------------------------------------------------------
794 void SAL_CALL KabResultSet::updateObject(sal_Int32, const Any&) throw(SQLException, RuntimeException)
795 {
796 	::osl::MutexGuard aGuard( m_aMutex );
797 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
798 }
799 // -------------------------------------------------------------------------
800 void SAL_CALL KabResultSet::updateNumericObject(sal_Int32, const Any&, sal_Int32) throw(SQLException, RuntimeException)
801 {
802 	::osl::MutexGuard aGuard( m_aMutex );
803 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
804 }
805 // -------------------------------------------------------------------------
806 // XRowLocate
807 Any SAL_CALL KabResultSet::getBookmark() throw( SQLException,  RuntimeException)
808 {
809 	::osl::MutexGuard aGuard( m_aMutex );
810 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
811 
812         sal_Int32 nAddressees = m_aKabAddressees.size();
813 
814         if (m_nRowPos != -1 && m_nRowPos != nAddressees)
815         {
816                 QString aQtName = m_aKabAddressees[m_nRowPos].uid();
817        		::rtl::OUString sUniqueIdentifier = ::rtl::OUString((const sal_Unicode *) aQtName.ucs2());
818 		return makeAny(sUniqueIdentifier);
819 	}
820 	return Any();
821 }
822 // -------------------------------------------------------------------------
823 sal_Bool SAL_CALL KabResultSet::moveToBookmark(const  Any& bookmark) throw( SQLException,  RuntimeException)
824 {
825 	::osl::MutexGuard aGuard( m_aMutex );
826 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
827 
828 	::rtl::OUString sBookmark = comphelper::getString(bookmark);
829         sal_Int32 nAddressees = m_aKabAddressees.size();
830 
831 	for (sal_Int32 nRow = 0; nRow < nAddressees; nRow++)
832 	{
833                 QString aQtName = m_aKabAddressees[nRow].uid();
834        		::rtl::OUString sUniqueIdentifier = ::rtl::OUString((const sal_Unicode *) aQtName.ucs2());
835 
836 		if (sUniqueIdentifier == sBookmark)
837 		{
838 			m_nRowPos = nRow;
839 			return sal_True;
840 		}
841 	}
842 	return sal_False;
843 }
844 // -------------------------------------------------------------------------
845 sal_Bool SAL_CALL KabResultSet::moveRelativeToBookmark(const  Any& bookmark, sal_Int32 rows) throw( SQLException,  RuntimeException)
846 {
847 	::osl::MutexGuard aGuard( m_aMutex );
848 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
849 
850 	sal_Int32 nRowSave = m_nRowPos;
851 
852 	if (moveToBookmark(bookmark))
853 	{
854 		sal_Int32 nAddressees = m_aKabAddressees.size();
855 
856 		m_nRowPos += rows;
857 
858 		if (-1 < m_nRowPos && m_nRowPos < nAddressees)
859 			return sal_True;
860 	}
861 
862 	m_nRowPos = nRowSave;
863 	return sal_False;
864 }
865 // -------------------------------------------------------------------------
866 sal_Int32 SAL_CALL KabResultSet::compareBookmarks(const  Any& firstItem, const  Any& secondItem) throw( SQLException,  RuntimeException)
867 {
868 	::osl::MutexGuard aGuard( m_aMutex );
869 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
870 
871 	::rtl::OUString sFirst = comphelper::getString(firstItem);
872 	::rtl::OUString sSecond = comphelper::getString(secondItem);
873 
874 	if (sFirst < sSecond)
875 		return CompareBookmark::LESS;
876 	if (sFirst > sSecond)
877 		return CompareBookmark::GREATER;
878 	return CompareBookmark::EQUAL;
879 }
880 // -------------------------------------------------------------------------
881 sal_Bool SAL_CALL KabResultSet::hasOrderedBookmarks() throw( SQLException,  RuntimeException)
882 {
883 	return sal_False;
884 }
885 // -------------------------------------------------------------------------
886 sal_Int32 SAL_CALL KabResultSet::hashBookmark(const  Any& bookmark) throw( SQLException,  RuntimeException)
887 {
888 	::osl::MutexGuard aGuard( m_aMutex );
889 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
890 
891 	::rtl::OUString sBookmark = comphelper::getString(bookmark);
892 
893 	return sBookmark.hashCode();
894 }
895 // -------------------------------------------------------------------------
896 // XDeleteRows
897 Sequence< sal_Int32 > SAL_CALL KabResultSet::deleteRows(const  Sequence<  Any >&) throw( SQLException,  RuntimeException)
898 {
899 	::osl::MutexGuard aGuard( m_aMutex );
900 	checkDisposed(KabResultSet_BASE::rBHelper.bDisposed);
901 
902 	return Sequence< sal_Int32 >();
903 }
904 // -------------------------------------------------------------------------
905 IPropertyArrayHelper* KabResultSet::createArrayHelper() const
906 {
907 	Sequence< Property > aProps(6);
908 	Property* pProperties = aProps.getArray();
909 	sal_Int32 nPos = 0;
910 	DECL_PROP1IMPL(CURSORNAME,			::rtl::OUString) PropertyAttribute::READONLY);
911 	DECL_PROP0(FETCHDIRECTION,			sal_Int32);
912 	DECL_PROP0(FETCHSIZE,				sal_Int32);
913 	DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
914 	DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
915 	DECL_PROP1IMPL(RESULTSETTYPE,		sal_Int32) PropertyAttribute::READONLY);
916 
917 	return new OPropertyArrayHelper(aProps);
918 }
919 // -------------------------------------------------------------------------
920 IPropertyArrayHelper & KabResultSet::getInfoHelper()
921 {
922 	return *static_cast<KabResultSet*>(this)->getArrayHelper();
923 }
924 // -------------------------------------------------------------------------
925 sal_Bool KabResultSet::convertFastPropertyValue(
926 			Any &,
927 			Any &,
928 			sal_Int32 nHandle,
929 			const Any& )
930 				throw (::com::sun::star::lang::IllegalArgumentException)
931 {
932 	switch (nHandle)
933 	{
934 		case PROPERTY_ID_ISBOOKMARKABLE:
935 		case PROPERTY_ID_CURSORNAME:
936 		case PROPERTY_ID_RESULTSETCONCURRENCY:
937 		case PROPERTY_ID_RESULTSETTYPE:
938 			throw ::com::sun::star::lang::IllegalArgumentException();
939 			break;
940 		case PROPERTY_ID_FETCHDIRECTION:
941 		case PROPERTY_ID_FETCHSIZE:
942 		default:
943 			;
944 	}
945 	return sal_False;
946 }
947 // -------------------------------------------------------------------------
948 void KabResultSet::setFastPropertyValue_NoBroadcast(
949 			sal_Int32 nHandle,
950 			const Any& )
951 				 throw (Exception)
952 {
953 	switch (nHandle)
954 	{
955 		case PROPERTY_ID_ISBOOKMARKABLE:
956 		case PROPERTY_ID_CURSORNAME:
957 		case PROPERTY_ID_RESULTSETCONCURRENCY:
958 		case PROPERTY_ID_RESULTSETTYPE:
959 			throw Exception();
960 			break;
961 		case PROPERTY_ID_FETCHDIRECTION:
962 			break;
963 		case PROPERTY_ID_FETCHSIZE:
964 			break;
965 		default:
966 			;
967 	}
968 }
969 // -------------------------------------------------------------------------
970 void KabResultSet::getFastPropertyValue(
971 			Any& _rValue,
972 			sal_Int32 nHandle) const
973 {
974 	switch (nHandle)
975 	{
976 		case PROPERTY_ID_ISBOOKMARKABLE:
977             _rValue <<= (sal_Bool)sal_False;
978             break;
979 		case PROPERTY_ID_CURSORNAME:
980 		case PROPERTY_ID_RESULTSETCONCURRENCY:
981 		case PROPERTY_ID_RESULTSETTYPE:
982 		case PROPERTY_ID_FETCHDIRECTION:
983 		case PROPERTY_ID_FETCHSIZE:
984 			;
985 	}
986 }
987 // -----------------------------------------------------------------------------
988