bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_resultset.cxx
blob7a11020ea8e0f8a12d02742c61f21f1e7a653e48
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
34 using namespace rtl;
36 using namespace connectivity::mysqlc;
37 using namespace cppu;
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;
50 namespace
52 // copied from string misc, it should be replaced when library is not an
53 // extension anymore
54 std::vector<OString> lcl_split(const OString& rStr, char cSeparator)
56 std::vector<OString> vec;
57 sal_Int32 idx = 0;
60 OString kw = rStr.getToken(0, cSeparator, idx);
61 kw = kw.trim();
62 if (!kw.isEmpty())
64 vec.push_back(kw);
66 } while (idx >= 0);
67 return vec;
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())
83 m_bWasNull = true;
84 return true;
86 m_bWasNull = false;
87 return false;
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))
111 , m_pResult(pResult)
112 , m_encoding(_encoding)
114 assert(m_pResult);
115 m_xMetaData = new OResultSetMetaData(rConn, m_pResult);
118 void OResultSet::ensureResultFetched()
120 if (m_pResult)
122 fetchResult();
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
132 // TODO ensure that
133 m_nRowCount = mysql_num_rows(m_pResult);
135 if (!m_aFields.empty())
136 return;
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);
166 if (errorNum)
167 mysqlc_sdbc_driver::throwSQLExceptionWithMsg(
168 mysql_error(m_pMysql), mysql_sqlstate(m_pMysql), errorNum, *this, m_encoding);
169 mysql_free_result(m_pResult);
170 m_pResult = nullptr;
173 void OResultSet::disposing()
175 OPropertySetHelper::disposing();
177 MutexGuard aGuard(m_aMutex);
179 if (m_pResult != nullptr)
181 mysql_free_result(m_pResult);
182 m_pResult = nullptr;
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);
195 return aRet;
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,
220 Any());
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))
229 return nullptr;
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",
242 *this);
243 return nullptr;
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))
252 return false;
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))
264 return 0;
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);
290 Date d;
292 if (checkNull(column))
293 return d;
295 OString dateStr = m_aRows[m_nRowPosition][column - 1];
297 OString dateString(dateStr);
298 OString token;
299 sal_Int32 nIndex = 0, i = 0;
302 token = dateString.getToken(0, '-', nIndex);
303 switch (i)
305 case 0:
306 d.Year = static_cast<sal_uInt16>(token.toUInt32());
307 break;
308 case 1:
309 d.Month = static_cast<sal_uInt16>(token.toUInt32());
310 break;
311 case 2:
312 d.Day = static_cast<sal_uInt16>(token.toUInt32());
313 break;
314 default:;
316 i++;
317 } while (nIndex >= 0);
318 return d;
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))
328 return 0.0;
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))
340 return 0.0f;
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))
352 return 0;
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))
372 return 0LL;
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);
382 return m_xMetaData;
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);
392 return nullptr;
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);
402 return nullptr;
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);
412 return nullptr;
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);
422 return nullptr;
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);
433 return Any();
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))
442 return 0;
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);
466 Time t;
467 if (checkNull(column))
468 return t;
470 OString sVal = m_aRows[m_nRowPosition][column - 1];
471 OString timeString{ sVal.getStr(), getDataLength(column) };
472 OString token;
473 sal_Int32 nIndex, i = 0;
475 nIndex = timeString.indexOf(' ') + 1;
478 token = timeString.getToken(0, ':', nIndex);
479 switch (i)
481 case 0:
482 t.Hours = static_cast<sal_uInt16>(token.toUInt32());
483 break;
484 case 1:
485 t.Minutes = static_cast<sal_uInt16>(token.toUInt32());
486 break;
487 case 2:
488 t.Seconds = static_cast<sal_uInt16>(token.toUInt32());
489 break;
491 i++;
492 } while (nIndex >= 0);
494 return t;
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))
504 return DateTime{};
506 OString sVal = m_aRows[m_nRowPosition][column - 1];
508 // YY-MM-DD HH:MM:SS
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());
518 DateTime dt;
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();
526 return dt;
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);
568 m_nRowPosition = -1;
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);
587 m_pResult = nullptr;
589 dispose();
592 sal_Bool SAL_CALL OResultSet::first()
594 MutexGuard aGuard(m_aMutex);
595 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
596 m_nRowPosition = 0;
598 return true;
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;
608 return true;
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;
621 if (nToGo < 0)
622 nToGo = 0;
624 m_nRowPosition = nToGo;
626 return true;
629 sal_Bool SAL_CALL OResultSet::relative(sal_Int32 row)
631 MutexGuard aGuard(m_aMutex);
632 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
633 ensureFieldInfoFetched();
635 if (row == 0)
636 return true;
638 sal_Int32 nToGo = m_nRowPosition + row;
639 if (nToGo >= m_nRowCount)
640 nToGo = m_nRowCount - 1;
641 if (nToGo < 0)
642 nToGo = 0;
644 m_nRowPosition = nToGo;
646 return true;
649 sal_Bool SAL_CALL OResultSet::previous()
651 MutexGuard aGuard(m_aMutex);
652 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
654 if (m_nRowPosition == 0)
656 m_nRowPosition--;
657 return false;
659 else if (m_nRowPosition < 0)
661 return false;
664 m_nRowPosition--;
665 return true;
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);
681 return false;
684 sal_Bool SAL_CALL OResultSet::rowInserted()
686 MutexGuard aGuard(m_aMutex);
687 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
689 return false;
692 sal_Bool SAL_CALL OResultSet::rowUpdated()
694 MutexGuard aGuard(m_aMutex);
695 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
697 return false;
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
706 return false;
707 if (m_nRowPosition + 1 == m_nRowCount) // last
709 // return false but take it to afterlast anyway
710 ++m_nRowPosition;
711 return false;
713 ++m_nRowPosition;
714 return true;
717 sal_Bool SAL_CALL OResultSet::wasNull()
719 MutexGuard aGuard(m_aMutex);
720 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
722 return m_bWasNull;
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);
786 checkRowIndex();
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);
795 checkRowIndex();
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);
804 checkRowIndex();
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);
813 checkRowIndex();
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);
822 checkRowIndex();
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);
831 checkRowIndex();
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);
840 checkRowIndex();
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);
849 checkRowIndex();
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);
858 checkRowIndex();
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);
867 checkRowIndex();
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);
876 checkRowIndex();
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);
885 checkRowIndex();
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);
894 checkRowIndex();
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);
905 checkRowIndex();
906 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateBinaryStream",
907 *this);
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);
917 checkRowIndex();
918 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateCharacterStream",
919 *this);
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);
934 checkRowIndex();
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);
944 checkRowIndex();
945 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSet::updateNumericObject",
946 *this);
949 // XRowLocate
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);
958 return Any();
961 sal_Bool SAL_CALL OResultSet::moveToBookmark(const Any& /* bookmark */)
963 MutexGuard aGuard(m_aMutex);
964 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
966 return false;
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",
976 *this);
977 return false;
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);
995 return 0;
998 // XDeleteRows
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();
1012 sal_Int32 nPos = 0;
1013 pProperties[nPos++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION,
1014 cppu::UnoType<sal_Int32>::get(), 0);
1015 pProperties[nPos++]
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 */)
1032 switch (nHandle)
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:
1041 default:;
1043 return false;
1046 void OResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& /* rValue */)
1048 switch (nHandle)
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:
1056 break;
1057 case PROPERTY_ID_FETCHSIZE:
1058 break;
1059 default:;
1063 void OResultSet::getFastPropertyValue(Any& _rValue, sal_Int32 nHandle) const
1065 switch (nHandle)
1067 case PROPERTY_ID_ISBOOKMARKABLE:
1068 _rValue <<= false;
1069 break;
1070 case PROPERTY_ID_CURSORNAME:
1071 break;
1072 case PROPERTY_ID_RESULTSETCONCURRENCY:
1073 _rValue <<= ResultSetConcurrency::READ_ONLY;
1074 break;
1075 case PROPERTY_ID_RESULTSETTYPE:
1076 _rValue <<= ResultSetType::SCROLL_INSENSITIVE;
1077 break;
1078 case PROPERTY_ID_FETCHDIRECTION:
1079 _rValue <<= FetchDirection::FORWARD;
1080 break;
1081 case PROPERTY_ID_FETCHSIZE:
1082 _rValue <<= sal_Int32(50);
1083 break;
1085 default:;
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);
1111 checkRowIndex();
1114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */