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