MySQL 8.4.0
Source Code Documentation
sql_servers.h
Go to the documentation of this file.
1#ifndef SQL_SERVERS_INCLUDED
2#define SQL_SERVERS_INCLUDED
3
4/* Copyright (c) 2006, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <stddef.h>
28
29#include "lex_string.h"
30#include "my_sqlcommand.h"
31#include "sql/sql_cmd.h" // Sql_cmd
32
33class THD;
34struct MEM_ROOT;
35struct TABLE;
36
38 public:
40 long port;
43
46 port(-1),
48 db(nullptr),
55 sport(nullptr) {}
56};
57
58/* cache handlers */
59bool servers_init(THD *thd);
60bool servers_reload(THD *thd);
61void servers_free(bool end = false);
62
63/* lookup functions */
64FOREIGN_SERVER *get_server_by_name(MEM_ROOT *mem, const char *server_name,
65 FOREIGN_SERVER *server_buffer);
66
67/**
68 This class represent server options as set by the parser.
69 */
70
72 public:
73 static const long PORT_NOT_SET = -1;
75
76 private:
77 long m_port;
85
86 public:
87 void set_port(long port) { m_port = port; }
89 void set_db(LEX_STRING db) { m_db = db; }
90 void set_username(LEX_STRING username) { m_username = username; }
92 void set_scheme(LEX_STRING scheme) { m_scheme = scheme; }
94 void set_owner(LEX_STRING owner) { m_owner = owner; }
95
96 long get_port() const { return m_port; }
97 const char *get_host() const { return m_host.str; }
98 const char *get_db() const { return m_db.str; }
99 const char *get_username() const { return m_username.str; }
100 const char *get_password() const { return m_password.str; }
101 const char *get_scheme() const { return m_scheme.str; }
102 const char *get_socket() const { return m_socket.str; }
103 const char *get_owner() const { return m_owner.str; }
104
105 /**
106 Reset all strings to NULL and port to PORT_NOT_SET.
107 This prepares the structure for being used by a new statement.
108 */
109 void reset();
110
111 /**
112 Create a cache entry and insert it into the cache.
113
114 @returns false if entry was created and inserted, true otherwise.
115 */
116 bool insert_into_cache() const;
117
118 /**
119 Update a cache entry.
120
121 @param existing Cache entry to update
122
123 @returns false if the entry was updated, true otherwise.
124 */
125 bool update_cache(FOREIGN_SERVER *existing) const;
126
127 /**
128 Create a record representing these server options,
129 ready to be inserted into the mysql.servers table.
130
131 @param table Table to be inserted into.
132 */
133 void store_new_server(TABLE *table) const;
134
135 /**
136 Create a record for updating a row in the mysql.servers table.
137
138 @param table Table to be updated.
139 @param existing Cache entry represeting the existing values.
140 */
141 void store_altered_server(TABLE *table, FOREIGN_SERVER *existing) const;
142};
143
144/**
145 This class has common code for CREATE/ALTER/DROP SERVER statements.
146*/
147
149 protected:
151
153
154 ~Sql_cmd_common_server() override = default;
155
156 /**
157 Check permissions and open the mysql.servers table.
158
159 @param thd Thread context
160
161 @returns false if success, true otherwise
162 */
163 bool check_and_open_table(THD *thd);
164};
165
166/**
167 This class implements the CREATE SERVER statement.
168*/
169
171 /**
172 Server_options::m_server_name contains the name of the
173 server to create. The remaining Server_options fields
174 contain options as set by the parser.
175 Unset options are NULL (or PORT_NOT_SET for port).
176 */
178
179 public:
181 : Sql_cmd_common_server(), m_server_options(server_options) {}
182
185 }
186
187 /**
188 Create a new server by inserting a row into the
189 mysql.server table and creating a cache entry.
190
191 @param thd Thread context
192
193 @returns false if success, true otherwise
194 */
195 bool execute(THD *thd) override;
196};
197
198/**
199 This class implements the ALTER SERVER statement.
200*/
201
203 /**
204 Server_options::m_server_name contains the name of the
205 server to change. The remaining Server_options fields
206 contain changed options as set by the parser.
207 Unchanged options are NULL (or PORT_NOT_SET for port).
208 */
210
211 public:
213 : Sql_cmd_common_server(), m_server_options(server_options) {}
214
216 return SQLCOM_ALTER_SERVER;
217 }
218
219 /**
220 Alter an existing server by updating the matching row in the
221 mysql.servers table and updating the cache entry.
222
223 @param thd Thread context
224
225 @returns false if success, true otherwise
226 */
227 bool execute(THD *thd) override;
228};
229
230/**
231 This class implements the DROP SERVER statement.
232*/
233
235 /// Name of server to drop
237
238 /// Is this DROP IF EXISTS?
240
241 public:
242 Sql_cmd_drop_server(LEX_STRING server_name, bool if_exists)
244 m_server_name(server_name),
245 m_if_exists(if_exists) {}
246
248 return SQLCOM_DROP_SERVER;
249 }
250
251 /**
252 Drop an existing server by deleting the matching row from the
253 mysql.servers table and removing the cache entry.
254
255 @param thd Thread context
256
257 @returns false if success, true otherwise
258 */
259 bool execute(THD *thd) override;
260};
261
262#endif /* SQL_SERVERS_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: sql_servers.h:37
FOREIGN_SERVER()
Definition: sql_servers.h:44
char * sport
Definition: sql_servers.h:42
char * password
Definition: sql_servers.h:42
char * server_name
Definition: sql_servers.h:39
char * scheme
Definition: sql_servers.h:42
char * owner
Definition: sql_servers.h:42
size_t server_name_length
Definition: sql_servers.h:41
char * socket
Definition: sql_servers.h:42
char * host
Definition: sql_servers.h:42
char * username
Definition: sql_servers.h:42
long port
Definition: sql_servers.h:40
char * db
Definition: sql_servers.h:42
This class represent server options as set by the parser.
Definition: sql_servers.h:71
void set_scheme(LEX_STRING scheme)
Definition: sql_servers.h:92
LEX_STRING m_password
Definition: sql_servers.h:81
const char * get_host() const
Definition: sql_servers.h:97
static const long PORT_NOT_SET
Definition: sql_servers.h:73
void store_new_server(TABLE *table) const
Create a record representing these server options, ready to be inserted into the mysql....
Definition: sql_servers.cc:594
const char * get_scheme() const
Definition: sql_servers.h:101
void set_host(LEX_STRING host)
Definition: sql_servers.h:88
void set_socket(LEX_STRING socket)
Definition: sql_servers.h:93
void reset()
Reset all strings to NULL and port to PORT_NOT_SET.
Definition: sql_servers.cc:463
void set_port(long port)
Definition: sql_servers.h:87
const char * get_password() const
Definition: sql_servers.h:100
void set_db(LEX_STRING db)
Definition: sql_servers.h:89
const char * get_socket() const
Definition: sql_servers.h:102
LEX_STRING m_socket
Definition: sql_servers.h:83
LEX_STRING m_host
Definition: sql_servers.h:78
LEX_STRING m_username
Definition: sql_servers.h:80
void store_altered_server(TABLE *table, FOREIGN_SERVER *existing) const
Create a record for updating a row in the mysql.servers table.
Definition: sql_servers.cc:627
bool insert_into_cache() const
Create a cache entry and insert it into the cache.
Definition: sql_servers.cc:483
void set_username(LEX_STRING username)
Definition: sql_servers.h:90
void set_owner(LEX_STRING owner)
Definition: sql_servers.h:94
LEX_STRING m_db
Definition: sql_servers.h:79
LEX_STRING m_server_name
Definition: sql_servers.h:74
const char * get_owner() const
Definition: sql_servers.h:103
long m_port
Definition: sql_servers.h:77
const char * get_db() const
Definition: sql_servers.h:98
bool update_cache(FOREIGN_SERVER *existing) const
Update a cache entry.
Definition: sql_servers.cc:529
void set_password(LEX_STRING password)
Definition: sql_servers.h:91
LEX_STRING m_scheme
Definition: sql_servers.h:82
const char * get_username() const
Definition: sql_servers.h:99
long get_port() const
Definition: sql_servers.h:96
LEX_STRING m_owner
Definition: sql_servers.h:84
This class implements the ALTER SERVER statement.
Definition: sql_servers.h:202
const Server_options * m_server_options
Server_options::m_server_name contains the name of the server to change.
Definition: sql_servers.h:209
Sql_cmd_alter_server(Server_options *server_options)
Definition: sql_servers.h:212
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_servers.h:215
bool execute(THD *thd) override
Alter an existing server by updating the matching row in the mysql.servers table and updating the cac...
Definition: sql_servers.cc:747
This class has common code for CREATE/ALTER/DROP SERVER statements.
Definition: sql_servers.h:148
TABLE * table
Definition: sql_servers.h:150
Sql_cmd_common_server()
Definition: sql_servers.h:152
~Sql_cmd_common_server() override=default
bool check_and_open_table(THD *thd)
Check permissions and open the mysql.servers table.
Definition: sql_servers.cc:644
This class implements the CREATE SERVER statement.
Definition: sql_servers.h:170
bool execute(THD *thd) override
Create a new server by inserting a row into the mysql.server table and creating a cache entry.
Definition: sql_servers.cc:679
Sql_cmd_create_server(Server_options *server_options)
Definition: sql_servers.h:180
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_servers.h:183
const Server_options * m_server_options
Server_options::m_server_name contains the name of the server to create.
Definition: sql_servers.h:177
This class implements the DROP SERVER statement.
Definition: sql_servers.h:234
bool execute(THD *thd) override
Drop an existing server by deleting the matching row from the mysql.servers table and removing the ca...
Definition: sql_servers.cc:824
Sql_cmd_drop_server(LEX_STRING server_name, bool if_exists)
Definition: sql_servers.h:242
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_servers.h:247
bool m_if_exists
Is this DROP IF EXISTS?
Definition: sql_servers.h:239
LEX_STRING m_server_name
Name of server to drop.
Definition: sql_servers.h:236
Representation of an SQL command.
Definition: sql_cmd.h:83
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_ALTER_SERVER
Definition: my_sqlcommand.h:168
@ SQLCOM_DROP_SERVER
Definition: my_sqlcommand.h:167
@ SQLCOM_CREATE_SERVER
Definition: my_sqlcommand.h:166
static char * password
Definition: mysql_secure_installation.cc:58
const char * host
Definition: mysqladmin.cc:65
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:63
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Representation of an SQL command.
static MEM_ROOT mem
Definition: sql_servers.cc:100
FOREIGN_SERVER * get_server_by_name(MEM_ROOT *mem, const char *server_name, FOREIGN_SERVER *server_buffer)
Definition: sql_servers.cc:940
void servers_free(bool end=false)
Definition: sql_servers.cc:882
bool servers_init(THD *thd)
Definition: sql_servers.cc:192
bool servers_reload(THD *thd)
Definition: sql_servers.cc:285
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:35
char * str
Definition: mysql_lex_string.h:36
Definition: table.h:1405