MySQL 9.3.0
Source Code Documentation
result.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26// MySQL DB access module, for use by plugins and others
27// For the module that implements interactive DB functionality see mod_db
28
29#ifndef MYSQLSHDK_LIBS_DB_MYSQL_RESULT_H_
30#define MYSQLSHDK_LIBS_DB_MYSQL_RESULT_H_
31
33
34#include <atomic>
35#include <deque>
36#include <list>
37#include <memory>
38#include <optional>
39#include <string>
40#include <vector>
41
42#include <mysql.h>
43
44#include "database/column.h"
46#include "database/row_copy.h"
47
48#include "utils/atomic_flag.h"
49
50namespace shcore {
51namespace polyglot {
52namespace database {
53
57
58class Session;
59class Row;
60
61class DbResult : public IResult, public std::enable_shared_from_this<DbResult> {
62 friend class Session;
63
64 public:
65 ~DbResult() override;
66
67 // Data Retrieving
68 const jit_executor::db::IRow *fetch_one() override;
69 bool next_resultset() override;
70 std::unique_ptr<jit_executor::db::Warning> fetch_one_warning() override;
71
72 // Metadata retrieval
73 int64_t get_auto_increment_value() const override { return _last_insert_id; }
74 bool has_resultset() override { return _has_resultset; }
75 uint64_t get_affected_row_count() const override {
76 return (_affected_rows == ~(my_ulonglong)0) ? 0 : _affected_rows;
77 }
78 uint64_t get_fetched_row_count() const override { return _fetched_row_count; }
79 uint64_t get_warning_count() const override;
80 std::string get_info() const override { return _info; }
81 const std::vector<std::string> &get_gtids() const override { return _gtids; }
82 const std::vector<std::shared_ptr<IColumn>> &get_metadata() const override {
83 return _metadata;
84 }
85 std::string get_statement_id() const override;
86
87 void buffer() override;
88 void rewind() override;
89
90 bool is_buffered() { return m_buffered; }
91
92 protected:
93 DbResult(std::shared_ptr<Session> owner, uint64_t affected_rows,
94 uint64_t last_insert_id, const char *info, bool buffered);
95 void reset(std::shared_ptr<MYSQL_RES> res);
96
97 std::deque<Row_copy> _pre_fetched_rows;
98 // size_t _fetched_warning_count = 0;
99 shcore::atomic_flag _stop_pre_fetch;
100 bool _pre_fetched = false;
103
104 bool pre_fetch_row();
105 bool pre_fetch_rows(bool persistent);
106 void stop_pre_fetch();
107
108 void fetch_metadata();
109 void fetch_statement_id();
110
111 // TODO(rennox) enable collation handling
112 Type map_data_type(int raw_type, int flags /*, int collation_id*/);
113
114 virtual std::shared_ptr<Field_names> field_names() const;
115
116 std::weak_ptr<shcore::polyglot::database::Session> _session;
117 std::vector<std::shared_ptr<IColumn>> _metadata;
118 std::unique_ptr<Row> _row;
119 std::weak_ptr<MYSQL_RES> _result;
120 std::vector<std::string> _gtids;
121 mutable std::shared_ptr<Field_names> _field_names;
122 uint64_t _affected_rows = 0;
123 uint64_t _last_insert_id = 0;
124 uint64_t _fetched_row_count = 0;
125 std::string _info;
126 std::list<std::unique_ptr<Warning>> _warnings;
127 bool _has_resultset = false;
128 bool _fetched_warnings = false;
129 bool m_buffered = false;
130 std::optional<std::string> m_statement_id;
131};
132} // namespace database
133} // namespace polyglot
134} // namespace shcore
135#endif // MYSQLSHDK_LIBS_DB_MYSQL_RESULT_H_
A row of result or a row of metadata A row is a collection of Column values or Column metadata.
Definition: protocol_local_v2.h:92
Definition: jit_executor_db_interface.h:57
Definition: jit_executor_db_interface.h:151
Definition: jit_executor_db_interface.h:82
std::unique_ptr< Row > _row
Definition: result.h:118
uint64_t _affected_rows
Definition: result.h:122
virtual std::shared_ptr< Field_names > field_names() const
Definition: result.cc:394
DbResult(std::shared_ptr< Session > owner, uint64_t affected_rows, uint64_t last_insert_id, const char *info, bool buffered)
Definition: result.cc:45
std::deque< Row_copy > _pre_fetched_rows
Definition: result.h:97
uint64_t get_affected_row_count() const override
Definition: result.h:75
bool next_resultset() override
Definition: result.cc:274
uint64_t _fetched_row_count
Definition: result.h:124
std::weak_ptr< MYSQL_RES > _result
Definition: result.h:119
uint64_t _last_insert_id
Definition: result.h:123
const std::vector< std::string > & get_gtids() const override
Definition: result.h:81
std::string get_statement_id() const override
Definition: result.cc:270
const jit_executor::db::IRow * fetch_one() override
Definition: result.cc:192
void fetch_metadata()
Definition: result.cc:157
const std::vector< std::shared_ptr< IColumn > > & get_metadata() const override
Definition: result.h:82
std::string get_info() const override
Definition: result.h:80
bool m_buffered
Definition: result.h:129
bool has_resultset() override
Definition: result.h:74
std::vector< std::shared_ptr< IColumn > > _metadata
Definition: result.h:117
bool _pre_fetched
Definition: result.h:100
uint64_t get_warning_count() const override
Definition: result.cc:296
uint64_t get_fetched_row_count() const override
Definition: result.h:78
std::vector< std::string > _gtids
Definition: result.h:120
void rewind() override
Definition: result.cc:288
bool pre_fetch_row()
Definition: result.cc:361
shcore::atomic_flag _stop_pre_fetch
Definition: result.h:99
bool pre_fetch_rows(bool persistent)
Definition: result.cc:375
std::optional< std::string > m_statement_id
Definition: result.h:130
bool _persistent_pre_fetch
Definition: result.h:101
void buffer() override
Definition: result.cc:353
bool _pre_fetched_clear_at_end
Definition: result.h:102
bool _fetched_warnings
Definition: result.h:128
Type map_data_type(int raw_type, int flags)
Definition: result.cc:404
void fetch_statement_id()
Definition: result.cc:262
bool _has_resultset
Definition: result.h:127
std::unique_ptr< jit_executor::db::Warning > fetch_one_warning() override
Definition: result.cc:301
std::shared_ptr< Field_names > _field_names
Definition: result.h:121
std::weak_ptr< shcore::polyglot::database::Session > _session
Definition: result.h:116
std::list< std::unique_ptr< Warning > > _warnings
Definition: result.h:126
std::string _info
Definition: result.h:125
bool is_buffered()
Definition: result.h:90
void reset(std::shared_ptr< MYSQL_RES > res)
Definition: result.cc:333
void stop_pre_fetch()
Definition: result.cc:392
int64_t get_auto_increment_value() const override
Definition: result.h:73
Definition: session.h:59
mrs::interface::RestHandler::HttpResult::Type Type
Definition: handler_content_file.cc:42
static int flags[50]
Definition: hp_test1.cc:40
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
uint64_t my_ulonglong
Definition: mysql.h:54
AuthorizeManager::Session Session
Definition: authorize_manager.cc:75
Definition: file_system_exceptions.h:34
Definition: jit_executor_db_interface.h:144