forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_service.cc
80 lines (67 loc) · 3.26 KB
/
command_service.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; version 2 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "mysql/service_command.h"
#include "srv_session.h"
/**
@file
Command service implementation. For more information please check
the function comments.
*/
/**
Executes a server command in a session.
There are two cases. Execution in a physical thread :
1. initialized by the srv_session service
2. NOT initialized by the srv_session service
In case of 1, if there is currently attached session, and it is
different from the passed one, the former will be automatically
detached. The session to be used for the execution will then be
attached. After the command is executed, the attached session will
not be detached. It will be detached by a next call to run_command()
with another session as parameter. In other words, for all sessions
used in a physical thread, there will be at most one in attached
state.
In case of 2, the current state (current_thd) will be
preserved. Then the given session will move to attached state and
the command will be executed. After the execution the state of the
session will be changed to detached and the preserved state
(current_thd) will be restored.
The client charset is used for commands like COM_QUERY and
COM_STMT_PREPARE to know how to threat the char* fields. This
charset will be used until the next call of run_command when it may
be changed again.
@param session The session
@param command The command to be executed.
@param data The data needed for the command to be executed
@param client_cs The charset for the string data input(COM_QUERY for example)
@param callbacks Callbacks to be used by the server to encode data and
to communicate with the client (plugin) side.
@param text_or_binary See enum cs_text_or_binary
@param service_callbacks_ctx Context passed to the command service callbacks
@return
0 success
1 failure
*/
extern "C"
int command_service_run_command(Srv_session *session,
enum enum_server_command command,
const union COM_DATA * data,
const CHARSET_INFO * client_cs,
const struct st_command_service_cbs *callbacks,
enum cs_text_or_binary text_or_binary,
void * service_callbacks_ctx)
{
if (!session || !Srv_session::is_valid(session))
return true;
return session->execute_command(command, data, client_cs, callbacks,
text_or_binary, service_callbacks_ctx);
}