fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
RowSet.cpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 F.D.Castel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include "RowSet.h"
26#include "Client.h"
27#include "Statement.h"
28
29using namespace fbcpp;
30using namespace fbcpp::impl;
31
32
33RowSet::RowSet(Statement& statement, unsigned maxRows)
34 : client{&statement.getAttachment().getClient()},
35 statusWrapper{statement.getAttachment().getClient()},
36 numericConverter{statement.getAttachment().getClient()},
37 calendarConverter{statement.getAttachment().getClient()}
38{
39 assert(statement.isValid());
40 assert(statement.getResultSetHandle());
41
42 descriptors = statement.getOutputDescriptors();
43
44 auto outMetadata = statement.getOutputMetadata();
45 messageLength = outMetadata->getMessageLength(&statusWrapper);
46
47 buffer.resize(static_cast<std::size_t>(maxRows) * messageLength);
48
49 auto resultSet = statement.getResultSetHandle();
50 auto* dest = buffer.data();
51
52 for (unsigned i = 0; i < maxRows; ++i)
53 {
54 if (resultSet->fetchNext(&statusWrapper, dest) != fb::IStatus::RESULT_OK)
55 break;
56
57 dest += messageLength;
58 ++count;
59 }
60
61 buffer.resize(static_cast<std::size_t>(dest - buffer.data()));
62}
RowSet(Statement &statement, unsigned maxRows)
Fetches up to maxRows rows from the current result set of statement.
Definition RowSet.cpp:33
Prepares, executes, and fetches SQL statements against a Firebird attachment.
Definition Statement.h:262
const std::vector< Descriptor > & getOutputDescriptors() noexcept
Provides cached descriptors for each output column.
Definition Statement.h:452
bool isValid() noexcept
Returns whether the Statement object is valid.
Definition Statement.h:368
FbRef< fb::IResultSet > getResultSetHandle() noexcept
Provides access to the underlying Firebird currently open result set handle, if any.
Definition Statement.h:386
FbRef< fb::IMessageMetadata > getOutputMetadata() noexcept
Returns the metadata describing columns produced by the statement.
Definition Statement.h:410
fb-cpp namespace.
Definition Attachment.h:42