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>
50using ::osl::MutexGuard;
56std::type_index getTypeFromMysqlType(enum_field_types
type)
61 return std::type_index(
typeid(
bool));
63 return std::type_index(
typeid(
sal_Int8));
64 case MYSQL_TYPE_SHORT:
66 return std::type_index(
typeid(sal_Int16));
68 case MYSQL_TYPE_INT24:
69 return std::type_index(
typeid(sal_Int32));
70 case MYSQL_TYPE_LONGLONG:
71 return std::type_index(
typeid(sal_Int64));
72 case MYSQL_TYPE_FLOAT:
73 return std::type_index(
typeid(
float));
74 case MYSQL_TYPE_DOUBLE:
75 return std::type_index(
typeid(
double));
76 case MYSQL_TYPE_TIMESTAMP:
77 case MYSQL_TYPE_DATETIME:
78 return std::type_index(
typeid(
DateTime));
80 return std::type_index(
typeid(
Date));
82 return std::type_index(
typeid(Time));
83 case MYSQL_TYPE_STRING:
84 case MYSQL_TYPE_VAR_STRING:
85 case MYSQL_TYPE_DECIMAL:
86 case MYSQL_TYPE_NEWDECIMAL:
87 return std::type_index(
typeid(OUString));
91 case MYSQL_TYPE_GEOMETRY:
94 return std::type_index(
typeid(
nullptr));
99bool OPreparedResultSet::fetchResult()
110 bool bIsBlobType =
false;
113 case MYSQL_TYPE_BLOB:
114 case MYSQL_TYPE_TINY_BLOB:
115 case MYSQL_TYPE_MEDIUM_BLOB:
116 case MYSQL_TYPE_LONG_BLOB:
138 int failure = mysql_stmt_fetch(
m_pStmt);
162 else if (failure == MYSQL_NO_DATA)
169 return "com.sun.star.sdbcx.mysqlc.ResultSet";
174 return {
"com.sun.star.sdbc.ResultSet",
"com.sun.star.sdbcx.ResultSet" };
185 , m_rConnection(rConn)
188 , m_encoding(rConn.getConnectionEncoding())
189 , m_nColumnCount(mysql_stmt_field_count(pMyStmt))
193 mysql_stmt_store_result(
m_pStmt);
211 if (!aRet.hasValue())
239 throw SQLException(
"The column name '" +
columnName +
"' is not valid.", *
this,
"42S22", 0,
248 if (*
m_aData[nColumnIndex - 1].is_null)
255 return retrieveValue<T>(nColumnIndex);
260 if (getTypeFromMysqlType(
m_aFields[nColumnIndex - 1].
type) == std::type_index(
typeid(T)))
261 return *
static_cast<T*
>(
m_aData[nColumnIndex - 1].buffer);
265 if constexpr (std::is_same_v<sal_Int64, T>)
266 return row.getLong();
267 else if constexpr (std::is_same_v<sal_Int32, T>)
268 return row.getInt32();
269 else if constexpr (std::is_same_v<sal_Int16, T>)
270 return row.getInt16();
271 else if constexpr (std::is_same_v<sal_Int8, T>)
272 return row.getInt8();
273 else if constexpr (std::is_same_v<double, T>)
274 return row.getDouble();
275 else if constexpr (std::is_same_v<float, T>)
276 return row.getFloat();
277 else if constexpr (std::is_same_v<bool, T>)
278 return row.getBool();
287 return uno::Sequence<sal_Int8>(
static_cast<sal_Int8 const*
>(
m_aData[column - 1].buffer),
293 if (getTypeFromMysqlType(
m_aFields[column - 1].
type) != std::type_index(
typeid(
Date)))
295 const MYSQL_TIME* pTime =
static_cast<MYSQL_TIME*
>(
m_aData[column - 1].buffer);
298 d.Year = pTime->year;
299 d.Month = pTime->month;
306 if (getTypeFromMysqlType(
m_aFields[column - 1].
type) != std::type_index(
typeid(Time)))
308 const MYSQL_TIME* pTime =
static_cast<MYSQL_TIME*
>(
m_aData[column - 1].buffer);
311 t.Hours = pTime->hour;
312 t.Minutes = pTime->minute;
313 t.Seconds = pTime->second;
321 const MYSQL_TIME* pTime =
static_cast<MYSQL_TIME*
>(
m_aData[column - 1].buffer);
324 t.Year = pTime->year;
325 t.Month = pTime->month;
327 t.Hours = pTime->hour;
328 t.Minutes = pTime->minute;
329 t.Seconds = pTime->second;
337 bool bIsBlobType =
false;
340 case MYSQL_TYPE_BLOB:
341 case MYSQL_TYPE_TINY_BLOB:
342 case MYSQL_TYPE_MEDIUM_BLOB:
343 case MYSQL_TYPE_LONG_BLOB:
350 if (getTypeFromMysqlType(
m_aFields[column - 1].
type) != std::type_index(
typeid(OUString))
353 const char* sStr =
static_cast<const char*
>(
m_aData[column - 1].buffer);
362 case MYSQL_TYPE_TINY:
364 case MYSQL_TYPE_SHORT:
365 case MYSQL_TYPE_YEAR:
367 case MYSQL_TYPE_LONG:
368 case MYSQL_TYPE_INT24:
369 return getInt(nColumnIndex);
372 case MYSQL_TYPE_LONGLONG:
374 case MYSQL_TYPE_FLOAT:
376 case MYSQL_TYPE_DOUBLE:
378 case MYSQL_TYPE_TIMESTAMP:
379 case MYSQL_TYPE_DATETIME:
381 case MYSQL_TYPE_DATE:
383 case MYSQL_TYPE_TIME:
385 case MYSQL_TYPE_STRING:
386 case MYSQL_TYPE_VAR_STRING:
387 case MYSQL_TYPE_DECIMAL:
388 case MYSQL_TYPE_NEWDECIMAL:
390 case MYSQL_TYPE_BLOB:
391 case MYSQL_TYPE_TINY_BLOB:
392 case MYSQL_TYPE_MEDIUM_BLOB:
393 case MYSQL_TYPE_LONG_BLOB:
394 throw SQLException(
"Column with type BLOB cannot be converted", *
this,
"22000", 1,
397 SAL_WARN(
"connectivity.mysqlc",
"OPreparedResultSet::getRowSetValue: unknown type: "
399 throw SQLException(
"Unknown column type when fetching result", *
this,
"22000", 1,
414 "OPreparedResultSet::getCharacterStream", *
this);
420 return safelyRetrieveValue<bool>(column);
425 return safelyRetrieveValue<sal_Int8>(column);
430 return safelyRetrieveValue<uno::Sequence<sal_Int8>>(column);
435 return safelyRetrieveValue<Date>(column);
440 return safelyRetrieveValue<double>(column);
445 return safelyRetrieveValue<float>(column);
450 return safelyRetrieveValue<sal_Int32>(column);
458 return static_cast<sal_Int32
>(mysql_field_tell(
m_pResult));
463 return safelyRetrieveValue<sal_Int64>(column);
518 const uno::Reference<XNameAccess>& )
532 return safelyRetrieveValue<sal_Int16>(column);
537 return safelyRetrieveValue<OUString>(column);
542 return safelyRetrieveValue<Time>(column);
547 return safelyRetrieveValue<DateTime>(column);
586 mysql_stmt_data_seek(
m_pStmt, 0);
610 mysql_stmt_free_result(
m_pStmt);
619 mysql_stmt_data_seek(
m_pStmt, 0);
642 sal_Int32 nToGo = row < 0 ?
m_nRowCount - row : row - 1;
649 mysql_stmt_data_seek(
m_pStmt, nToGo);
669 mysql_stmt_data_seek(
m_pStmt, nToGo);
882 const uno::Sequence<sal_Int8>& )
919 const uno::Reference<XInputStream>& ,
926 "OPreparedResultSet::updateBinaryStream", *
this);
930 const uno::Reference<XInputStream>& ,
937 "OPreparedResultSet::updateCharacterStream", *
this);
964 "OPreparedResultSet::updateNumericObject", *
this);
995 "OPreparedResultSet::moveRelativeToBookmark", *
this);
1007 return CompareBookmark::NOT_EQUAL;
1020uno::Sequence<sal_Int32>
1028 return uno::Sequence<sal_Int32>();
1037 PropertyAttribute::READONLY },
1041 PropertyAttribute::READONLY } }
1048 Any& , sal_Int32 nHandle,
1057 throw css::lang::IllegalArgumentException();
1074 throw uno::Exception(
"cannot set prop " + OUString::number(
nHandle),
nullptr);
1093 _rValue <<= ResultSetConcurrency::READ_ONLY;
1096 _rValue <<= ResultSetType::SCROLL_INSENSITIVE;
1099 _rValue <<= FetchDirection::FORWARD;
1102 _rValue <<= sal_Int32(50);
1115 return ::cppu::OPropertySetHelper::createPropertySetInfo(
getInfoHelper());
1121 throw SQLException(
"Cursor out of range", *
this,
"HY109", 1,
Any());
1125 throw SQLException(
"index out of range", *
this,
"42S22", 1,
Any());
void disposing(std::unique_lock< std::mutex > &rGuard)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
css::util::Time getTime() const
OUString getString() const
css::util::Date getDate() const
css::util::DateTime getDateTime() const
MYSQL * getMysqlConnection()
void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any &rValue) override
void SAL_CALL updateFloat(sal_Int32 column, float x) override
void SAL_CALL updateInt(sal_Int32 column, sal_Int32 x) override
void SAL_CALL updateBytes(sal_Int32 column, const css::uno::Sequence< sal_Int8 > &x) override
std::unique_ptr< BindMetaData[]> m_aMetaData
css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 column) override
sal_Bool SAL_CALL getBoolean(sal_Int32 column) override
sal_Bool SAL_CALL isLast() override
sal_Bool SAL_CALL isAfterLast() override
sal_Int16 SAL_CALL getShort(sal_Int32 column) override
::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 column) override
sal_Bool SAL_CALL isBeforeFirst() override
sal_Bool SAL_CALL previous() override
void SAL_CALL getFastPropertyValue(Any &rValue, sal_Int32 nHandle) const override
OUString SAL_CALL getString(sal_Int32 column) override
css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL updateByte(sal_Int32 column, sal_Int8 x) override
css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
void SAL_CALL cancel() override
sal_Bool SAL_CALL convertFastPropertyValue(Any &rConvertedValue, Any &rOldValue, sal_Int32 nHandle, const Any &rValue) override
sal_Bool SAL_CALL next() override
Any SAL_CALL getObject(sal_Int32 column, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
void SAL_CALL moveToInsertRow() override
void SAL_CALL release() noexcept override
css::util::DateTime SAL_CALL getTimestamp(sal_Int32 column) override
void SAL_CALL afterLast() override
OConnection & m_rConnection
T safelyRetrieveValue(const sal_Int32 nColumnIndex)
sal_Int32 SAL_CALL compareBookmarks(const Any &first, const Any &second) override
void SAL_CALL beforeFirst() override
sal_Bool SAL_CALL moveToBookmark(const Any &bookmark) override
sal_Int32 SAL_CALL hashBookmark(const Any &bookmark) override
sal_Bool SAL_CALL rowDeleted() override
void SAL_CALL cancelRowUpdates() override
void SAL_CALL refreshRow() override
sal_Bool SAL_CALL rowInserted() override
void SAL_CALL deleteRow() override
css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 column) override
void SAL_CALL updateBoolean(sal_Int32 column, sal_Bool x) override
void SAL_CALL updateLong(sal_Int32 column, sal_Int64 x) override
css::util::Time SAL_CALL getTime(sal_Int32 column) override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
sal_Bool SAL_CALL rowUpdated() override
sal_Bool SAL_CALL absolute(sal_Int32 row) override
void SAL_CALL updateCharacterStream(sal_Int32 column, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
void checkColumnIndex(sal_Int32 index)
sal_Int8 SAL_CALL getByte(sal_Int32 column) override
void SAL_CALL updateObject(sal_Int32 column, const Any &x) override
sal_Bool SAL_CALL relative(sal_Int32 rows) override
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
float SAL_CALL getFloat(sal_Int32 column) override
sal_Bool SAL_CALL first() override
void SAL_CALL updateTime(sal_Int32 column, const css::util::Time &x) override
css::uno::WeakReferenceHelper m_aStatement
::cppu::IPropertyArrayHelper * createArrayHelper() const override
used to implement the creation of the array helper which is shared amongst all instances of the class...
T retrieveValue(const sal_Int32 nColumnIndex)
void SAL_CALL clearWarnings() override
void SAL_CALL updateTimestamp(sal_Int32 column, const css::util::DateTime &x) override
void SAL_CALL disposing() override
Any SAL_CALL queryInterface(const css::uno::Type &rType) override
std::unique_ptr< MYSQL_BIND[]> m_aData
void SAL_CALL acquire() noexcept override
sal_Int32 SAL_CALL getRow() override
sal_Bool SAL_CALL last() override
void SAL_CALL updateNull(sal_Int32 column) override
rtl_TextEncoding m_encoding
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
void SAL_CALL updateDate(sal_Int32 column, const css::util::Date &x) override
double SAL_CALL getDouble(sal_Int32 column) override
void SAL_CALL moveToCurrentRow() override
css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 column) override
sal_Bool SAL_CALL isFirst() override
css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 column) override
css::util::Date SAL_CALL getDate(sal_Int32 column) override
Any SAL_CALL getBookmark() override
sal_Bool SAL_CALL hasOrderedBookmarks() override
void SAL_CALL updateString(sal_Int32 column, const OUString &x) override
virtual OUString SAL_CALL getImplementationName() override
connectivity::ORowSetValue getRowSetValue(sal_Int32 nColumnIndex)
void SAL_CALL close() override
void SAL_CALL insertRow() override
sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
void SAL_CALL updateBinaryStream(sal_Int32 column, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
OPreparedResultSet(OConnection &rConn, OPreparedStatement *pStmt, MYSQL_STMT *pMyStmt)
css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows(const css::uno::Sequence< Any > &rows) override
void SAL_CALL updateRow() override
void SAL_CALL updateShort(sal_Int32 column, sal_Int16 x) override
sal_Int32 SAL_CALL getInt(sal_Int32 column) override
Any SAL_CALL getWarnings() override
sal_Bool SAL_CALL wasNull() override
void SAL_CALL updateNumericObject(sal_Int32 column, const Any &x, sal_Int32 scale) override
sal_Int64 SAL_CALL getLong(sal_Int32 column) override
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 column) override
void SAL_CALL updateDouble(sal_Int32 column, double x) override
css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 column) override
sal_Bool SAL_CALL moveRelativeToBookmark(const Any &bookmark, sal_Int32 rows) override
::cppu::IPropertyArrayHelper * getArrayHelper()
call this in the getInfoHelper method of your derived class.
mutable::osl::Mutex m_aMutex
css::uno::Type const & get()
virtual void SAL_CALL dispose() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
#define SAL_WARN(area, stream)
static ColumnProperty ** pFields
void checkDisposed(bool _bThrow)
@ PROPERTY_ID_FETCHDIRECTION
@ PROPERTY_ID_ISBOOKMARKABLE
@ PROPERTY_ID_RESULTSETTYPE
@ PROPERTY_ID_RESULTSETCONCURRENCY
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &_rLeft, const css::uno::Sequence< T > &_rRight)
concat two sequences
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void allocateSqlVar(void **mem, enum_field_types eType, unsigned nSize)
void throwSQLExceptionWithMsg(const char *msg, const char *SQLSTATE, unsigned int errorNum, const css::uno::Reference< css::uno::XInterface > &_context, const rtl_TextEncoding encoding)
void throwFeatureNotImplementedException(const char *_pAsciiFeatureName, const css::uno::Reference< XInterface > &_rxContext)