MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
bind.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 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,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License 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
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_BIND_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_BIND_H_
28
29#include <memory>
30#include <string>
31#include <vector>
32
33#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
34#include "my_rapidjson_size_t.h"
35#endif
36
37#include <rapidjson/fwd.h>
38
40#include "mysql.h"
41
42namespace mrs {
43namespace database {
44
45class MysqlBind {
46 public:
49
50 public:
51 void fill_mysql_bind_for_out(DataType data_type);
52
53 template <typename Value>
54 void fill_mysql_bind_for_inout(const Value &value_with_user_type,
55 DataType data_type) {
56 if (is_null(value_with_user_type)) {
57 fill_null_as_inout(data_type);
58 return;
59 }
60 if (data_type == DataType::VECTOR) {
61 fill_mysql_bind_inout_vector(value_with_user_type);
62 return;
63 }
64 fill_mysql_bind_impl(to_string(value_with_user_type), data_type);
65 }
66
67 void fill_null_as_inout(DataType data_type);
68
69 std::vector<MYSQL_BIND> parameters;
70
71 private:
72 void fill_mysql_bind_inout_vector(const rapidjson::Value &value);
73 void fill_mysql_bind_inout_vector(const std::string &value);
74 void fill_mysql_bind_impl(const std::string &value_with_user_type,
75 DataType data_type);
77 static const std::string &to_string(const std::string &value);
78 static std::string to_string(const rapidjson::Value &value);
79 static bool is_null(const std::string &value);
80 static bool is_null(const rapidjson::Value &value);
81
82 MYSQL_BIND *allocate_for_blob(const std::string &value);
83 MYSQL_BIND *allocate_for_string(const std::string &value);
84 MYSQL_BIND *allocate_for(const std::string &value);
86
87 std::vector<std::unique_ptr<char[]>> buffers_;
88 std::vector<std::unique_ptr<unsigned long>> lengths_;
89 std::vector<std::unique_ptr<bool>> nulls_;
90};
91
92} // namespace database
93} // namespace mrs
94
95#endif /* ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_BIND_H_ */
Definition: bind.h:45
std::vector< MYSQL_BIND > parameters
Definition: bind.h:69
static const std::string & to_string(const std::string &value)
Definition: bind.cc:182
std::vector< std::unique_ptr< unsigned long > > lengths_
Definition: bind.h:88
void fill_mysql_bind_inout_vector(const rapidjson::Value &value)
Definition: bind.cc:64
MYSQL_BIND * allocate_for_blob(const std::string &value)
Definition: bind.cc:192
void fill_mysql_bind_impl(const std::string &value_with_user_type, DataType data_type)
Definition: bind.cc:108
void fill_null_as_inout(DataType data_type)
Definition: bind.cc:45
static enum_field_types to_mysql_type(DataType pdt)
Definition: bind.cc:146
std::vector< std::unique_ptr< bool > > nulls_
Definition: bind.h:89
std::vector< std::unique_ptr< char[]> > buffers_
Definition: bind.h:87
void fill_mysql_bind_for_inout(const Value &value_with_user_type, DataType data_type)
Definition: bind.h:54
MYSQL_BIND * allocate_for(const std::string &value)
Definition: bind.cc:201
mrs::database::entry::ColumnType DataType
Definition: bind.h:48
static bool is_null(const std::string &value)
Definition: bind.cc:176
void fill_mysql_bind_for_out(DataType data_type)
Definition: bind.cc:56
MYSQL_BIND * allocate_bind_buffer(DataType data_type)
Definition: bind.cc:225
mrs::database::entry::Field::Mode Mode
Definition: bind.h:47
MYSQL_BIND * allocate_for_string(const std::string &value)
Definition: bind.cc:197
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
Define rapidjson::SizeType to be std::uint64_t.
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
ColumnType
Definition: column_type.h:48
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
mrs::database::entry::ColumnType DataType
Definition: sp_function_query.h:65
FilterObjectGenerator::Value Value
Definition: filter_object_generator.cc:51
Definition: authorize_manager.h:48
Definition: mysql.h:665
Mode
Definition: field.h:43