MySQL 8.0.39
Source Code Documentation
storing_auto_thd.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 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 STORING_AUTO_THD_H
25#define STORING_AUTO_THD_H
26
27#include <sql/auto_thd.h>
28#include <sql/current_thd.h>
29#include <sql/sql_lex.h>
31#include "sql/auth/auth_acls.h"
32
35
36/**
37 A version of Auto_THD that:
38 - doesn't catch or print the error onto the error log but just passes it up
39 - stores and restores the current_thd correctly
40*/
44
45 public:
48 /* Allocate thread local memory if necessary. */
49 if (!m_previous_thd) {
51 }
53 }
54
56 if (m_previous_thd) {
58 Diagnostics_area *curr_da = thd->get_stmt_da();
59 /* We need to put any errors in the DA as well as the condition list. */
60 if (curr_da->is_error())
61 prev_da->set_error_status(curr_da->mysql_errno(),
62 curr_da->message_text(),
63 curr_da->returned_sqlstate());
64
66 }
68 if (!m_previous_thd) {
70 }
71 if (m_previous_thd) {
73 }
74 }
75 THD *get_THD() { return thd; }
76};
77
78#endif /* STORING_AUTO_THD_H */
std::unique_ptr< T, std::function< void(T *)> > Sctx_ptr
Definition: auth_common.h:963
Stores status of the currently executed statement.
Definition: sql_error.h:269
void set_error_status(THD *thd, uint mysql_errno)
Set ERROR status in the Diagnostics Area.
Definition: sql_error.cc:418
bool is_error() const
Definition: sql_error.h:366
const char * message_text() const
Definition: sql_error.h:376
uint mysql_errno() const
Definition: sql_error.h:386
void copy_sql_conditions_from_da(THD *thd, const Diagnostics_area *src_da)
Copy all SQL-conditions from src_da to this DA.
Definition: sql_error.cc:531
const char * returned_sqlstate() const
Definition: sql_error.h:391
A version of Auto_THD that:
Definition: storing_auto_thd.h:41
Storing_auto_THD()
Definition: storing_auto_thd.h:46
THD * get_THD()
Definition: storing_auto_thd.h:75
THD * m_previous_thd
Definition: storing_auto_thd.h:42
~Storing_auto_THD()
Definition: storing_auto_thd.h:55
THD * thd
Definition: storing_auto_thd.h:42
Sctx_ptr< Security_context > ctx
Definition: storing_auto_thd.h:43
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
void store_globals()
Definition: sql_class.cc:1684
Diagnostics_area * get_stmt_da()
Returns first Diagnostics Area for the current statement.
Definition: sql_class.h:3212
thread_local THD * current_thd
Definition: current_thd.cc:26
bool my_thread_init()
Allocate thread specific memory for the thread, used by mysys and dbug.
Definition: my_thr_init.cc:269
void my_thread_end()
Deallocate memory used by the thread for book-keeping.
Definition: my_thr_init.cc:304
THD * create_internal_thd_ctx(Sctx_ptr< Security_context > &ctx)
Wrapper of create_internal_thd() function, creating a temporary THD with the following differences co...
Definition: storing_auto_thd.cc:36
void destroy_internal_thd_ctx(THD *thd, Sctx_ptr< Security_context > &ctx)
Wrapper of destroy_internal_thd() function, safely destroying a temporary THD and its associated secu...
Definition: storing_auto_thd.cc:74