1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX 21 #define INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX 22 23 #include "mysqlc_preparedstatement.hxx" 24 #include "mysqlc_statement.hxx" 25 #include "mysqlc_subcomponent.hxx" 26 #include "mysqlc_connection.hxx" 27 28 #include <com/sun/star/sdbc/XCloseable.hpp> 29 #include <com/sun/star/sdbc/XColumnLocate.hpp> 30 #include <com/sun/star/sdbc/XResultSet.hpp> 31 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 32 #include <com/sun/star/sdbc/XResultSetUpdate.hpp> 33 #include <com/sun/star/sdbc/XRow.hpp> 34 #include <com/sun/star/sdbc/XRowUpdate.hpp> 35 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 36 #include <com/sun/star/sdbcx/XDeleteRows.hpp> 37 #include <com/sun/star/sdbcx/XRowLocate.hpp> 38 #include <com/sun/star/util/XCancellable.hpp> 39 #include <connectivity/FValue.hxx> 40 41 #include <cppuhelper/compbase12.hxx> 42 43 namespace connectivity 44 { 45 namespace mysqlc 46 { 47 using ::com::sun::star::sdbc::SQLException; 48 using ::com::sun::star::uno::Any; 49 using ::com::sun::star::uno::RuntimeException; 50 51 typedef ::cppu::WeakComponentImplHelper12< 52 css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, 53 css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate, 54 css::sdbc::XRowUpdate, css::sdbcx::XRowLocate, css::sdbcx::XDeleteRows, css::sdbc::XCloseable, 55 css::sdbc::XColumnLocate, css::lang::XServiceInfo> 56 OPreparedResultSet_BASE; 57 58 class OPreparedResultSet final : public OBase_Mutex, 59 public OPreparedResultSet_BASE, 60 public ::cppu::OPropertySetHelper, 61 public OPropertyArrayUsageHelper<OPreparedResultSet> 62 { 63 OConnection& m_rConnection; 64 css::uno::WeakReferenceHelper m_aStatement; 65 css::uno::Reference<css::sdbc::XResultSetMetaData> m_xMetaData; 66 67 // non-owning pointers 68 MYSQL_RES* m_pResult; 69 MYSQL_STMT* m_pStmt; 70 MYSQL_FIELD* m_aFields; 71 72 rtl_TextEncoding m_encoding; 73 sal_Int32 m_nCurrentRow = 0; 74 sal_Int32 m_nColumnCount; 75 sal_Int32 m_nRowCount; 76 77 // Use c style arrays, because we have to work with pointers 78 // on these. 79 std::unique_ptr<MYSQL_BIND[]> m_aData; 80 std::unique_ptr<BindMetaData[]> m_aMetaData; 81 82 bool m_bWasNull = false; 83 84 // OPropertyArrayUsageHelper 85 ::cppu::IPropertyArrayHelper* createArrayHelper() const override; 86 // OPropertySetHelper 87 ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; 88 89 sal_Bool SAL_CALL convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, 90 sal_Int32 nHandle, const Any& rValue) override; 91 92 void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) override; 93 94 void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const override; 95 96 template <typename T> T safelyRetrieveValue(const sal_Int32 nColumnIndex); 97 template <typename T> T retrieveValue(const sal_Int32 nColumnIndex); 98 connectivity::ORowSetValue getRowSetValue(sal_Int32 nColumnIndex); 99 100 bool fetchResult(); 101 102 // you can't delete objects of this type 103 virtual ~OPreparedResultSet() override = default; 104 105 public: 106 virtual OUString SAL_CALL getImplementationName() override; 107 108 virtual sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; 109 110 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; 111 112 OPreparedResultSet(OConnection& rConn, OPreparedStatement* pStmt, MYSQL_STMT* pMyStmt); 113 114 // ::cppu::OComponentHelper 115 void SAL_CALL disposing() override; 116 117 // XInterface 118 Any SAL_CALL queryInterface(const css::uno::Type& rType) override; 119 120 void SAL_CALL acquire() throw() override; 121 void SAL_CALL release() throw() override; 122 123 //XTypeProvider 124 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; 125 126 // XPropertySet 127 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; 128 129 // XResultSet 130 sal_Bool SAL_CALL next() override; 131 sal_Bool SAL_CALL isBeforeFirst() override; 132 sal_Bool SAL_CALL isAfterLast() override; 133 sal_Bool SAL_CALL isFirst() override; 134 sal_Bool SAL_CALL isLast() override; 135 136 void SAL_CALL beforeFirst() override; 137 void SAL_CALL afterLast() override; 138 139 sal_Bool SAL_CALL first() override; 140 sal_Bool SAL_CALL last() override; 141 142 sal_Int32 SAL_CALL getRow() override; 143 144 sal_Bool SAL_CALL absolute(sal_Int32 row) override; 145 sal_Bool SAL_CALL relative(sal_Int32 rows) override; 146 sal_Bool SAL_CALL previous() override; 147 148 void SAL_CALL refreshRow() override; 149 150 sal_Bool SAL_CALL rowUpdated() override; 151 sal_Bool SAL_CALL rowInserted() override; 152 sal_Bool SAL_CALL rowDeleted() override; 153 154 css::uno::Reference<css::uno::XInterface> SAL_CALL getStatement() override; 155 // XRow 156 sal_Bool SAL_CALL wasNull() override; 157 158 OUString SAL_CALL getString(sal_Int32 column) override; 159 160 sal_Bool SAL_CALL getBoolean(sal_Int32 column) override; 161 sal_Int8 SAL_CALL getByte(sal_Int32 column) override; 162 sal_Int16 SAL_CALL getShort(sal_Int32 column) override; 163 sal_Int32 SAL_CALL getInt(sal_Int32 column) override; 164 sal_Int64 SAL_CALL getLong(sal_Int32 column) override; 165 166 float SAL_CALL getFloat(sal_Int32 column) override; 167 double SAL_CALL getDouble(sal_Int32 column) override; 168 169 css::uno::Sequence<sal_Int8> SAL_CALL getBytes(sal_Int32 column) override; 170 css::util::Date SAL_CALL getDate(sal_Int32 column) override; 171 css::util::Time SAL_CALL getTime(sal_Int32 column) override; 172 css::util::DateTime SAL_CALL getTimestamp(sal_Int32 column) override; 173 174 css::uno::Reference<css::io::XInputStream> SAL_CALL getBinaryStream(sal_Int32 column) override; 175 css::uno::Reference<css::io::XInputStream> 176 SAL_CALL getCharacterStream(sal_Int32 column) override; 177 178 Any SAL_CALL getObject( 179 sal_Int32 column, const css::uno::Reference<css::container::XNameAccess>& typeMap) override; 180 181 css::uno::Reference<css::sdbc::XRef> SAL_CALL getRef(sal_Int32 column) override; 182 css::uno::Reference<css::sdbc::XBlob> SAL_CALL getBlob(sal_Int32 column) override; 183 css::uno::Reference<css::sdbc::XClob> SAL_CALL getClob(sal_Int32 column) override; 184 css::uno::Reference<css::sdbc::XArray> SAL_CALL getArray(sal_Int32 column) override; 185 186 // XResultSetMetaDataSupplier 187 css::uno::Reference<css::sdbc::XResultSetMetaData> SAL_CALL getMetaData() override; 188 189 // XCancellable 190 void SAL_CALL cancel() override; 191 192 // XCloseable 193 void SAL_CALL close() override; 194 195 // XWarningsSupplier 196 Any SAL_CALL getWarnings() override; 197 198 void SAL_CALL clearWarnings() override; 199 200 // XResultSetUpdate 201 void SAL_CALL insertRow() override; 202 void SAL_CALL updateRow() override; 203 void SAL_CALL deleteRow() override; 204 void SAL_CALL cancelRowUpdates() override; 205 void SAL_CALL moveToInsertRow() override; 206 void SAL_CALL moveToCurrentRow() override; 207 208 // XRowUpdate 209 void SAL_CALL updateNull(sal_Int32 column) override; 210 void SAL_CALL updateBoolean(sal_Int32 column, sal_Bool x) override; 211 void SAL_CALL updateByte(sal_Int32 column, sal_Int8 x) override; 212 void SAL_CALL updateShort(sal_Int32 column, sal_Int16 x) override; 213 void SAL_CALL updateInt(sal_Int32 column, sal_Int32 x) override; 214 void SAL_CALL updateLong(sal_Int32 column, sal_Int64 x) override; 215 void SAL_CALL updateFloat(sal_Int32 column, float x) override; 216 void SAL_CALL updateDouble(sal_Int32 column, double x) override; 217 void SAL_CALL updateString(sal_Int32 column, const OUString& x) override; 218 void SAL_CALL updateBytes(sal_Int32 column, const css::uno::Sequence<sal_Int8>& x) override; 219 void SAL_CALL updateDate(sal_Int32 column, const css::util::Date& x) override; 220 void SAL_CALL updateTime(sal_Int32 column, const css::util::Time& x) override; 221 void SAL_CALL updateTimestamp(sal_Int32 column, const css::util::DateTime& x) override; 222 void SAL_CALL updateBinaryStream(sal_Int32 column, 223 const css::uno::Reference<css::io::XInputStream>& x, 224 sal_Int32 length) override; 225 void SAL_CALL updateCharacterStream(sal_Int32 column, 226 const css::uno::Reference<css::io::XInputStream>& x, 227 sal_Int32 length) override; 228 void SAL_CALL updateObject(sal_Int32 column, const Any& x) override; 229 void SAL_CALL updateNumericObject(sal_Int32 column, const Any& x, sal_Int32 scale) override; 230 231 // XColumnLocate 232 sal_Int32 SAL_CALL findColumn(const OUString& columnName) override; 233 234 // XRowLocate 235 Any SAL_CALL getBookmark() override; 236 237 sal_Bool SAL_CALL moveToBookmark(const Any& bookmark) override; 238 sal_Bool SAL_CALL moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows) override; 239 sal_Int32 SAL_CALL compareBookmarks(const Any& first, const Any& second) override; 240 sal_Bool SAL_CALL hasOrderedBookmarks() override; 241 sal_Int32 SAL_CALL hashBookmark(const Any& bookmark) override; 242 243 // XDeleteRows 244 css::uno::Sequence<sal_Int32> SAL_CALL deleteRows(const css::uno::Sequence<Any>& rows) override; 245 246 /// @throws SQLException 247 /// @throws RuntimeException 248 void checkColumnIndex(sal_Int32 index); 249 250 private: 251 using ::cppu::OPropertySetHelper::getFastPropertyValue; 252 }; 253 } /* mysqlc */ 254 } /* connectivity */ 255 #endif // CONNECTIVITY_SRESULTSET_HXX 256 257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 258