MySQL Connector/C++
MySQL connector library for C and C++ applications
row.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, 2024, 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, as
6 * 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, as
10 * 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 * Without limiting anything contained in the foregoing, this file,
17 * which is part of Connector/C++, is also subject to the
18 * Universal FOSS Exception, version 1.0, a copy of which can be found at
19 * https://oss.oracle.com/licenses/universal-foss-exception.
20 *
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License, version 2.0, for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation, Inc.,
28 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31#ifndef MYSQLX_ROW_H
32#define MYSQLX_ROW_H
33
40#include "common.h"
41#include "document.h"
42#include "detail/row.h"
43
44#include <memory>
45
46
47namespace mysqlx {
48MYSQLX_ABI_BEGIN(2,0)
49
50
51
70class Row
71 : private internal::Row_detail
72{
73
74 Row(internal::Row_detail &&other)
75 try
76 : Row_detail(std::move(other))
77 {}
78 CATCH_AND_WRAP
79
80
81public:
82
83 Row() {}
84
85 template<typename T, typename... Types>
86 explicit Row(T val, Types... vals)
87 {
88 try {
89 Row_detail::set_values(0, val, vals...);
90 }
91 CATCH_AND_WRAP
92 }
93
94
95 col_count_t colCount() const
96 {
97 try {
98 return Row_detail::col_count();
99 }
100 CATCH_AND_WRAP
101 }
102
103
144 bytes getBytes(col_count_t pos) const
145 {
146 try {
147 return Row_detail::get_bytes(pos);
148 }
149 CATCH_AND_WRAP
150 }
151
152
159 Value& get(col_count_t pos)
160 {
161 try {
162 return Row_detail::get_val(pos);
163 }
164 CATCH_AND_WRAP
165 }
166
167
176 Value& set(col_count_t pos, const Value &val)
177 {
178 try {
179 Row_detail::set_values(pos, val);
180 return Row_detail::get_val(pos);
181 }
182 CATCH_AND_WRAP
183 }
184
193 const Value& operator[](col_count_t pos) const
194 {
195 return const_cast<Row*>(this)->get(pos);
196 }
197
198
206 Value& operator[](col_count_t pos)
207 {
208 ensure_impl();
209 try {
210 return get(pos);
211 }
212 catch (const out_of_range&)
213 {
214 return set(pos, Value());
215 }
216 }
217
219 bool isNull() const { return NULL == m_impl; }
220 operator bool() const { return !isNull(); }
221
222 void clear()
223 {
224 try {
225 Row_detail::clear();
226 }
227 CATCH_AND_WRAP
228 }
229
230private:
231
232 using internal::Row_detail::m_impl;
233
235 friend internal::Row_result_detail<Columns>;
236 friend internal::Table_insert_detail;
238};
239
240
241MYSQLX_ABI_END(2,0)
242} // mysqlx
243
244#endif
Represents a single row from a result that contains rows.
Definition: row.h:72
bool isNull() const
Check if this row contains fields or is null.
Definition: row.h:219
Value & get(col_count_t pos)
Get reference to row field at position pos.
Definition: row.h:159
Value & set(col_count_t pos, const Value &val)
Set value of row field at position pos.
Definition: row.h:176
bytes getBytes(col_count_t pos) const
Get raw bytes representing value of row field at position pos.
Definition: row.h:144
Value & operator[](col_count_t pos)
Get modifiable reference to row field at position pos.
Definition: row.h:206
const Value & operator[](col_count_t pos) const
Get const reference to row field at position pos.
Definition: row.h:193
Value object can store value of scalar type, string, array or document.
Definition: document.h:230
Class representing a region of memory holding raw bytes.
Definition: common.h:298
Details for Row class.
Declaration of DbDoc and related classes.