bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_resultset.hxx
blob461e81286cb62dc52062f875b345942126875398
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 #pragma once
22 #include "mysqlc_preparedstatement.hxx"
23 #include "mysqlc_statement.hxx"
24 #include "mysqlc_subcomponent.hxx"
25 #include "mysqlc_connection.hxx"
27 #include <com/sun/star/sdbc/XCloseable.hpp>
28 #include <com/sun/star/sdbc/XColumnLocate.hpp>
29 #include <com/sun/star/sdbc/XResultSet.hpp>
30 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
31 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
32 #include <com/sun/star/sdbc/XRow.hpp>
33 #include <com/sun/star/sdbc/XRowUpdate.hpp>
34 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
35 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
36 #include <com/sun/star/sdbcx/XRowLocate.hpp>
37 #include <com/sun/star/util/XCancellable.hpp>
39 #include <cppuhelper/compbase12.hxx>
41 namespace connectivity::mysqlc
43 using ::com::sun::star::sdbc::SQLException;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::RuntimeException;
48 ** OResultSet
50 typedef ::cppu::WeakComponentImplHelper12<
51 css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier,
52 css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate,
53 css::sdbc::XRowUpdate, css::sdbcx::XRowLocate, css::sdbcx::XDeleteRows, css::sdbc::XCloseable,
54 css::sdbc::XColumnLocate, css::lang::XServiceInfo>
55 OResultSet_BASE;
57 class OResultSet final : public OBase_Mutex,
58 public OResultSet_BASE,
59 public ::cppu::OPropertySetHelper,
60 public OPropertyArrayUsageHelper<OResultSet>
62 using DataFields = std::vector<OString>;
63 std::vector<DataFields> m_aRows;
64 std::vector<OUString> m_aFields;
65 MYSQL* m_pMysql = nullptr;
66 css::uno::WeakReferenceHelper m_aStatement;
67 css::uno::Reference<css::sdbc::XResultSetMetaData> m_xMetaData;
68 MYSQL_RES* m_pResult;
69 rtl_TextEncoding m_encoding;
70 bool m_bWasNull = false; // did the last getXXX result null?
72 sal_Int32 getDataLength(sal_Int32 column)
74 return m_aRows[m_nRowPosition][column - 1].getLength();
76 bool checkNull(sal_Int32 column);
78 /**
79 * Position of cursor indexed from 0
81 sal_Int32 m_nRowPosition = -1;
82 sal_Int32 m_nRowCount = 0;
84 // OPropertyArrayUsageHelper
85 ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
86 // OPropertySetHelper
87 ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
89 sal_Bool SAL_CALL convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue,
90 sal_Int32 nHandle, const Any& rValue) override;
92 void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) override;
94 void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const override;
96 virtual ~OResultSet() override = default;
98 /**
99 * Ensures that the results of the query has already been fetched.
101 void ensureResultFetched();
104 * Ensures that meta data of the corresponding result set has been already
105 * queried. It should be called before freeing the result set, unless the
106 * information is lost.
108 void ensureFieldInfoFetched();
111 * Check the following things:
112 * - cursor is out of range. Throws exception if true.
113 * - column index is out of range. Throws exception if true.
114 * - result set is fetched. If no, then it fetches the result.
116 void checkBordersAndEnsureFetched(sal_Int32 index);
119 * Fetches all the data from the MYSQL_RES object related to the class. It
120 * frees the MYSQL_RES object afterwards, so it cannot be used anymore.
122 void fetchResult();
124 public:
125 virtual OUString SAL_CALL getImplementationName() override;
127 virtual sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override;
129 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
131 OResultSet(OConnection& rConn, OCommonStatement* pStmt, MYSQL_RES* pResult,
132 rtl_TextEncoding _encoding);
134 // ::cppu::OComponentHelper
135 void SAL_CALL disposing() override;
137 // XInterface
138 Any SAL_CALL queryInterface(const css::uno::Type& rType) override;
140 void SAL_CALL acquire() noexcept override;
141 void SAL_CALL release() noexcept override;
143 //XTypeProvider
144 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
146 // XPropertySet
147 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
149 // XResultSet
150 sal_Bool SAL_CALL next() override;
151 sal_Bool SAL_CALL isBeforeFirst() override;
152 sal_Bool SAL_CALL isAfterLast() override;
153 sal_Bool SAL_CALL isFirst() override;
154 sal_Bool SAL_CALL isLast() override;
156 void SAL_CALL beforeFirst() override;
157 void SAL_CALL afterLast() override;
159 sal_Bool SAL_CALL first() override;
160 sal_Bool SAL_CALL last() override;
162 sal_Int32 SAL_CALL getRow() override;
164 sal_Bool SAL_CALL absolute(sal_Int32 row) override;
165 sal_Bool SAL_CALL relative(sal_Int32 rows) override;
166 sal_Bool SAL_CALL previous() override;
168 void SAL_CALL refreshRow() override;
170 sal_Bool SAL_CALL rowUpdated() override;
171 sal_Bool SAL_CALL rowInserted() override;
172 sal_Bool SAL_CALL rowDeleted() override;
174 css::uno::Reference<css::uno::XInterface> SAL_CALL getStatement() override;
175 // XRow
176 sal_Bool SAL_CALL wasNull() override;
178 OUString SAL_CALL getString(sal_Int32 column) override;
180 sal_Bool SAL_CALL getBoolean(sal_Int32 column) override;
181 sal_Int8 SAL_CALL getByte(sal_Int32 column) override;
182 sal_Int16 SAL_CALL getShort(sal_Int32 column) override;
183 sal_Int32 SAL_CALL getInt(sal_Int32 column) override;
184 sal_Int64 SAL_CALL getLong(sal_Int32 column) override;
186 float SAL_CALL getFloat(sal_Int32 column) override;
187 double SAL_CALL getDouble(sal_Int32 column) override;
189 css::uno::Sequence<sal_Int8> SAL_CALL getBytes(sal_Int32 column) override;
190 css::util::Date SAL_CALL getDate(sal_Int32 column) override;
191 css::util::Time SAL_CALL getTime(sal_Int32 column) override;
192 css::util::DateTime SAL_CALL getTimestamp(sal_Int32 column) override;
194 css::uno::Reference<css::io::XInputStream> SAL_CALL getBinaryStream(sal_Int32 column) override;
195 css::uno::Reference<css::io::XInputStream>
196 SAL_CALL getCharacterStream(sal_Int32 column) override;
198 Any SAL_CALL getObject(
199 sal_Int32 column, const css::uno::Reference<css::container::XNameAccess>& typeMap) override;
201 css::uno::Reference<css::sdbc::XRef> SAL_CALL getRef(sal_Int32 column) override;
202 css::uno::Reference<css::sdbc::XBlob> SAL_CALL getBlob(sal_Int32 column) override;
203 css::uno::Reference<css::sdbc::XClob> SAL_CALL getClob(sal_Int32 column) override;
204 css::uno::Reference<css::sdbc::XArray> SAL_CALL getArray(sal_Int32 column) override;
206 // XResultSetMetaDataSupplier
207 css::uno::Reference<css::sdbc::XResultSetMetaData> SAL_CALL getMetaData() override;
209 // XCancellable
210 void SAL_CALL cancel() override;
212 // XCloseable
213 void SAL_CALL close() override;
215 // XWarningsSupplier
216 Any SAL_CALL getWarnings() override;
218 void SAL_CALL clearWarnings() override;
220 // XResultSetUpdate
221 void SAL_CALL insertRow() override;
222 void SAL_CALL updateRow() override;
223 void SAL_CALL deleteRow() override;
224 void SAL_CALL cancelRowUpdates() override;
225 void SAL_CALL moveToInsertRow() override;
226 void SAL_CALL moveToCurrentRow() override;
228 // XRowUpdate
229 void SAL_CALL updateNull(sal_Int32 column) override;
230 void SAL_CALL updateBoolean(sal_Int32 column, sal_Bool x) override;
231 void SAL_CALL updateByte(sal_Int32 column, sal_Int8 x) override;
232 void SAL_CALL updateShort(sal_Int32 column, sal_Int16 x) override;
233 void SAL_CALL updateInt(sal_Int32 column, sal_Int32 x) override;
234 void SAL_CALL updateLong(sal_Int32 column, sal_Int64 x) override;
235 void SAL_CALL updateFloat(sal_Int32 column, float x) override;
236 void SAL_CALL updateDouble(sal_Int32 column, double x) override;
237 void SAL_CALL updateString(sal_Int32 column, const OUString& x) override;
238 void SAL_CALL updateBytes(sal_Int32 column, const css::uno::Sequence<sal_Int8>& x) override;
239 void SAL_CALL updateDate(sal_Int32 column, const css::util::Date& x) override;
240 void SAL_CALL updateTime(sal_Int32 column, const css::util::Time& x) override;
241 void SAL_CALL updateTimestamp(sal_Int32 column, const css::util::DateTime& x) override;
242 void SAL_CALL updateBinaryStream(sal_Int32 column,
243 const css::uno::Reference<css::io::XInputStream>& x,
244 sal_Int32 length) override;
245 void SAL_CALL updateCharacterStream(sal_Int32 column,
246 const css::uno::Reference<css::io::XInputStream>& x,
247 sal_Int32 length) override;
248 void SAL_CALL updateObject(sal_Int32 column, const Any& x) override;
249 void SAL_CALL updateNumericObject(sal_Int32 column, const Any& x, sal_Int32 scale) override;
251 // XColumnLocate
252 sal_Int32 SAL_CALL findColumn(const OUString& columnName) override;
254 // XRowLocate
255 Any SAL_CALL getBookmark() override;
257 sal_Bool SAL_CALL moveToBookmark(const Any& bookmark) override;
258 sal_Bool SAL_CALL moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows) override;
259 sal_Int32 SAL_CALL compareBookmarks(const Any& first, const Any& second) override;
260 sal_Bool SAL_CALL hasOrderedBookmarks() override;
261 sal_Int32 SAL_CALL hashBookmark(const Any& bookmark) override;
263 // XDeleteRows
264 css::uno::Sequence<sal_Int32> SAL_CALL deleteRows(const css::uno::Sequence<Any>& rows) override;
266 void checkColumnIndex(sal_Int32 index);
267 void checkRowIndex();
269 private:
270 using ::cppu::OPropertySetHelper::getFastPropertyValue;
273 } /* connectivity::mysqlc */
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */