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