1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mysqlc_propertyids.hxx"
21 #include "mysqlc_general.hxx"
22 #include "mysqlc_resultset.hxx"
23 #include "mysqlc_resultsetmetadata.hxx"
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
27 #include <com/sun/star/sdbc/ResultSetType.hpp>
28 #include <com/sun/star/sdbc/FetchDirection.hpp>
29 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <comphelper/seqstream.hxx>
36 using namespace connectivity::mysqlc
;
38 using namespace com::sun::star
;
39 using namespace com::sun::star::lang
;
40 using namespace com::sun::star::beans
;
41 using namespace com::sun::star::sdbc
;
42 using namespace com::sun::star::sdbcx
;
43 using namespace com::sun::star::container
;
44 using namespace com::sun::star::io
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::util
;
47 using namespace ::comphelper
;
48 using ::osl::MutexGuard
;
52 // copied from string misc, it should be replaced when library is not an
54 std::vector
<OString
> lcl_split(const OString
& rStr
, char cSeparator
)
56 std::vector
<OString
> vec
;
60 OString kw
= rStr
.getToken(0, cSeparator
, idx
);
71 void OResultSet::checkRowIndex()
73 if (m_nRowPosition
< 0 || m_nRowPosition
>= m_nRowCount
)
75 throw SQLException("Cursor position out of range", *this, OUString(), 1, Any());
79 bool OResultSet::checkNull(sal_Int32 column
)
81 if (m_aRows
[m_nRowPosition
][column
- 1].isEmpty())
90 OUString SAL_CALL
OResultSet::getImplementationName()
92 return "com.sun.star.sdbcx.mysqlc.ResultSet";
95 uno::Sequence
<OUString
> SAL_CALL
OResultSet::getSupportedServiceNames()
97 return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
100 sal_Bool SAL_CALL
OResultSet::supportsService(const OUString
& _rServiceName
)
102 return cppu::supportsService(this, _rServiceName
);
105 OResultSet::OResultSet(OConnection
& rConn
, OCommonStatement
* pStmt
, MYSQL_RES
* pResult
,
106 rtl_TextEncoding _encoding
)
107 : OResultSet_BASE(m_aMutex
)
108 , OPropertySetHelper(OResultSet_BASE::rBHelper
)
109 , m_pMysql(rConn
.getMysqlConnection())
110 , m_aStatement(static_cast<OWeakObject
*>(pStmt
))
112 , m_encoding(_encoding
)
115 m_xMetaData
= new OResultSetMetaData(rConn
, m_pResult
);
118 void OResultSet::ensureResultFetched()
126 void OResultSet::ensureFieldInfoFetched()
128 if (m_pResult
== nullptr)
129 return; // already fetched
131 // it works only if result set is produced via mysql_store_result
133 m_nRowCount
= mysql_num_rows(m_pResult
);
135 if (!m_aFields
.empty())
137 unsigned nFieldCount
= mysql_num_fields(m_pResult
);
138 MYSQL_FIELD
* pFields
= mysql_fetch_fields(m_pResult
);
139 m_aFields
.reserve(nFieldCount
);
140 for (unsigned i
= 0; i
< nFieldCount
; ++i
)
141 m_aFields
.push_back(OUString
{
142 pFields
[i
].name
, static_cast<sal_Int32
>(strlen(pFields
[i
].name
)), m_encoding
});
145 void OResultSet::fetchResult()
147 // Mysql C API does not allow simultaneously opened result sets, but sdbc does.
148 // Because of that we need to fetch all of the data ASAP
149 ensureFieldInfoFetched();
151 // fetch all the data
152 m_aRows
.reserve(m_nRowCount
);
154 for (sal_Int32 row
= 0; row
< m_nRowCount
; ++row
)
156 MYSQL_ROW data
= mysql_fetch_row(m_pResult
);
157 unsigned long* lengths
= mysql_fetch_lengths(m_pResult
);
158 m_aRows
.push_back(DataFields
{});
159 // MYSQL_ROW is char**, array of strings
160 for (std::size_t col
= 0; col
< m_aFields
.size(); ++col
)
162 m_aRows
.back().push_back(OString
{ data
[col
], static_cast<sal_Int32
>(lengths
[col
]) });
165 unsigned errorNum
= mysql_errno(m_pMysql
);
167 mysqlc_sdbc_driver::throwSQLExceptionWithMsg(
168 mysql_error(m_pMysql
), mysql_sqlstate(m_pMysql
), errorNum
, *this, m_encoding
);
169 mysql_free_result(m_pResult
);
173 void OResultSet::disposing()
175 OPropertySetHelper::disposing();
177 MutexGuard
aGuard(m_aMutex
);
179 if (m_pResult
!= nullptr)
181 mysql_free_result(m_pResult
);
184 m_aStatement
= nullptr;
185 m_xMetaData
= nullptr;
188 Any SAL_CALL
OResultSet::queryInterface(const Type
& rType
)
190 Any aRet
= OPropertySetHelper::queryInterface(rType
);
191 if (!aRet
.hasValue())
193 aRet
= OResultSet_BASE::queryInterface(rType
);
198 uno::Sequence
<Type
> SAL_CALL
OResultSet::getTypes()
200 OTypeCollection
aTypes(cppu::UnoType
<XMultiPropertySet
>::get(),
201 cppu::UnoType
<XFastPropertySet
>::get(),
202 cppu::UnoType
<XPropertySet
>::get());
204 return concatSequences(aTypes
.getTypes(), OResultSet_BASE::getTypes());
207 sal_Int32 SAL_CALL
OResultSet::findColumn(const OUString
& columnName
)
209 MutexGuard
aGuard(m_aMutex
);
210 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
211 ensureFieldInfoFetched();
213 for (std::size_t i
= 0; i
< m_aFields
.size(); ++i
)
215 if (columnName
.equalsIgnoreAsciiCase(m_aFields
[i
]))
216 return static_cast<sal_Int32
>(i
) + 1; // sdbc indexes from 1
219 throw SQLException("The column name '" + columnName
+ "' is not valid.", *this, "42S22", 0,
223 uno::Reference
<XInputStream
> SAL_CALL
OResultSet::getBinaryStream(sal_Int32 column
)
225 MutexGuard
aGuard(m_aMutex
);
226 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
227 checkBordersAndEnsureFetched(column
);
228 if (checkNull(column
))
231 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
232 return new SequenceInputStream
{ uno::Sequence
<sal_Int8
>(
233 reinterpret_cast<sal_Int8
const*>(sVal
.getStr()), getDataLength(column
)) };
236 uno::Reference
<XInputStream
> SAL_CALL
OResultSet::getCharacterStream(sal_Int32 column
)
238 MutexGuard
aGuard(m_aMutex
);
239 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
240 checkBordersAndEnsureFetched(column
);
241 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getCharacterStream",
246 sal_Bool SAL_CALL
OResultSet::getBoolean(sal_Int32 column
)
248 MutexGuard
aGuard(m_aMutex
);
249 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
250 checkBordersAndEnsureFetched(column
);
251 if (checkNull(column
))
254 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
255 return sVal
.toInt32() != 0;
258 sal_Int8 SAL_CALL
OResultSet::getByte(sal_Int32 column
)
260 MutexGuard
aGuard(m_aMutex
);
261 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
262 checkBordersAndEnsureFetched(column
);
263 if (checkNull(column
))
266 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
268 return static_cast<sal_Int8
>(sVal
.toInt32());
271 uno::Sequence
<sal_Int8
> SAL_CALL
OResultSet::getBytes(sal_Int32 column
)
273 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
274 MutexGuard
aGuard(m_aMutex
);
275 checkBordersAndEnsureFetched(column
);
276 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
277 if (checkNull(column
))
278 return uno::Sequence
<sal_Int8
>();
280 return uno::Sequence
<sal_Int8
>(reinterpret_cast<sal_Int8
const*>(sVal
.getStr()),
281 getDataLength(column
));
284 Date SAL_CALL
OResultSet::getDate(sal_Int32 column
)
286 MutexGuard
aGuard(m_aMutex
);
287 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
288 checkBordersAndEnsureFetched(column
);
292 if (checkNull(column
))
295 OString dateStr
= m_aRows
[m_nRowPosition
][column
- 1];
297 OString
dateString(dateStr
);
299 sal_Int32 nIndex
= 0, i
= 0;
302 token
= dateString
.getToken(0, '-', nIndex
);
306 d
.Year
= static_cast<sal_uInt16
>(token
.toUInt32());
309 d
.Month
= static_cast<sal_uInt16
>(token
.toUInt32());
312 d
.Day
= static_cast<sal_uInt16
>(token
.toUInt32());
317 } while (nIndex
>= 0);
321 double SAL_CALL
OResultSet::getDouble(sal_Int32 column
)
323 MutexGuard
aGuard(m_aMutex
);
324 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
325 checkBordersAndEnsureFetched(column
);
327 if (checkNull(column
))
330 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
331 return sVal
.toDouble();
334 float SAL_CALL
OResultSet::getFloat(sal_Int32 column
)
336 MutexGuard
aGuard(m_aMutex
);
337 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
338 checkBordersAndEnsureFetched(column
);
339 if (checkNull(column
))
342 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
343 return sVal
.toFloat();
346 sal_Int32 SAL_CALL
OResultSet::getInt(sal_Int32 column
)
348 MutexGuard
aGuard(m_aMutex
);
349 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
350 checkBordersAndEnsureFetched(column
);
351 if (checkNull(column
))
354 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
355 return sVal
.toInt32();
358 sal_Int32 SAL_CALL
OResultSet::getRow()
360 MutexGuard
aGuard(m_aMutex
);
361 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
363 return m_nRowPosition
+ 1; // indexed from 1
366 sal_Int64 SAL_CALL
OResultSet::getLong(sal_Int32 column
)
368 MutexGuard
aGuard(m_aMutex
);
369 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
370 checkBordersAndEnsureFetched(column
);
371 if (checkNull(column
))
374 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
375 return sVal
.toInt64();
378 uno::Reference
<XResultSetMetaData
> SAL_CALL
OResultSet::getMetaData()
380 MutexGuard
aGuard(m_aMutex
);
381 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
385 uno::Reference
<XArray
> SAL_CALL
OResultSet::getArray(sal_Int32 column
)
387 MutexGuard
aGuard(m_aMutex
);
388 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
389 checkBordersAndEnsureFetched(column
);
391 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getArray", *this);
395 uno::Reference
<XClob
> SAL_CALL
OResultSet::getClob(sal_Int32 column
)
397 MutexGuard
aGuard(m_aMutex
);
398 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
399 checkBordersAndEnsureFetched(column
);
401 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getClob", *this);
405 uno::Reference
<XBlob
> SAL_CALL
OResultSet::getBlob(sal_Int32 column
)
407 MutexGuard
aGuard(m_aMutex
);
408 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
409 checkBordersAndEnsureFetched(column
);
411 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getBlob", *this);
415 uno::Reference
<XRef
> SAL_CALL
OResultSet::getRef(sal_Int32 column
)
417 MutexGuard
aGuard(m_aMutex
);
418 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
419 checkBordersAndEnsureFetched(column
);
421 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getRef", *this);
425 Any SAL_CALL
OResultSet::getObject(sal_Int32 column
,
426 const uno::Reference
<XNameAccess
>& /* typeMap */)
428 MutexGuard
aGuard(m_aMutex
);
429 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
430 checkBordersAndEnsureFetched(column
);
432 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getObject", *this);
436 sal_Int16 SAL_CALL
OResultSet::getShort(sal_Int32 column
)
438 MutexGuard
aGuard(m_aMutex
);
439 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
440 checkBordersAndEnsureFetched(column
);
441 if (checkNull(column
))
444 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
445 return sVal
.toInt32();
448 OUString SAL_CALL
OResultSet::getString(sal_Int32 column
)
450 MutexGuard
aGuard(m_aMutex
);
451 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
452 checkBordersAndEnsureFetched(column
);
453 if (checkNull(column
))
454 return rtl::OUString
{};
456 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
457 return OStringToOUString(sVal
, m_encoding
);
460 Time SAL_CALL
OResultSet::getTime(sal_Int32 column
)
462 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
463 MutexGuard
aGuard(m_aMutex
);
464 checkBordersAndEnsureFetched(column
);
467 if (checkNull(column
))
470 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
471 OString timeString
{ sVal
.getStr(), getDataLength(column
) };
473 sal_Int32 nIndex
, i
= 0;
475 nIndex
= timeString
.indexOf(' ') + 1;
478 token
= timeString
.getToken(0, ':', nIndex
);
482 t
.Hours
= static_cast<sal_uInt16
>(token
.toUInt32());
485 t
.Minutes
= static_cast<sal_uInt16
>(token
.toUInt32());
488 t
.Seconds
= static_cast<sal_uInt16
>(token
.toUInt32());
492 } while (nIndex
>= 0);
497 DateTime SAL_CALL
OResultSet::getTimestamp(sal_Int32 column
)
499 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
500 MutexGuard
aGuard(m_aMutex
);
501 checkBordersAndEnsureFetched(column
);
503 if (checkNull(column
))
506 OString sVal
= m_aRows
[m_nRowPosition
][column
- 1];
509 std::vector
<OString
> dateAndTime
510 = lcl_split(OString
{ sVal
.getStr(), getDataLength(column
) }, ' ');
512 auto dateParts
= lcl_split(dateAndTime
.at(0), '-');
513 auto timeParts
= lcl_split(dateAndTime
.at(1), ':');
515 if (dateParts
.size() < 2 || timeParts
.size() < 2)
516 throw SQLException("Timestamp has a wrong format", *this, OUString(), 1, Any());
520 dt
.Year
= dateParts
.at(0).toUInt32();
521 dt
.Month
= dateParts
.at(1).toUInt32();
522 dt
.Day
= dateParts
.at(2).toUInt32();
523 dt
.Hours
= timeParts
.at(0).toUInt32();
524 dt
.Minutes
= timeParts
.at(1).toUInt32();
525 dt
.Seconds
= timeParts
.at(2).toUInt32();
529 sal_Bool SAL_CALL
OResultSet::isBeforeFirst()
531 MutexGuard
aGuard(m_aMutex
);
532 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
534 return m_nRowPosition
< 0;
537 sal_Bool SAL_CALL
OResultSet::isAfterLast()
539 MutexGuard
aGuard(m_aMutex
);
540 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
541 ensureFieldInfoFetched();
543 return m_nRowPosition
>= m_nRowCount
;
546 sal_Bool SAL_CALL
OResultSet::isFirst()
548 MutexGuard
aGuard(m_aMutex
);
549 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
550 ensureFieldInfoFetched();
552 return m_nRowPosition
== 0 && !isAfterLast();
555 sal_Bool SAL_CALL
OResultSet::isLast()
557 MutexGuard
aGuard(m_aMutex
);
558 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
559 ensureFieldInfoFetched();
561 return m_nRowPosition
== m_nRowCount
- 1;
564 void SAL_CALL
OResultSet::beforeFirst()
566 MutexGuard
aGuard(m_aMutex
);
567 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
571 void SAL_CALL
OResultSet::afterLast()
573 MutexGuard
aGuard(m_aMutex
);
574 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
575 ensureFieldInfoFetched();
576 m_nRowPosition
= m_nRowCount
;
579 void SAL_CALL
OResultSet::close()
581 MutexGuard
aGuard(m_aMutex
);
582 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
584 if (m_pResult
!= nullptr)
586 mysql_free_result(m_pResult
);
592 sal_Bool SAL_CALL
OResultSet::first()
594 MutexGuard
aGuard(m_aMutex
);
595 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
601 sal_Bool SAL_CALL
OResultSet::last()
603 MutexGuard
aGuard(m_aMutex
);
604 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
605 ensureFieldInfoFetched();
606 m_nRowPosition
= m_nRowCount
- 1;
611 sal_Bool SAL_CALL
OResultSet::absolute(sal_Int32 row
)
613 MutexGuard
aGuard(m_aMutex
);
614 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
615 ensureFieldInfoFetched();
617 sal_Int32 nToGo
= row
< 0 ? (m_nRowCount
- 1) - row
: row
- 1;
619 if (nToGo
>= m_nRowCount
)
620 nToGo
= m_nRowCount
- 1;
624 m_nRowPosition
= nToGo
;
629 sal_Bool SAL_CALL
OResultSet::relative(sal_Int32 row
)
631 MutexGuard
aGuard(m_aMutex
);
632 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
633 ensureFieldInfoFetched();
638 sal_Int32 nToGo
= m_nRowPosition
+ row
;
639 if (nToGo
>= m_nRowCount
)
640 nToGo
= m_nRowCount
- 1;
644 m_nRowPosition
= nToGo
;
649 sal_Bool SAL_CALL
OResultSet::previous()
651 MutexGuard
aGuard(m_aMutex
);
652 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
654 if (m_nRowPosition
== 0)
659 else if (m_nRowPosition
< 0)
668 uno::Reference
<uno::XInterface
> SAL_CALL
OResultSet::getStatement()
670 MutexGuard
aGuard(m_aMutex
);
671 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
673 return m_aStatement
.get();
676 sal_Bool SAL_CALL
OResultSet::rowDeleted()
678 MutexGuard
aGuard(m_aMutex
);
679 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
684 sal_Bool SAL_CALL
OResultSet::rowInserted()
686 MutexGuard
aGuard(m_aMutex
);
687 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
692 sal_Bool SAL_CALL
OResultSet::rowUpdated()
694 MutexGuard
aGuard(m_aMutex
);
695 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
700 sal_Bool SAL_CALL
OResultSet::next()
702 MutexGuard
aGuard(m_aMutex
);
703 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
704 ensureFieldInfoFetched();
705 if (m_nRowPosition
+ 1 > m_nRowCount
) // afterlast
707 if (m_nRowPosition
+ 1 == m_nRowCount
) // last
709 // return false but take it to afterlast anyway
717 sal_Bool SAL_CALL
OResultSet::wasNull()
719 MutexGuard
aGuard(m_aMutex
);
720 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
725 void SAL_CALL
OResultSet::cancel()
727 MutexGuard
aGuard(m_aMutex
);
728 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
731 void SAL_CALL
OResultSet::clearWarnings() {}
733 Any SAL_CALL
OResultSet::getWarnings() { return Any(); }
735 void SAL_CALL
OResultSet::insertRow()
737 MutexGuard
aGuard(m_aMutex
);
738 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
739 // you only have to implement this if you want to insert new rows
740 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::insertRow", *this);
743 void SAL_CALL
OResultSet::updateRow()
745 MutexGuard
aGuard(m_aMutex
);
746 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
748 // only when you allow updates
749 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateRow", *this);
752 void SAL_CALL
OResultSet::deleteRow()
754 MutexGuard
aGuard(m_aMutex
);
755 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
756 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::deleteRow", *this);
759 void SAL_CALL
OResultSet::cancelRowUpdates()
761 MutexGuard
aGuard(m_aMutex
);
762 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
763 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::cancelRowUpdates", *this);
766 void SAL_CALL
OResultSet::moveToInsertRow()
768 MutexGuard
aGuard(m_aMutex
);
769 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
771 // only when you allow insert's
772 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::moveToInsertRow", *this);
775 void SAL_CALL
OResultSet::moveToCurrentRow()
777 MutexGuard
aGuard(m_aMutex
);
778 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
781 void SAL_CALL
OResultSet::updateNull(sal_Int32 column
)
783 MutexGuard
aGuard(m_aMutex
);
784 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
785 checkColumnIndex(column
);
787 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateNull", *this);
790 void SAL_CALL
OResultSet::updateBoolean(sal_Int32 column
, sal_Bool
/* x */)
792 MutexGuard
aGuard(m_aMutex
);
793 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
794 checkColumnIndex(column
);
796 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateBoolean", *this);
799 void SAL_CALL
OResultSet::updateByte(sal_Int32 column
, sal_Int8
/* x */)
801 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
802 MutexGuard
aGuard(m_aMutex
);
803 checkColumnIndex(column
);
805 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateByte", *this);
808 void SAL_CALL
OResultSet::updateShort(sal_Int32 column
, sal_Int16
/* x */)
810 MutexGuard
aGuard(m_aMutex
);
811 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
812 checkColumnIndex(column
);
814 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateShort", *this);
817 void SAL_CALL
OResultSet::updateInt(sal_Int32 column
, sal_Int32
/* x */)
819 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
820 MutexGuard
aGuard(m_aMutex
);
821 checkColumnIndex(column
);
823 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateInt", *this);
826 void SAL_CALL
OResultSet::updateLong(sal_Int32 column
, sal_Int64
/* x */)
828 MutexGuard
aGuard(m_aMutex
);
829 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
830 checkColumnIndex(column
);
832 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateLong", *this);
835 void SAL_CALL
OResultSet::updateFloat(sal_Int32 column
, float /* x */)
837 MutexGuard
aGuard(m_aMutex
);
838 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
839 checkColumnIndex(column
);
841 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateFloat", *this);
844 void SAL_CALL
OResultSet::updateDouble(sal_Int32 column
, double /* x */)
846 MutexGuard
aGuard(m_aMutex
);
847 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
848 checkColumnIndex(column
);
850 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateDouble", *this);
853 void SAL_CALL
OResultSet::updateString(sal_Int32 column
, const OUString
& /* x */)
855 MutexGuard
aGuard(m_aMutex
);
856 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
857 checkColumnIndex(column
);
859 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateString", *this);
862 void SAL_CALL
OResultSet::updateBytes(sal_Int32 column
, const uno::Sequence
<sal_Int8
>& /* x */)
864 MutexGuard
aGuard(m_aMutex
);
865 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
866 checkColumnIndex(column
);
868 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateBytes", *this);
871 void SAL_CALL
OResultSet::updateDate(sal_Int32 column
, const Date
& /* x */)
873 MutexGuard
aGuard(m_aMutex
);
874 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
875 checkColumnIndex(column
);
877 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateDate", *this);
880 void SAL_CALL
OResultSet::updateTime(sal_Int32 column
, const Time
& /* x */)
882 MutexGuard
aGuard(m_aMutex
);
883 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
884 checkColumnIndex(column
);
886 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateTime", *this);
889 void SAL_CALL
OResultSet::updateTimestamp(sal_Int32 column
, const DateTime
& /* x */)
891 MutexGuard
aGuard(m_aMutex
);
892 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
893 checkColumnIndex(column
);
895 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateTimestamp", *this);
898 void SAL_CALL
OResultSet::updateBinaryStream(sal_Int32 column
,
899 const uno::Reference
<XInputStream
>& /* x */,
900 sal_Int32
/* length */)
902 MutexGuard
aGuard(m_aMutex
);
903 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
904 checkColumnIndex(column
);
906 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateBinaryStream",
910 void SAL_CALL
OResultSet::updateCharacterStream(sal_Int32 column
,
911 const uno::Reference
<XInputStream
>& /* x */,
912 sal_Int32
/* length */)
914 MutexGuard
aGuard(m_aMutex
);
915 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
916 checkColumnIndex(column
);
918 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateCharacterStream",
922 void SAL_CALL
OResultSet::refreshRow()
924 MutexGuard
aGuard(m_aMutex
);
925 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
926 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::refreshRow", *this);
929 void SAL_CALL
OResultSet::updateObject(sal_Int32 column
, const Any
& /* x */)
931 MutexGuard
aGuard(m_aMutex
);
932 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
933 checkColumnIndex(column
);
935 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateObject", *this);
938 void SAL_CALL
OResultSet::updateNumericObject(sal_Int32 column
, const Any
& /* x */,
939 sal_Int32
/* scale */)
941 MutexGuard
aGuard(m_aMutex
);
942 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
943 checkColumnIndex(column
);
945 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateNumericObject",
950 Any SAL_CALL
OResultSet::getBookmark()
952 MutexGuard
aGuard(m_aMutex
);
953 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
955 // if you don't want to support bookmark you must remove the XRowLocate interface
956 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::getBookmark", *this);
961 sal_Bool SAL_CALL
OResultSet::moveToBookmark(const Any
& /* bookmark */)
963 MutexGuard
aGuard(m_aMutex
);
964 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
969 sal_Bool SAL_CALL
OResultSet::moveRelativeToBookmark(const Any
& /* bookmark */,
970 sal_Int32
/* rows */)
972 MutexGuard
aGuard(m_aMutex
);
973 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
975 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::moveRelativeToBookmark",
980 sal_Int32 SAL_CALL
OResultSet::compareBookmarks(const Any
& /* n1 */, const Any
& /* n2 */)
982 MutexGuard
aGuard(m_aMutex
);
983 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
985 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::compareBookmarks", *this);
987 return CompareBookmark::NOT_EQUAL
;
990 sal_Bool SAL_CALL
OResultSet::hasOrderedBookmarks() { return false; }
992 sal_Int32 SAL_CALL
OResultSet::hashBookmark(const Any
& /* bookmark */)
994 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::hashBookmark", *this);
999 uno::Sequence
<sal_Int32
> SAL_CALL
OResultSet::deleteRows(const uno::Sequence
<Any
>& /* rows */)
1001 MutexGuard
aGuard(m_aMutex
);
1002 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
1004 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::deleteRows", *this);
1005 return uno::Sequence
<sal_Int32
>();
1008 IPropertyArrayHelper
* OResultSet::createArrayHelper() const
1010 uno::Sequence
<Property
> aProps(5);
1011 Property
* pProperties
= aProps
.getArray();
1013 pProperties
[nPos
++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION
,
1014 cppu::UnoType
<sal_Int32
>::get(), 0);
1016 = Property("FetchSize", PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
1017 pProperties
[nPos
++] = Property("IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE
,
1018 cppu::UnoType
<bool>::get(), PropertyAttribute::READONLY
);
1019 pProperties
[nPos
++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY
,
1020 cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
1021 pProperties
[nPos
++] = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE
,
1022 cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
1024 return new OPropertyArrayHelper(aProps
);
1027 IPropertyArrayHelper
& OResultSet::getInfoHelper() { return *getArrayHelper(); }
1029 sal_Bool
OResultSet::convertFastPropertyValue(Any
& /* rConvertedValue */, Any
& /* rOldValue */,
1030 sal_Int32 nHandle
, const Any
& /* rValue */)
1034 case PROPERTY_ID_ISBOOKMARKABLE
:
1035 case PROPERTY_ID_CURSORNAME
:
1036 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1037 case PROPERTY_ID_RESULTSETTYPE
:
1038 throw css::lang::IllegalArgumentException();
1039 case PROPERTY_ID_FETCHDIRECTION
:
1040 case PROPERTY_ID_FETCHSIZE
:
1046 void OResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const Any
& /* rValue */)
1050 case PROPERTY_ID_ISBOOKMARKABLE
:
1051 case PROPERTY_ID_CURSORNAME
:
1052 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1053 case PROPERTY_ID_RESULTSETTYPE
:
1054 throw uno::Exception("cannot set prop " + OUString::number(nHandle
), nullptr);
1055 case PROPERTY_ID_FETCHDIRECTION
:
1057 case PROPERTY_ID_FETCHSIZE
:
1063 void OResultSet::getFastPropertyValue(Any
& _rValue
, sal_Int32 nHandle
) const
1067 case PROPERTY_ID_ISBOOKMARKABLE
:
1070 case PROPERTY_ID_CURSORNAME
:
1072 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1073 _rValue
<<= ResultSetConcurrency::READ_ONLY
;
1075 case PROPERTY_ID_RESULTSETTYPE
:
1076 _rValue
<<= ResultSetType::SCROLL_INSENSITIVE
;
1078 case PROPERTY_ID_FETCHDIRECTION
:
1079 _rValue
<<= FetchDirection::FORWARD
;
1081 case PROPERTY_ID_FETCHSIZE
:
1082 _rValue
<<= sal_Int32(50);
1089 void SAL_CALL
OResultSet::acquire() noexcept
{ OResultSet_BASE::acquire(); }
1091 void SAL_CALL
OResultSet::release() noexcept
{ OResultSet_BASE::release(); }
1093 css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
OResultSet::getPropertySetInfo()
1095 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1098 void OResultSet::checkColumnIndex(sal_Int32 index
)
1100 if (index
< 1 || index
> static_cast<int>(m_aFields
.size()))
1102 /* static object for efficiency or thread safety is a problem ? */
1103 throw SQLException("index out of range", *this, OUString(), 1, Any());
1107 void OResultSet::checkBordersAndEnsureFetched(sal_Int32 index
)
1109 ensureResultFetched();
1110 checkColumnIndex(index
);
1114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */