MySQL 9.1.0
Source Code Documentation
ed_connection.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_ED_CONNECTION_H
25#define SQL_ED_CONNECTION_H
26
27#include "sql/sql_class.h"
28#include "sql/sql_error.h"
30
31class Server_runnable;
32
33class Ed_connection final {
34 public:
35 /**
36 Construct a new "execute direct" connection.
37
38 The connection can be used to execute SQL statements.
39 If the connection failed to initialize, the error
40 will be returned on the attempt to execute a statement.
41
42 @pre thd must have no open tables
43 while the connection is used. However,
44 Ed_connection works okay in LOCK TABLES mode.
45 Other properties of THD, such as the current warning
46 information, errors, etc. do not matter and are
47 preserved by Ed_connection. One thread may have many
48 Ed_connections created for it.
49 */
50 Ed_connection(THD *thd);
51
52 /**
53 Execute one SQL statement.
54
55 Until this method is executed, no other methods of
56 Ed_connection can be used. Life cycle of Ed_connection is:
57
58 Initialized -> a statement has been executed ->
59 look at result, move to next result ->
60 look at result, move to next result ->
61 ...
62 moved beyond the last result == Initialized.
63
64 This method can be called repeatedly. Once it's invoked,
65 results of the previous execution are lost.
66
67 A result of execute_direct() can be either:
68
69 - success, no result set rows. In this case get_field_count()
70 returns 0. This happens after execution of INSERT, UPDATE,
71 DELETE, DROP and similar statements. Some other methods, such
72 as get_affected_rows() can be used to retrieve additional
73 result information.
74
75 - success, there are some result set rows (maybe 0). E.g.
76 happens after SELECT. In this case get_field_count() returns
77 the number of columns in a result set and store_result()
78 can be used to retrieve a result set..
79
80 - an error, methods to retrieve error information can
81 be used.
82
83 @return execution status
84 @retval false success, use get_field_count()
85 to determine what to do next.
86 @retval true error, use get_last_error()
87 to see the error number.
88 */
89 bool execute_direct(LEX_STRING sql_text);
90
91 /**
92 Same as the previous, but takes an instance of Server_runnable
93 instead of SQL statement text.
94
95 @return execution status
96
97 @retval false success, use get_field_count()
98 if your code fragment is supposed to
99 return a result set
100 @retval true failure
101 */
102 bool execute_direct(Server_runnable *server_runnable);
103
104 /**
105 The following three members are only valid if execute_direct()
106 or move_to_next_result() returned an error.
107 They never fail, but if they are called when there is no
108 result, or no error, the result is not defined.
109 */
110 const char *get_last_error() const {
112 }
113
114 unsigned int get_last_errno() const {
116 }
117
119
121
122 private:
124 /**
125 Execute direct interface does not support multi-statements, only
126 multi-results. So we never have a situation when we have
127 a mix of result sets and OK or error packets. We either
128 have a single result set, a single error, or a single OK,
129 or we have a series of result sets, followed by an OK or error.
130 */
134 friend class Protocol_local;
135
136 private:
137 void free_old_result();
138 void add_result_set(Ed_result_set *ed_result_set);
139
140 private:
141 Ed_connection(const Ed_connection &); /* not implemented */
142 Ed_connection &operator=(Ed_connection &); /* not implemented */
143};
144
145#endif
Stores status of the currently executed statement.
Definition: sql_error.h:269
const char * message_text() const
Definition: sql_error.h:376
uint mysql_errno() const
Definition: sql_error.h:386
Definition: ed_connection.h:33
Diagnostics_area m_diagnostics_area
Definition: ed_connection.h:123
Ed_connection(THD *thd)
Construct a new "execute direct" connection.
Definition: ed_connection.cc:34
Ed_result_set * m_rsets
Definition: ed_connection.h:132
unsigned int get_last_errno() const
Definition: ed_connection.h:114
~Ed_connection()
Definition: ed_connection.h:120
bool execute_direct(LEX_STRING sql_text)
Execute one SQL statement.
Definition: ed_connection.cc:62
Ed_result_set * m_current_rset
Definition: ed_connection.h:133
Ed_connection & operator=(Ed_connection &)
Ed_connection(const Ed_connection &)
const char * get_last_error() const
The following three members are only valid if execute_direct() or move_to_next_result() returned an e...
Definition: ed_connection.h:110
void free_old_result()
Free all result sets of the previous statement, if any, and reset warnings and errors.
Definition: ed_connection.cc:47
Ed_result_set * get_result_sets()
Definition: ed_connection.h:118
THD * m_thd
Execute direct interface does not support multi-statements, only multi-results.
Definition: ed_connection.h:131
void add_result_set(Ed_result_set *ed_result_set)
A helper method that is called only during execution.
Definition: ed_connection.cc:125
Ed_result_set – a container with result set rows.
Definition: protocol_local.h:66
Protocol_local: a helper class to intercept the result of the data written to the network.
Definition: protocol_local.h:126
Execute a fragment of server code in an isolated context, so that it doesn't leave any effect on THD.
Definition: statement_runnable.h:42
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: mysql_lex_string.h:35