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_prepared_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 <sal/log.hxx>
38 using namespace connectivity::mysqlc
;
39 using namespace connectivity
;
41 using namespace com::sun::star
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::beans
;
44 using namespace com::sun::star::sdbc
;
45 using namespace com::sun::star::sdbcx
;
46 using namespace com::sun::star::container
;
47 using namespace com::sun::star::io
;
48 using namespace com::sun::star::util
;
49 using namespace ::comphelper
;
50 using ::osl::MutexGuard
;
56 std::type_index
getTypeFromMysqlType(enum_field_types type
)
61 return std::type_index(typeid(sal_Int8
));
62 case MYSQL_TYPE_SHORT
:
63 return std::type_index(typeid(sal_Int16
));
65 case MYSQL_TYPE_INT24
:
66 return std::type_index(typeid(sal_Int32
));
67 case MYSQL_TYPE_LONGLONG
:
68 return std::type_index(typeid(sal_Int64
));
69 case MYSQL_TYPE_FLOAT
:
70 return std::type_index(typeid(float));
71 case MYSQL_TYPE_DOUBLE
:
72 return std::type_index(typeid(double));
73 case MYSQL_TYPE_TIMESTAMP
:
74 case MYSQL_TYPE_DATETIME
:
75 return std::type_index(typeid(DateTime
));
77 return std::type_index(typeid(Date
));
79 return std::type_index(typeid(Time
));
80 case MYSQL_TYPE_STRING
:
81 case MYSQL_TYPE_VAR_STRING
:
82 case MYSQL_TYPE_DECIMAL
:
83 case MYSQL_TYPE_NEWDECIMAL
:
84 return std::type_index(typeid(OUString
));
90 case MYSQL_TYPE_GEOMETRY
:
93 return std::type_index(typeid(nullptr));
98 bool OPreparedResultSet::fetchResult()
100 // allocate array if it does not exist
101 if (m_aData
== nullptr)
103 m_aData
.reset(new MYSQL_BIND
[m_nColumnCount
]);
104 memset(m_aData
.get(), 0, m_nColumnCount
* sizeof(MYSQL_BIND
));
105 m_aMetaData
.reset(new BindMetaData
[m_nColumnCount
]);
107 for (sal_Int32 i
= 0; i
< m_nColumnCount
; ++i
)
109 m_aMetaData
[i
].is_null
= false;
110 m_aMetaData
[i
].length
= 0l;
111 m_aMetaData
[i
].error
= false;
113 m_aData
[i
].is_null
= &m_aMetaData
[i
].is_null
;
114 m_aData
[i
].buffer_length
= m_aFields
[i
].type
== MYSQL_TYPE_BLOB
? 0 : m_aFields
[i
].length
;
115 m_aData
[i
].length
= &m_aMetaData
[i
].length
;
116 m_aData
[i
].error
= &m_aMetaData
[i
].error
;
117 m_aData
[i
].buffer
= nullptr;
118 m_aData
[i
].buffer_type
= m_aFields
[i
].type
;
120 // allocates memory, if it is a fixed size type. If not then nullptr
121 mysqlc_sdbc_driver::allocateSqlVar(&m_aData
[i
].buffer
, m_aData
[i
].buffer_type
,
122 m_aFields
[i
].length
);
124 mysql_stmt_bind_result(m_pStmt
, m_aData
.get());
125 int failure
= mysql_stmt_fetch(m_pStmt
);
127 for (sal_Int32 i
= 0; i
< m_nColumnCount
; ++i
)
129 if (*m_aData
[i
].error
)
131 // expected if we have a BLOB, as buffer_length is set to 0. We want to
132 // fetch it piece by piece
133 // see https://bugs.mysql.com/file.php?id=12361&bug_id=33086
134 if (m_aData
[i
].buffer
== nullptr)
136 m_aData
[i
].buffer_length
= *m_aData
[i
].length
;
137 m_aData
[i
].buffer
= malloc(*m_aData
[i
].length
);
138 mysql_stmt_fetch_column(m_pStmt
, &m_aData
[i
], i
, 0);
145 MYSQL
* pMysql
= m_rConnection
.getMysqlConnection();
146 mysqlc_sdbc_driver::throwSQLExceptionWithMsg(mysql_error(pMysql
), mysql_sqlstate(pMysql
),
147 mysql_errno(pMysql
), *this, m_encoding
);
149 else if (failure
== MYSQL_NO_DATA
)
154 OUString SAL_CALL
OPreparedResultSet::getImplementationName()
156 return "com.sun.star.sdbcx.mysqlc.ResultSet";
159 uno::Sequence
<OUString
> SAL_CALL
OPreparedResultSet::getSupportedServiceNames()
161 return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
164 sal_Bool SAL_CALL
OPreparedResultSet::supportsService(const OUString
& _rServiceName
)
166 return cppu::supportsService(this, _rServiceName
);
168 OPreparedResultSet::OPreparedResultSet(OConnection
& rConn
, OPreparedStatement
* pStmt
,
170 : OPreparedResultSet_BASE(m_aMutex
)
171 , OPropertySetHelper(OPreparedResultSet_BASE::rBHelper
)
172 , m_rConnection(rConn
)
173 , m_aStatement(static_cast<OWeakObject
*>(pStmt
))
175 , m_encoding(rConn
.getConnectionEncoding())
176 , m_nColumnCount(mysql_stmt_field_count(pMyStmt
))
178 m_pResult
= mysql_stmt_result_metadata(m_pStmt
);
179 if (m_pResult
!= nullptr)
180 mysql_stmt_store_result(m_pStmt
);
181 m_aFields
= mysql_fetch_fields(m_pResult
);
182 m_nRowCount
= mysql_stmt_num_rows(pMyStmt
);
185 void OPreparedResultSet::disposing()
187 OPropertySetHelper::disposing();
189 MutexGuard
aGuard(m_aMutex
);
191 m_aStatement
= nullptr;
192 m_xMetaData
= nullptr;
195 Any SAL_CALL
OPreparedResultSet::queryInterface(const Type
& rType
)
197 Any aRet
= OPropertySetHelper::queryInterface(rType
);
198 if (!aRet
.hasValue())
200 aRet
= OPreparedResultSet_BASE::queryInterface(rType
);
205 uno::Sequence
<Type
> SAL_CALL
OPreparedResultSet::getTypes()
207 OTypeCollection
aTypes(cppu::UnoType
<XMultiPropertySet
>::get(),
208 cppu::UnoType
<XFastPropertySet
>::get(),
209 cppu::UnoType
<XPropertySet
>::get());
211 return concatSequences(aTypes
.getTypes(), OPreparedResultSet_BASE::getTypes());
214 sal_Int32 SAL_CALL
OPreparedResultSet::findColumn(const OUString
& columnName
)
216 MutexGuard
aGuard(m_aMutex
);
217 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
219 MYSQL_FIELD
* pFields
= mysql_fetch_fields(m_pResult
);
220 for (sal_Int32 i
= 0; i
< m_nColumnCount
; ++i
)
222 if (columnName
.equalsIgnoreAsciiCaseAscii(pFields
[i
].name
))
223 return i
+ 1; // sdbc indexes from 1
226 throw SQLException("The column name '" + columnName
+ "' is not valid.", *this, "42S22", 0,
230 template <typename T
> T
OPreparedResultSet::safelyRetrieveValue(sal_Int32 nColumnIndex
)
232 MutexGuard
aGuard(m_aMutex
);
233 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
234 checkColumnIndex(nColumnIndex
);
235 if (*m_aData
[nColumnIndex
- 1].is_null
)
242 return retrieveValue
<T
>(nColumnIndex
);
245 template <typename T
> T
OPreparedResultSet::retrieveValue(sal_Int32 nColumnIndex
)
247 if (getTypeFromMysqlType(m_aFields
[nColumnIndex
- 1].type
) == std::type_index(typeid(T
)))
248 return *static_cast<T
*>(m_aData
[nColumnIndex
- 1].buffer
);
250 return getRowSetValue(nColumnIndex
);
253 template <> uno::Sequence
<sal_Int8
> OPreparedResultSet::retrieveValue(sal_Int32 column
)
255 // TODO make conversion possible
256 return uno::Sequence
<sal_Int8
>(static_cast<sal_Int8
const*>(m_aData
[column
- 1].buffer
),
257 *m_aData
[column
- 1].length
);
260 template <> Date
OPreparedResultSet::retrieveValue(sal_Int32 column
)
262 if (getTypeFromMysqlType(m_aFields
[column
- 1].type
) != std::type_index(typeid(Date
)))
263 return getRowSetValue(column
);
264 const MYSQL_TIME
* pTime
= static_cast<MYSQL_TIME
*>(m_aData
[column
- 1].buffer
);
267 d
.Year
= pTime
->year
;
268 d
.Month
= pTime
->month
;
273 template <> Time
OPreparedResultSet::retrieveValue(sal_Int32 column
)
275 if (getTypeFromMysqlType(m_aFields
[column
- 1].type
) != std::type_index(typeid(Time
)))
276 return getRowSetValue(column
);
277 const MYSQL_TIME
* pTime
= static_cast<MYSQL_TIME
*>(m_aData
[column
- 1].buffer
);
280 t
.Hours
= pTime
->hour
;
281 t
.Minutes
= pTime
->minute
;
282 t
.Seconds
= pTime
->second
;
286 template <> DateTime
OPreparedResultSet::retrieveValue(sal_Int32 column
)
288 if (getTypeFromMysqlType(m_aFields
[column
- 1].type
) != std::type_index(typeid(DateTime
)))
289 return getRowSetValue(column
);
290 const MYSQL_TIME
* pTime
= static_cast<MYSQL_TIME
*>(m_aData
[column
- 1].buffer
);
293 t
.Year
= pTime
->year
;
294 t
.Month
= pTime
->month
;
296 t
.Hours
= pTime
->hour
;
297 t
.Minutes
= pTime
->minute
;
298 t
.Seconds
= pTime
->second
;
302 template <> OUString
OPreparedResultSet::retrieveValue(sal_Int32 column
)
304 // redirect call to the appropriate method if needed
305 // BLOB can be simply read out as string
306 if (getTypeFromMysqlType(m_aFields
[column
- 1].type
) != std::type_index(typeid(OUString
))
307 && m_aFields
[column
- 1].type
!= MYSQL_TYPE_BLOB
)
308 return getRowSetValue(column
);
309 const char* sStr
= static_cast<const char*>(m_aData
[column
- 1].buffer
);
311 return OUString(sStr
, *m_aData
[column
- 1].length
, m_encoding
);
314 ORowSetValue
OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex
)
316 switch (m_aFields
[nColumnIndex
- 1].type
)
318 case MYSQL_TYPE_TINY
:
319 return getByte(nColumnIndex
);
320 case MYSQL_TYPE_SHORT
:
321 return getShort(nColumnIndex
);
322 case MYSQL_TYPE_LONG
:
323 case MYSQL_TYPE_INT24
:
324 return getInt(nColumnIndex
);
325 case MYSQL_TYPE_LONGLONG
:
326 return getLong(nColumnIndex
);
327 case MYSQL_TYPE_FLOAT
:
328 return getFloat(nColumnIndex
);
329 case MYSQL_TYPE_DOUBLE
:
330 return getDouble(nColumnIndex
);
331 case MYSQL_TYPE_TIMESTAMP
:
332 case MYSQL_TYPE_DATETIME
:
333 return getTimestamp(nColumnIndex
);
334 case MYSQL_TYPE_DATE
:
335 return getDate(nColumnIndex
);
336 case MYSQL_TYPE_TIME
:
337 return getTime(nColumnIndex
);
338 case MYSQL_TYPE_STRING
:
339 case MYSQL_TYPE_VAR_STRING
:
340 case MYSQL_TYPE_DECIMAL
:
341 case MYSQL_TYPE_NEWDECIMAL
:
342 return getString(nColumnIndex
);
343 case MYSQL_TYPE_BLOB
:
344 throw SQLException("Column with type BLOB cannot be converted", *this, "22000", 1,
347 SAL_WARN("connectivity.mysqlc", "OPreparedResultSet::getRowSetValue: unknown type: "
348 << m_aFields
[nColumnIndex
- 1].type
);
349 throw SQLException("Unknown column type when fetching result", *this, "22000", 1,
354 uno::Reference
<XInputStream
> SAL_CALL
OPreparedResultSet::getBinaryStream(sal_Int32
/*column*/)
356 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBinaryStream",
361 uno::Reference
<XInputStream
> SAL_CALL
OPreparedResultSet::getCharacterStream(sal_Int32
/*column*/)
363 mysqlc_sdbc_driver::throwFeatureNotImplementedException(
364 "OPreparedResultSet::getCharacterStream", *this);
368 sal_Bool SAL_CALL
OPreparedResultSet::getBoolean(sal_Int32 column
)
370 return safelyRetrieveValue
<bool>(column
);
373 sal_Int8 SAL_CALL
OPreparedResultSet::getByte(sal_Int32 column
)
375 return safelyRetrieveValue
<sal_Int8
>(column
);
378 uno::Sequence
<sal_Int8
> SAL_CALL
OPreparedResultSet::getBytes(sal_Int32 column
)
380 return safelyRetrieveValue
<uno::Sequence
<sal_Int8
>>(column
);
383 Date SAL_CALL
OPreparedResultSet::getDate(sal_Int32 column
)
385 return safelyRetrieveValue
<Date
>(column
);
388 double SAL_CALL
OPreparedResultSet::getDouble(sal_Int32 column
)
390 return safelyRetrieveValue
<double>(column
);
393 float SAL_CALL
OPreparedResultSet::getFloat(sal_Int32 column
)
395 return safelyRetrieveValue
<float>(column
);
398 sal_Int32 SAL_CALL
OPreparedResultSet::getInt(sal_Int32 column
)
400 return safelyRetrieveValue
<sal_Int32
>(column
);
403 sal_Int32 SAL_CALL
OPreparedResultSet::getRow()
405 MutexGuard
aGuard(m_aMutex
);
406 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
408 return static_cast<sal_Int32
>(mysql_field_tell(m_pResult
));
411 sal_Int64 SAL_CALL
OPreparedResultSet::getLong(sal_Int32 column
)
413 return safelyRetrieveValue
<sal_Int64
>(column
);
416 uno::Reference
<XResultSetMetaData
> SAL_CALL
OPreparedResultSet::getMetaData()
418 MutexGuard
aGuard(m_aMutex
);
419 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
420 if (!m_xMetaData
.is())
422 m_xMetaData
= new OResultSetMetaData(m_rConnection
, m_pResult
);
427 uno::Reference
<XArray
> SAL_CALL
OPreparedResultSet::getArray(sal_Int32 column
)
429 MutexGuard
aGuard(m_aMutex
);
430 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
431 checkColumnIndex(column
);
433 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getArray", *this);
437 uno::Reference
<XClob
> SAL_CALL
OPreparedResultSet::getClob(sal_Int32 column
)
439 MutexGuard
aGuard(m_aMutex
);
440 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
441 checkColumnIndex(column
);
443 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getClob", *this);
447 uno::Reference
<XBlob
> SAL_CALL
OPreparedResultSet::getBlob(sal_Int32 column
)
449 MutexGuard
aGuard(m_aMutex
);
450 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
451 checkColumnIndex(column
);
453 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBlob", *this);
457 uno::Reference
<XRef
> SAL_CALL
OPreparedResultSet::getRef(sal_Int32 column
)
459 MutexGuard
aGuard(m_aMutex
);
460 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
461 checkColumnIndex(column
);
463 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getRef", *this);
467 Any SAL_CALL
OPreparedResultSet::getObject(sal_Int32 column
,
468 const uno::Reference
<XNameAccess
>& /* typeMap */)
470 MutexGuard
aGuard(m_aMutex
);
471 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
472 checkColumnIndex(column
);
476 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getObject", *this);
480 sal_Int16 SAL_CALL
OPreparedResultSet::getShort(sal_Int32 column
)
482 return safelyRetrieveValue
<sal_Int16
>(column
);
485 OUString SAL_CALL
OPreparedResultSet::getString(sal_Int32 column
)
487 return safelyRetrieveValue
<OUString
>(column
);
490 Time SAL_CALL
OPreparedResultSet::getTime(sal_Int32 column
)
492 return safelyRetrieveValue
<Time
>(column
);
495 DateTime SAL_CALL
OPreparedResultSet::getTimestamp(sal_Int32 column
)
497 return safelyRetrieveValue
<DateTime
>(column
);
500 sal_Bool SAL_CALL
OPreparedResultSet::isBeforeFirst()
502 MutexGuard
aGuard(m_aMutex
);
503 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
505 return m_nCurrentRow
== 0;
508 sal_Bool SAL_CALL
OPreparedResultSet::isAfterLast()
510 MutexGuard
aGuard(m_aMutex
);
511 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
513 return m_nCurrentRow
> m_nRowCount
;
516 sal_Bool SAL_CALL
OPreparedResultSet::isFirst()
518 MutexGuard
aGuard(m_aMutex
);
519 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
521 return m_nCurrentRow
== 1 && !isAfterLast();
524 sal_Bool SAL_CALL
OPreparedResultSet::isLast()
526 MutexGuard
aGuard(m_aMutex
);
527 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
529 return m_nCurrentRow
== m_nRowCount
;
532 void SAL_CALL
OPreparedResultSet::beforeFirst()
534 MutexGuard
aGuard(m_aMutex
);
535 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
536 mysql_stmt_data_seek(m_pStmt
, 0);
542 void SAL_CALL
OPreparedResultSet::afterLast()
544 MutexGuard
aGuard(m_aMutex
);
545 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
547 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::afterLast", *this);
550 void SAL_CALL
OPreparedResultSet::close()
552 MutexGuard
aGuard(m_aMutex
);
553 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
559 mysql_free_result(m_pResult
);
560 mysql_stmt_free_result(m_pStmt
);
564 sal_Bool SAL_CALL
OPreparedResultSet::first()
566 MutexGuard
aGuard(m_aMutex
);
567 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
569 mysql_stmt_data_seek(m_pStmt
, 0);
576 sal_Bool SAL_CALL
OPreparedResultSet::last()
578 MutexGuard
aGuard(m_aMutex
);
579 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
581 mysql_stmt_data_seek(m_pStmt
, m_nRowCount
- 1);
587 sal_Bool SAL_CALL
OPreparedResultSet::absolute(sal_Int32 row
)
589 MutexGuard
aGuard(m_aMutex
);
590 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
592 sal_Int32 nToGo
= row
< 0 ? m_nRowCount
- row
: row
- 1;
594 if (nToGo
>= m_nRowCount
)
595 nToGo
= m_nRowCount
- 1;
599 mysql_stmt_data_seek(m_pStmt
, nToGo
);
605 sal_Bool SAL_CALL
OPreparedResultSet::relative(sal_Int32 row
)
607 MutexGuard
aGuard(m_aMutex
);
608 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
613 sal_Int32 nToGo
= m_nCurrentRow
+ row
;
614 if (nToGo
>= m_nRowCount
)
615 nToGo
= m_nRowCount
- 1;
619 mysql_stmt_data_seek(m_pStmt
, nToGo
);
621 m_nCurrentRow
+= row
;
626 sal_Bool SAL_CALL
OPreparedResultSet::previous()
628 MutexGuard
aGuard(m_aMutex
);
629 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
631 if (m_nCurrentRow
<= 1)
634 mysql_stmt_data_seek(m_pStmt
, m_nCurrentRow
- 2);
640 uno::Reference
<uno::XInterface
> SAL_CALL
OPreparedResultSet::getStatement()
642 MutexGuard
aGuard(m_aMutex
);
643 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
645 return m_aStatement
.get();
648 sal_Bool SAL_CALL
OPreparedResultSet::rowDeleted()
650 MutexGuard
aGuard(m_aMutex
);
651 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
656 sal_Bool SAL_CALL
OPreparedResultSet::rowInserted()
658 MutexGuard
aGuard(m_aMutex
);
659 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
664 sal_Bool SAL_CALL
OPreparedResultSet::rowUpdated()
666 MutexGuard
aGuard(m_aMutex
);
667 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
672 sal_Bool SAL_CALL
OPreparedResultSet::next()
674 MutexGuard
aGuard(m_aMutex
);
675 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
676 bool hasData
= fetchResult();
678 // current field cannot be asked as a number. We have to keep track it
685 sal_Bool SAL_CALL
OPreparedResultSet::wasNull()
687 MutexGuard
aGuard(m_aMutex
);
688 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
693 void SAL_CALL
OPreparedResultSet::cancel()
695 MutexGuard
aGuard(m_aMutex
);
696 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
699 void SAL_CALL
OPreparedResultSet::clearWarnings() {}
701 Any SAL_CALL
OPreparedResultSet::getWarnings() { return Any(); }
703 void SAL_CALL
OPreparedResultSet::insertRow()
705 MutexGuard
aGuard(m_aMutex
);
706 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
707 // you only have to implement this if you want to insert new rows
708 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::insertRow", *this);
711 void SAL_CALL
OPreparedResultSet::updateRow()
713 MutexGuard
aGuard(m_aMutex
);
714 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
716 // only when you allow updates
717 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateRow", *this);
720 void SAL_CALL
OPreparedResultSet::deleteRow()
722 MutexGuard
aGuard(m_aMutex
);
723 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
724 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::deleteRow", *this);
727 void SAL_CALL
OPreparedResultSet::cancelRowUpdates()
729 MutexGuard
aGuard(m_aMutex
);
730 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
731 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::cancelRowUpdates",
735 void SAL_CALL
OPreparedResultSet::moveToInsertRow()
737 MutexGuard
aGuard(m_aMutex
);
738 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
740 // only when you allow insert's
741 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::moveToInsertRow",
745 void SAL_CALL
OPreparedResultSet::moveToCurrentRow()
747 MutexGuard
aGuard(m_aMutex
);
748 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
751 void SAL_CALL
OPreparedResultSet::updateNull(sal_Int32 column
)
753 MutexGuard
aGuard(m_aMutex
);
754 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
755 checkColumnIndex(column
);
756 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateNull",
760 void SAL_CALL
OPreparedResultSet::updateBoolean(sal_Int32 column
, sal_Bool
/* x */)
762 MutexGuard
aGuard(m_aMutex
);
763 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
764 checkColumnIndex(column
);
765 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateBoolean",
769 void SAL_CALL
OPreparedResultSet::updateByte(sal_Int32 column
, sal_Int8
/* x */)
771 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
772 MutexGuard
aGuard(m_aMutex
);
773 checkColumnIndex(column
);
774 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateByte",
778 void SAL_CALL
OPreparedResultSet::updateShort(sal_Int32 column
, sal_Int16
/* x */)
780 MutexGuard
aGuard(m_aMutex
);
781 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
782 checkColumnIndex(column
);
783 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateShort",
787 void SAL_CALL
OPreparedResultSet::updateInt(sal_Int32 column
, sal_Int32
/* x */)
789 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
790 MutexGuard
aGuard(m_aMutex
);
791 checkColumnIndex(column
);
792 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateInt", *this);
795 void SAL_CALL
OPreparedResultSet::updateLong(sal_Int32 column
, sal_Int64
/* x */)
797 MutexGuard
aGuard(m_aMutex
);
798 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
799 checkColumnIndex(column
);
800 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateLong",
804 void SAL_CALL
OPreparedResultSet::updateFloat(sal_Int32 column
, float /* x */)
806 MutexGuard
aGuard(m_aMutex
);
807 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
808 checkColumnIndex(column
);
809 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateFloat",
813 void SAL_CALL
OPreparedResultSet::updateDouble(sal_Int32 column
, double /* x */)
815 MutexGuard
aGuard(m_aMutex
);
816 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
817 checkColumnIndex(column
);
818 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateDouble",
822 void SAL_CALL
OPreparedResultSet::updateString(sal_Int32 column
, const OUString
& /* x */)
824 MutexGuard
aGuard(m_aMutex
);
825 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
826 checkColumnIndex(column
);
827 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateString",
831 void SAL_CALL
OPreparedResultSet::updateBytes(sal_Int32 column
,
832 const uno::Sequence
<sal_Int8
>& /* x */)
834 MutexGuard
aGuard(m_aMutex
);
835 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
836 checkColumnIndex(column
);
837 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateBytes",
841 void SAL_CALL
OPreparedResultSet::updateDate(sal_Int32 column
, const Date
& /* x */)
843 MutexGuard
aGuard(m_aMutex
);
844 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
845 checkColumnIndex(column
);
846 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateDate",
850 void SAL_CALL
OPreparedResultSet::updateTime(sal_Int32 column
, const Time
& /* x */)
852 MutexGuard
aGuard(m_aMutex
);
853 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
854 checkColumnIndex(column
);
855 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateTime",
859 void SAL_CALL
OPreparedResultSet::updateTimestamp(sal_Int32 column
, const DateTime
& /* x */)
861 MutexGuard
aGuard(m_aMutex
);
862 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
863 checkColumnIndex(column
);
864 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateTimestamp",
868 void SAL_CALL
OPreparedResultSet::updateBinaryStream(sal_Int32 column
,
869 const uno::Reference
<XInputStream
>& /* x */,
870 sal_Int32
/* length */)
872 MutexGuard
aGuard(m_aMutex
);
873 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
874 checkColumnIndex(column
);
875 mysqlc_sdbc_driver::throwFeatureNotImplementedException(
876 "OPreparedResultSet::updateBinaryStream", *this);
879 void SAL_CALL
OPreparedResultSet::updateCharacterStream(sal_Int32 column
,
880 const uno::Reference
<XInputStream
>& /* x */,
881 sal_Int32
/* length */)
883 MutexGuard
aGuard(m_aMutex
);
884 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
885 checkColumnIndex(column
);
886 mysqlc_sdbc_driver::throwFeatureNotImplementedException(
887 "OPreparedResultSet::updateCharacterStream", *this);
890 void SAL_CALL
OPreparedResultSet::refreshRow()
892 MutexGuard
aGuard(m_aMutex
);
893 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
894 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::refreshRow",
898 void SAL_CALL
OPreparedResultSet::updateObject(sal_Int32 column
, const Any
& /* x */)
900 MutexGuard
aGuard(m_aMutex
);
901 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
902 checkColumnIndex(column
);
903 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::updateObject",
907 void SAL_CALL
OPreparedResultSet::updateNumericObject(sal_Int32 column
, const Any
& /* x */,
908 sal_Int32
/* scale */)
910 MutexGuard
aGuard(m_aMutex
);
911 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
912 checkColumnIndex(column
);
913 mysqlc_sdbc_driver::throwFeatureNotImplementedException(
914 "OPreparedResultSet::updateNumericObject", *this);
918 Any SAL_CALL
OPreparedResultSet::getBookmark()
920 MutexGuard
aGuard(m_aMutex
);
921 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
923 // if you don't want to support bookmark you must remove the XRowLocate interface
924 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::getBookmark",
930 sal_Bool SAL_CALL
OPreparedResultSet::moveToBookmark(const Any
& /* bookmark */)
932 MutexGuard
aGuard(m_aMutex
);
933 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
938 sal_Bool SAL_CALL
OPreparedResultSet::moveRelativeToBookmark(const Any
& /* bookmark */,
939 sal_Int32
/* rows */)
941 MutexGuard
aGuard(m_aMutex
);
942 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
944 mysqlc_sdbc_driver::throwFeatureNotImplementedException(
945 "OPreparedResultSet::moveRelativeToBookmark", *this);
949 sal_Int32 SAL_CALL
OPreparedResultSet::compareBookmarks(const Any
& /* n1 */, const Any
& /* n2 */)
951 MutexGuard
aGuard(m_aMutex
);
952 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
954 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::compareBookmarks",
957 return CompareBookmark::NOT_EQUAL
;
960 sal_Bool SAL_CALL
OPreparedResultSet::hasOrderedBookmarks() { return false; }
962 sal_Int32 SAL_CALL
OPreparedResultSet::hashBookmark(const Any
& /* bookmark */)
964 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::hashBookmark",
970 uno::Sequence
<sal_Int32
>
971 SAL_CALL
OPreparedResultSet::deleteRows(const uno::Sequence
<Any
>& /* rows */)
973 MutexGuard
aGuard(m_aMutex
);
974 checkDisposed(OPreparedResultSet_BASE::rBHelper
.bDisposed
);
976 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedResultSet::deleteRows",
978 return uno::Sequence
<sal_Int32
>();
981 IPropertyArrayHelper
* OPreparedResultSet::createArrayHelper() const
983 uno::Sequence
<Property
> aProps(5);
984 Property
* pProperties
= aProps
.getArray();
986 pProperties
[nPos
++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION
,
987 cppu::UnoType
<sal_Int32
>::get(), 0);
989 = Property("FetchSize", PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
990 pProperties
[nPos
++] = Property("IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE
,
991 cppu::UnoType
<bool>::get(), PropertyAttribute::READONLY
);
992 pProperties
[nPos
++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY
,
993 cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
994 pProperties
[nPos
++] = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE
,
995 cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
997 return new OPropertyArrayHelper(aProps
);
1000 IPropertyArrayHelper
& OPreparedResultSet::getInfoHelper() { return *getArrayHelper(); }
1002 sal_Bool
OPreparedResultSet::convertFastPropertyValue(Any
& /* rConvertedValue */,
1003 Any
& /* rOldValue */, sal_Int32 nHandle
,
1004 const Any
& /* rValue */)
1008 case PROPERTY_ID_ISBOOKMARKABLE
:
1009 case PROPERTY_ID_CURSORNAME
:
1010 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1011 case PROPERTY_ID_RESULTSETTYPE
:
1012 throw css::lang::IllegalArgumentException();
1013 case PROPERTY_ID_FETCHDIRECTION
:
1014 case PROPERTY_ID_FETCHSIZE
:
1020 void OPreparedResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,
1021 const Any
& /* rValue */)
1025 case PROPERTY_ID_ISBOOKMARKABLE
:
1026 case PROPERTY_ID_CURSORNAME
:
1027 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1028 case PROPERTY_ID_RESULTSETTYPE
:
1029 throw uno::Exception("cannot set prop " + OUString::number(nHandle
), nullptr);
1030 case PROPERTY_ID_FETCHDIRECTION
:
1032 case PROPERTY_ID_FETCHSIZE
:
1038 void OPreparedResultSet::getFastPropertyValue(Any
& _rValue
, sal_Int32 nHandle
) const
1042 case PROPERTY_ID_ISBOOKMARKABLE
:
1045 case PROPERTY_ID_CURSORNAME
:
1047 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1048 _rValue
<<= ResultSetConcurrency::READ_ONLY
;
1050 case PROPERTY_ID_RESULTSETTYPE
:
1051 _rValue
<<= ResultSetType::SCROLL_INSENSITIVE
;
1053 case PROPERTY_ID_FETCHDIRECTION
:
1054 _rValue
<<= FetchDirection::FORWARD
;
1056 case PROPERTY_ID_FETCHSIZE
:
1057 _rValue
<<= sal_Int32(50);
1064 void SAL_CALL
OPreparedResultSet::acquire() noexcept
{ OPreparedResultSet_BASE::acquire(); }
1066 void SAL_CALL
OPreparedResultSet::release() noexcept
{ OPreparedResultSet_BASE::release(); }
1068 css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
OPreparedResultSet::getPropertySetInfo()
1070 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1073 void OPreparedResultSet::checkColumnIndex(sal_Int32 index
)
1076 throw SQLException("Cursor out of range", *this, "HY109", 1, Any());
1077 if (index
< 1 || index
> static_cast<int>(m_nColumnCount
))
1079 /* static object for efficiency or thread safety is a problem ? */
1080 throw SQLException("index out of range", *this, "42S22", 1, Any());
1084 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */