bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_resultset.hxx
blob027cc294c1531e0f7c74c8f7de53a3466a2edd9a
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 #ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX
21 #define INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX
23 #include "mysqlc_preparedstatement.hxx"
24 #include "mysqlc_statement.hxx"
25 #include "mysqlc_subcomponent.hxx"
26 #include "mysqlc_connection.hxx"
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>
40 #include <cppuhelper/compbase12.hxx>
42 namespace connectivity
44 namespace mysqlc
46 using ::com::sun::star::sdbc::SQLException;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::RuntimeException;
51 ** OResultSet
53 typedef ::cppu::WeakComponentImplHelper12<
54 css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier,
55 css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate,
56 css::sdbc::XRowUpdate, css::sdbcx::XRowLocate, css::sdbcx::XDeleteRows, css::sdbc::XCloseable,
57 css::sdbc::XColumnLocate, css::lang::XServiceInfo>
58 OResultSet_BASE;
60 class OResultSet final : public OBase_Mutex,
61 public OResultSet_BASE,
62 public ::cppu::OPropertySetHelper,
63 public OPropertyArrayUsageHelper<OResultSet>
65 using DataFields = std::vector<OString>;
66 std::vector<DataFields> m_aRows;
67 std::vector<OUString> m_aFields;
68 MYSQL* m_pMysql = nullptr;
69 css::uno::WeakReferenceHelper m_aStatement;
70 css::uno::Reference<css::sdbc::XResultSetMetaData> m_xMetaData;
71 MYSQL_RES* m_pResult;
72 rtl_TextEncoding m_encoding;
73 bool m_bWasNull = false; // did the last getXXX result null?
74 bool m_bResultFetched = false;
76 sal_Int32 getDataLength(sal_Int32 column)
78 return m_aRows[m_nRowPosition][column - 1].getLength();
80 bool checkNull(sal_Int32 column);
82 /**
83 * Position of cursor indexed from 0
85 sal_Int32 m_nRowPosition = -1;
86 sal_Int32 m_nRowCount = 0;
88 // OPropertyArrayUsageHelper
89 ::cppu::IPropertyArrayHelper* createArrayHelper() const override;
90 // OPropertySetHelper
91 ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
93 sal_Bool SAL_CALL convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue,
94 sal_Int32 nHandle, const Any& rValue) override;
96 void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) override;
98 void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const override;
100 virtual ~OResultSet() override = default;
103 * Ensures that the results of the query has already been fetched.
105 void ensureResultFetched();
108 * Ensures that meta data of the corresponding result set has been already
109 * queried. It should be called before freeing the result set, unless the
110 * information is lost.
112 void ensureFieldInfoFetched();
115 * Check the following things:
116 * - cursor is out of range. Throws exception if true.
117 * - column index is out of range. Throws exception if true.
118 * - result set is fetched. If no, then it fetches the result.
120 void checkBordersAndEnsureFetched(sal_Int32 index);
123 * Fetches all the data from the MYSQL_RES object related to the class. It
124 * frees the MYSQL_RES object afterwards, so it cannot be used anymore.
126 void fetchResult();
128 public:
129 virtual OUString SAL_CALL getImplementationName() override;
131 virtual sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override;
133 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
135 OResultSet(OConnection& rConn, OCommonStatement* pStmt, MYSQL_RES* pResult,
136 rtl_TextEncoding _encoding);
138 // ::cppu::OComponentHelper
139 void SAL_CALL disposing() override;
141 // XInterface
142 Any SAL_CALL queryInterface(const css::uno::Type& rType) override;
144 void SAL_CALL acquire() throw() override;
145 void SAL_CALL release() throw() override;
147 //XTypeProvider
148 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
150 // XPropertySet
151 css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
153 // XResultSet
154 sal_Bool SAL_CALL next() override;
155 sal_Bool SAL_CALL isBeforeFirst() override;
156 sal_Bool SAL_CALL isAfterLast() override;
157 sal_Bool SAL_CALL isFirst() override;
158 sal_Bool SAL_CALL isLast() override;
160 void SAL_CALL beforeFirst() override;
161 void SAL_CALL afterLast() override;
163 sal_Bool SAL_CALL first() override;
164 sal_Bool SAL_CALL last() override;
166 sal_Int32 SAL_CALL getRow() override;
168 sal_Bool SAL_CALL absolute(sal_Int32 row) override;
169 sal_Bool SAL_CALL relative(sal_Int32 rows) override;
170 sal_Bool SAL_CALL previous() override;
172 void SAL_CALL refreshRow() override;
174 sal_Bool SAL_CALL rowUpdated() override;
175 sal_Bool SAL_CALL rowInserted() override;
176 sal_Bool SAL_CALL rowDeleted() override;
178 css::uno::Reference<css::uno::XInterface> SAL_CALL getStatement() override;
179 // XRow
180 sal_Bool SAL_CALL wasNull() override;
182 OUString SAL_CALL getString(sal_Int32 column) override;
184 sal_Bool SAL_CALL getBoolean(sal_Int32 column) override;
185 sal_Int8 SAL_CALL getByte(sal_Int32 column) override;
186 sal_Int16 SAL_CALL getShort(sal_Int32 column) override;
187 sal_Int32 SAL_CALL getInt(sal_Int32 column) override;
188 sal_Int64 SAL_CALL getLong(sal_Int32 column) override;
190 float SAL_CALL getFloat(sal_Int32 column) override;
191 double SAL_CALL getDouble(sal_Int32 column) override;
193 css::uno::Sequence<sal_Int8> SAL_CALL getBytes(sal_Int32 column) override;
194 css::util::Date SAL_CALL getDate(sal_Int32 column) override;
195 css::util::Time SAL_CALL getTime(sal_Int32 column) override;
196 css::util::DateTime SAL_CALL getTimestamp(sal_Int32 column) override;
198 css::uno::Reference<css::io::XInputStream> SAL_CALL getBinaryStream(sal_Int32 column) override;
199 css::uno::Reference<css::io::XInputStream>
200 SAL_CALL getCharacterStream(sal_Int32 column) override;
202 Any SAL_CALL getObject(
203 sal_Int32 column, const css::uno::Reference<css::container::XNameAccess>& typeMap) override;
205 css::uno::Reference<css::sdbc::XRef> SAL_CALL getRef(sal_Int32 column) override;
206 css::uno::Reference<css::sdbc::XBlob> SAL_CALL getBlob(sal_Int32 column) override;
207 css::uno::Reference<css::sdbc::XClob> SAL_CALL getClob(sal_Int32 column) override;
208 css::uno::Reference<css::sdbc::XArray> SAL_CALL getArray(sal_Int32 column) override;
210 // XResultSetMetaDataSupplier
211 css::uno::Reference<css::sdbc::XResultSetMetaData> SAL_CALL getMetaData() override;
213 // XCancellable
214 void SAL_CALL cancel() override;
216 // XCloseable
217 void SAL_CALL close() override;
219 // XWarningsSupplier
220 Any SAL_CALL getWarnings() override;
222 void SAL_CALL clearWarnings() override;
224 // XResultSetUpdate
225 void SAL_CALL insertRow() override;
226 void SAL_CALL updateRow() override;
227 void SAL_CALL deleteRow() override;
228 void SAL_CALL cancelRowUpdates() override;
229 void SAL_CALL moveToInsertRow() override;
230 void SAL_CALL moveToCurrentRow() override;
232 // XRowUpdate
233 void SAL_CALL updateNull(sal_Int32 column) override;
234 void SAL_CALL updateBoolean(sal_Int32 column, sal_Bool x) override;
235 void SAL_CALL updateByte(sal_Int32 column, sal_Int8 x) override;
236 void SAL_CALL updateShort(sal_Int32 column, sal_Int16 x) override;
237 void SAL_CALL updateInt(sal_Int32 column, sal_Int32 x) override;
238 void SAL_CALL updateLong(sal_Int32 column, sal_Int64 x) override;
239 void SAL_CALL updateFloat(sal_Int32 column, float x) override;
240 void SAL_CALL updateDouble(sal_Int32 column, double x) override;
241 void SAL_CALL updateString(sal_Int32 column, const OUString& x) override;
242 void SAL_CALL updateBytes(sal_Int32 column, const css::uno::Sequence<sal_Int8>& x) override;
243 void SAL_CALL updateDate(sal_Int32 column, const css::util::Date& x) override;
244 void SAL_CALL updateTime(sal_Int32 column, const css::util::Time& x) override;
245 void SAL_CALL updateTimestamp(sal_Int32 column, const css::util::DateTime& x) override;
246 void SAL_CALL updateBinaryStream(sal_Int32 column,
247 const css::uno::Reference<css::io::XInputStream>& x,
248 sal_Int32 length) override;
249 void SAL_CALL updateCharacterStream(sal_Int32 column,
250 const css::uno::Reference<css::io::XInputStream>& x,
251 sal_Int32 length) override;
252 void SAL_CALL updateObject(sal_Int32 column, const Any& x) override;
253 void SAL_CALL updateNumericObject(sal_Int32 column, const Any& x, sal_Int32 scale) override;
255 // XColumnLocate
256 sal_Int32 SAL_CALL findColumn(const OUString& columnName) override;
258 // XRowLocate
259 Any SAL_CALL getBookmark() override;
261 sal_Bool SAL_CALL moveToBookmark(const Any& bookmark) override;
262 sal_Bool SAL_CALL moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows) override;
263 sal_Int32 SAL_CALL compareBookmarks(const Any& first, const Any& second) override;
264 sal_Bool SAL_CALL hasOrderedBookmarks() override;
265 sal_Int32 SAL_CALL hashBookmark(const Any& bookmark) override;
267 // XDeleteRows
268 css::uno::Sequence<sal_Int32> SAL_CALL deleteRows(const css::uno::Sequence<Any>& rows) override;
270 void checkColumnIndex(sal_Int32 index);
271 void checkRowIndex();
273 private:
274 using ::cppu::OPropertySetHelper::getFastPropertyValue;
276 } /* mysqlc */
277 } /* connectivity */
278 #endif // CONNECTIVITY_SRESULTSET_HXX
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */