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::vector<OString> lcl_split(std::string_view rStr,
char cSeparator)
58 std::vector<OString> vec;
72void OResultSet::checkRowIndex()
74 if (m_nRowPosition < 0 || m_nRowPosition >=
m_nRowCount)
76 throw SQLException(
"Cursor position out of range", *
this, OUString(), 1,
Any());
93 return "com.sun.star.sdbcx.mysqlc.ResultSet";
98 return {
"com.sun.star.sdbc.ResultSet",
"com.sun.star.sdbcx.ResultSet" };
107 rtl_TextEncoding _encoding)
110 , m_pMysql(rConn.getMysqlConnection())
113 , m_encoding(_encoding)
138 unsigned nFieldCount = mysql_num_fields(
m_pResult);
141 for (
unsigned i = 0;
i < nFieldCount; ++
i)
143 pFields[i].name, static_cast<sal_Int32>(strlen(pFields[i].name)), m_encoding });
157 MYSQL_ROW data = mysql_fetch_row(
m_pResult);
158 unsigned long* lengths = mysql_fetch_lengths(
m_pResult);
163 m_aRows.back().push_back(OString{ data[
col],
static_cast<sal_Int32
>(lengths[
col]) });
166 unsigned errorNum = mysql_errno(
m_pMysql);
192 if (!aRet.hasValue())
217 return static_cast<sal_Int32
>(
i) + 1;
220 throw SQLException(
"The column name '" +
columnName +
"' is not valid.", *
this,
"42S22", 0,
256 return sVal.toInt32() != 0;
269 return static_cast<sal_Int8>(sVal.toInt32());
279 return uno::Sequence<sal_Int8>();
281 return uno::Sequence<sal_Int8>(
reinterpret_cast<sal_Int8 const*
>(sVal.getStr()),
298 std::string_view dateString(dateStr);
331 return sVal.toDouble();
343 return sVal.toFloat();
355 return sVal.toInt32();
375 return sVal.toInt64();
426 const uno::Reference<XNameAccess>& )
445 return sVal.toInt32();
454 return rtl::OUString{};
474 size_t idx = timeString.find(
' ');
475 if (
idx == std::string_view::npos)
512 std::vector<OString> dateAndTime = lcl_split(sVal.subView(0,
getDataLength(column)),
' ');
514 auto dateParts = lcl_split(dateAndTime.at(0),
'-');
515 auto timeParts = lcl_split(dateAndTime.at(1),
':');
517 if (dateParts.size() < 2 || timeParts.size() < 2)
518 throw SQLException(
"Timestamp has a wrong format", *
this, OUString(), 1,
Any());
522 dt.Year = dateParts.at(0).toUInt32();
523 dt.Month = dateParts.at(1).toUInt32();
524 dt.Day = dateParts.at(2).toUInt32();
525 dt.Hours = timeParts.at(0).toUInt32();
526 dt.Minutes = timeParts.at(1).toUInt32();
527 dt.Seconds = timeParts.at(2).toUInt32();
619 sal_Int32 nToGo = row < 0 ? (
m_nRowCount - 1) - row : row - 1;
901 const uno::Reference<XInputStream>& ,
913 const uno::Reference<XInputStream>& ,
989 return CompareBookmark::NOT_EQUAL;
1007 return uno::Sequence<sal_Int32>();
1016 PropertyAttribute::READONLY },
1020 PropertyAttribute::READONLY } }
1027 sal_Int32 nHandle,
const Any& )
1035 throw css::lang::IllegalArgumentException();
1051 throw uno::Exception(
"cannot set prop " + OUString::number(
nHandle),
nullptr);
1070 _rValue <<= ResultSetConcurrency::READ_ONLY;
1073 _rValue <<= ResultSetType::SCROLL_INSENSITIVE;
1076 _rValue <<= FetchDirection::FORWARD;
1079 _rValue <<= sal_Int32(50);
1092 return ::cppu::OPropertySetHelper::createPropertySetInfo(
getInfoHelper());
1100 throw SQLException(
"index out of range", *
this, OUString(), 1,
Any());
void disposing(std::unique_lock< std::mutex > &rGuard)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
::cppu::IPropertyArrayHelper * getArrayHelper()
call this in the getInfoHelper method of your derived class.
std::vector< OUString > m_aFields
sal_Bool SAL_CALL getBoolean(sal_Int32 column) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
sal_Bool SAL_CALL rowUpdated() override
void SAL_CALL updateNull(sal_Int32 column) override
sal_Bool SAL_CALL first() override
void ensureFieldInfoFetched()
Ensures that meta data of the corresponding result set has been already queried.
void ensureResultFetched()
Ensures that the results of the query has already been fetched.
void SAL_CALL updateByte(sal_Int32 column, sal_Int8 x) override
void SAL_CALL updateString(sal_Int32 column, const OUString &x) override
void SAL_CALL updateBinaryStream(sal_Int32 column, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
sal_Bool SAL_CALL absolute(sal_Int32 row) override
css::util::DateTime SAL_CALL getTimestamp(sal_Int32 column) override
void SAL_CALL updateFloat(sal_Int32 column, float x) override
sal_Bool SAL_CALL moveToBookmark(const Any &bookmark) override
sal_Int32 SAL_CALL getInt(sal_Int32 column) override
void SAL_CALL disposing() override
void SAL_CALL deleteRow() override
sal_Bool SAL_CALL relative(sal_Int32 rows) override
OResultSet(OConnection &rConn, OCommonStatement *pStmt, MYSQL_RES *pResult, rtl_TextEncoding _encoding)
void SAL_CALL updateDate(sal_Int32 column, const css::util::Date &x) override
void SAL_CALL clearWarnings() override
void SAL_CALL close() override
sal_Bool SAL_CALL isLast() override
Any SAL_CALL getObject(sal_Int32 column, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
void SAL_CALL updateNumericObject(sal_Int32 column, const Any &x, sal_Int32 scale) override
sal_Int32 SAL_CALL compareBookmarks(const Any &first, const Any &second) override
void checkColumnIndex(sal_Int32 index)
sal_Int32 getDataLength(sal_Int32 column)
sal_Bool SAL_CALL isFirst() override
::cppu::IPropertyArrayHelper * createArrayHelper() const override
used to implement the creation of the array helper which is shared amongst all instances of the class...
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
float SAL_CALL getFloat(sal_Int32 column) override
std::vector< OString > DataFields
sal_Bool SAL_CALL hasOrderedBookmarks() override
sal_Bool SAL_CALL convertFastPropertyValue(Any &rConvertedValue, Any &rOldValue, sal_Int32 nHandle, const Any &rValue) override
css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 column) override
sal_Bool SAL_CALL next() override
void SAL_CALL beforeFirst() override
css::uno::WeakReferenceHelper m_aStatement
void SAL_CALL updateDouble(sal_Int32 column, double x) override
Any SAL_CALL getWarnings() override
css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 column) override
void SAL_CALL updateTime(sal_Int32 column, const css::util::Time &x) override
sal_Int32 m_nRowPosition
Position of cursor indexed from 0.
void SAL_CALL updateTimestamp(sal_Int32 column, const css::util::DateTime &x) override
void SAL_CALL moveToInsertRow() override
css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 column) override
void SAL_CALL updateBytes(sal_Int32 column, const css::uno::Sequence< sal_Int8 > &x) override
Any SAL_CALL getBookmark() override
sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
sal_Bool SAL_CALL isAfterLast() override
void SAL_CALL afterLast() override
void SAL_CALL release() noexcept override
Any SAL_CALL queryInterface(const css::uno::Type &rType) override
css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows(const css::uno::Sequence< Any > &rows) override
sal_Bool SAL_CALL isBeforeFirst() override
sal_Int16 SAL_CALL getShort(sal_Int32 column) override
void SAL_CALL updateBoolean(sal_Int32 column, sal_Bool x) override
sal_Bool SAL_CALL last() override
void fetchResult()
Fetches all the data from the MYSQL_RES object related to the class.
::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
void SAL_CALL insertRow() override
void SAL_CALL getFastPropertyValue(Any &rValue, sal_Int32 nHandle) const override
css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
void SAL_CALL acquire() noexcept override
void SAL_CALL updateRow() override
double SAL_CALL getDouble(sal_Int32 column) override
css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 column) override
void SAL_CALL updateObject(sal_Int32 column, const Any &x) override
void SAL_CALL updateCharacterStream(sal_Int32 column, const css::uno::Reference< css::io::XInputStream > &x, sal_Int32 length) override
void SAL_CALL refreshRow() override
void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any &rValue) override
sal_Bool SAL_CALL previous() override
void SAL_CALL updateShort(sal_Int32 column, sal_Int16 x) override
rtl_TextEncoding m_encoding
OUString SAL_CALL getString(sal_Int32 column) override
css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 column) override
css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 column) override
sal_Int32 SAL_CALL hashBookmark(const Any &bookmark) override
sal_Bool SAL_CALL rowInserted() override
void SAL_CALL cancel() override
void SAL_CALL moveToCurrentRow() override
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
std::vector< DataFields > m_aRows
sal_Bool SAL_CALL wasNull() override
bool checkNull(sal_Int32 column)
css::util::Time SAL_CALL getTime(sal_Int32 column) override
void SAL_CALL cancelRowUpdates() override
void SAL_CALL updateInt(sal_Int32 column, sal_Int32 x) override
sal_Bool SAL_CALL rowDeleted() override
css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 column) override
sal_Int32 SAL_CALL getRow() override
css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
sal_Int64 SAL_CALL getLong(sal_Int32 column) override
void checkBordersAndEnsureFetched(sal_Int32 index)
Check the following things:
css::util::Date SAL_CALL getDate(sal_Int32 column) override
void SAL_CALL updateLong(sal_Int32 column, sal_Int64 x) override
sal_Int8 SAL_CALL getByte(sal_Int32 column) override
sal_Bool SAL_CALL moveRelativeToBookmark(const Any &bookmark, sal_Int32 rows) override
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
RttiCompleteObjectLocator col
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 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)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)