MySQL 9.1.0
Source Code Documentation
sql_parser_state.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 2024, 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 ROUTING_SQL_PARSER_STATE_INCLUDED
27#define ROUTING_SQL_PARSER_STATE_INCLUDED
28
29#include <string_view>
30
31#include "my_alloc.h" // MEM_ROOT
32#include "sql_lexer.h"
33#include "sql_lexer_thd.h" // THD
34
36 public:
40 }
41
42 void statement(std::string_view stmt) {
43 // copy the string as the lexer needs a trailing \0
44 stmt_ = stmt;
45
46 parser_state_.init(&session_, stmt_.data(), stmt_.size());
47 }
48
49 SqlLexer lexer(bool reset_state = true) {
50 if (reset_state) parser_state_.reset(stmt_.data(), stmt_.size());
51
52 return {&session_};
53 }
54
55 THD *thd() { return &session_; }
56
58
59 private:
63
64 std::string stmt_;
65};
66
67#endif
Internal state of the parser.
Definition: sql_lexer_parser_state.h:44
void reset(const char *found_semicolon, size_t length)
Definition: sql_lexer_parser_state.h:67
bool init(THD *thd, const char *buff, size_t length)
Object initializer.
Definition: sql_lexer_parser_state.h:63
Definition: sql_lexer.h:35
Definition: sql_parser_state.h:35
MEM_ROOT mem_root_
Definition: sql_parser_state.h:60
THD * thd()
Definition: sql_parser_state.h:55
std::string stmt_
Definition: sql_parser_state.h:64
SqlParserState()
Definition: sql_parser_state.h:37
Parser_state * parser_state()
Definition: sql_parser_state.h:57
void statement(std::string_view stmt)
Definition: sql_parser_state.h:42
SqlLexer lexer(bool reset_state=true)
Definition: sql_parser_state.h:49
THD session_
Definition: sql_parser_state.h:61
Parser_state parser_state_
Definition: sql_parser_state.h:62
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Parser_state * m_parser_state
Internal parser state.
Definition: sql_lexer_thd.h:66
MEM_ROOT * mem_root
Definition: sql_lexer_thd.h:40
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void reset_state(task_env *p)
Definition: task.cc:661