520.6.3
by Monty Taylor
Moved scheduler.h out of common_includes. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
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 as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
1055.2.13
by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore. |
20 |
/**
|
21 |
* @file Implementation of the Session class and API
|
|
22 |
*/
|
|
23 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
24 |
#include "config.h" |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
25 |
#include <drizzled/session.h> |
1241.9.17
by Monty Taylor
Removed more bits from server_includes. |
26 |
#include "drizzled/session_list.h" |
1
by brian
clean slate |
27 |
#include <sys/stat.h> |
549
by Monty Taylor
Took gettext.h out of header files. |
28 |
#include <drizzled/error.h> |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
29 |
#include <drizzled/gettext.h> |
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
30 |
#include <drizzled/query_id.h> |
520.6.7
by Monty Taylor
Moved a bunch of crap out of common_includes. |
31 |
#include <drizzled/data_home.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
32 |
#include <drizzled/sql_base.h> |
670.2.4
by Monty Taylor
Removed more stuff from the headers. |
33 |
#include <drizzled/lock.h> |
675
by Brian Aker
Cleanup around item includes. |
34 |
#include <drizzled/item/cache.h> |
676
by Brian Aker
Merge of Monty's work. |
35 |
#include <drizzled/item/float.h> |
642.1.17
by Lee
header file clean up |
36 |
#include <drizzled/item/return_int.h> |
675
by Brian Aker
Cleanup around item includes. |
37 |
#include <drizzled/item/empty_string.h> |
793
by Brian Aker
Pass through on refactoring functions to clases. |
38 |
#include <drizzled/show.h> |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
39 |
#include <drizzled/plugin/client.h> |
1130.1.3
by Monty Taylor
Merged up with trunk. |
40 |
#include "drizzled/plugin/scheduler.h" |
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
41 |
#include "drizzled/plugin/authentication.h" |
1316.1.1
by Joe Daly
add plugin handle to logging to indicate when the session destructor is called |
42 |
#include "drizzled/plugin/logging.h" |
1273.1.15
by Jay Pipes
This patch completes the first step in the splitting of |
43 |
#include "drizzled/plugin/transactional_storage_engine.h" |
1126.10.18
by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled. |
44 |
#include "drizzled/probes.h" |
1130.3.9
by Monty Taylor
Wrapped table_proto_write.cc code in namespace drizzled. |
45 |
#include "drizzled/table_proto.h" |
1235.4.23
by Stewart Smith
fix includes for drizzled/db.h. Now only in .cc files, no header files. should make modifying db.h much less painful. |
46 |
#include "drizzled/db.h" |
1241.9.31
by Monty Taylor
Moved global pthread variables into their own header. |
47 |
#include "drizzled/pthread_globals.h" |
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
48 |
#include "drizzled/transaction_services.h" |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
49 |
#include "drizzled/drizzled.h" |
1241.9.31
by Monty Taylor
Moved global pthread variables into their own header. |
50 |
|
1532.1.1
by Brian Aker
Merge of change to flip table instance to be share instance |
51 |
#include "drizzled/table_share_instance.h" |
52 |
||
1241.9.62
by Monty Taylor
Removed plugin/myisam/myisam.h from session.h |
53 |
#include "plugin/myisam/myisam.h" |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
54 |
#include "drizzled/internal/iocache.h" |
1502.5.7
by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer. |
55 |
#include "drizzled/plugin/event_observer.h" |
1
by brian
clean slate |
56 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
57 |
#include <fcntl.h> |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
58 |
#include <algorithm> |
1241.9.24
by Monty Taylor
Removed m_string.h from server_includes.h. |
59 |
#include <climits> |
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
60 |
|
61 |
using namespace std; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
62 |
namespace drizzled |
63 |
{
|
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
64 |
|
1
by brian
clean slate |
65 |
/*
|
66 |
The following is used to initialise Table_ident with a internal
|
|
67 |
table name
|
|
68 |
*/
|
|
69 |
char internal_table_name[2]= "*"; |
|
70 |
char empty_c_string[1]= {0}; /* used for not defined db */ |
|
71 |
||
520.1.21
by Brian Aker
THD -> Session rename |
72 |
const char * const Session::DEFAULT_WHERE= "field list"; |
670.2.1
by Monty Taylor
Moved pthread keys |
73 |
extern pthread_key_t THR_Session; |
74 |
extern pthread_key_t THR_Mem_root; |
|
1
by brian
clean slate |
75 |
|
76 |
||
77 |
/****************************************************************************
|
|
78 |
** User variables
|
|
79 |
****************************************************************************/
|
|
1471.5.2
by mordred
Removed some extern "C" bits that were screwing with the callstack. |
80 |
static unsigned char *get_var_key(user_var_entry *entry, size_t *length, bool) |
1
by brian
clean slate |
81 |
{
|
82 |
*length= entry->name.length; |
|
481
by Brian Aker
Remove all of uchar. |
83 |
return (unsigned char*) entry->name.str; |
1
by brian
clean slate |
84 |
}
|
85 |
||
1471.5.2
by mordred
Removed some extern "C" bits that were screwing with the callstack. |
86 |
static void free_user_var(user_var_entry *entry) |
1
by brian
clean slate |
87 |
{
|
1089.1.5
by Brian Aker
Cleanup of user_var |
88 |
delete entry; |
1
by brian
clean slate |
89 |
}
|
90 |
||
91 |
bool Key_part_spec::operator==(const Key_part_spec& other) const |
|
92 |
{
|
|
93 |
return length == other.length && |
|
94 |
field_name.length == other.field_name.length && |
|
95 |
!strcmp(field_name.str, other.field_name.str); |
|
96 |
}
|
|
97 |
||
1539
by Brian Aker
Simplify out Open_tables_state() backup/restore (no longer needed). |
98 |
Open_tables_state::Open_tables_state(uint64_t version_arg) : |
99 |
version(version_arg) |
|
1
by brian
clean slate |
100 |
{
|
1539
by Brian Aker
Simplify out Open_tables_state() backup/restore (no longer needed). |
101 |
open_tables= temporary_tables= derived_tables= NULL; |
102 |
extra_lock= lock= NULL; |
|
1
by brian
clean slate |
103 |
}
|
104 |
||
105 |
/*
|
|
106 |
The following functions form part of the C plugin API
|
|
107 |
*/
|
|
1471.5.2
by mordred
Removed some extern "C" bits that were screwing with the callstack. |
108 |
int mysql_tmpfile(const char *prefix) |
1
by brian
clean slate |
109 |
{
|
110 |
char filename[FN_REFLEN]; |
|
1556.1.1
by Brian Aker
Updates for moving temporary directory. |
111 |
int fd = internal::create_temp_file(filename, drizzle_tmpdir.c_str(), prefix, MYF(MY_WME)); |
1
by brian
clean slate |
112 |
if (fd >= 0) { |
113 |
unlink(filename); |
|
114 |
}
|
|
115 |
||
116 |
return fd; |
|
117 |
}
|
|
118 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
119 |
int session_tablespace_op(const Session *session) |
1
by brian
clean slate |
120 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
121 |
return test(session->tablespace_op); |
1
by brian
clean slate |
122 |
}
|
123 |
||
322.2.5
by Mats Kindahl
Replaced use of thd_proc_info() macro with calls to |
124 |
/**
|
520.1.21
by Brian Aker
THD -> Session rename |
125 |
Set the process info field of the Session structure.
|
322.2.5
by Mats Kindahl
Replaced use of thd_proc_info() macro with calls to |
126 |
|
127 |
This function is used by plug-ins. Internally, the
|
|
520.1.21
by Brian Aker
THD -> Session rename |
128 |
Session::set_proc_info() function should be used.
|
322.2.5
by Mats Kindahl
Replaced use of thd_proc_info() macro with calls to |
129 |
|
520.1.21
by Brian Aker
THD -> Session rename |
130 |
@see Session::set_proc_info
|
322.2.5
by Mats Kindahl
Replaced use of thd_proc_info() macro with calls to |
131 |
*/
|
1471.5.2
by mordred
Removed some extern "C" bits that were screwing with the callstack. |
132 |
void set_session_proc_info(Session *session, const char *info) |
520.1.22
by Brian Aker
Second pass of thd cleanup |
133 |
{
|
134 |
session->set_proc_info(info); |
|
135 |
}
|
|
136 |
||
137 |
const char *get_session_proc_info(Session *session) |
|
138 |
{
|
|
139 |
return session->get_proc_info(); |
|
140 |
}
|
|
141 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
142 |
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored) |
1240.9.6
by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that) |
143 |
{
|
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
144 |
return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr); |
1240.9.6
by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that) |
145 |
}
|
146 |
||
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
147 |
ResourceContext *Session::getResourceContext(const plugin::MonitoredInTransaction *monitored, |
1273.1.10
by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext |
148 |
size_t index) |
1240.9.6
by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that) |
149 |
{
|
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
150 |
return &ha_data[monitored->getId()].resource_context[index]; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
151 |
}
|
152 |
||
153 |
int64_t session_test_options(const Session *session, int64_t test_options) |
|
154 |
{
|
|
155 |
return session->options & test_options; |
|
156 |
}
|
|
157 |
||
158 |
int session_sql_command(const Session *session) |
|
159 |
{
|
|
160 |
return (int) session->lex->sql_command; |
|
161 |
}
|
|
162 |
||
163 |
int session_tx_isolation(const Session *session) |
|
164 |
{
|
|
165 |
return (int) session->variables.tx_isolation; |
|
166 |
}
|
|
167 |
||
1539
by Brian Aker
Simplify out Open_tables_state() backup/restore (no longer needed). |
168 |
Session::Session(plugin::Client *client_arg) : |
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
169 |
Open_tables_state(refresh_version), |
1100.3.29
by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by |
170 |
mem_root(&main_mem_root), |
171 |
lex(&main_lex), |
|
1280.3.16
by Padraig O'Sullivan
Updated the calls to dtrace probes to use the c_str() pointer from query in Session |
172 |
query(), |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
173 |
client(client_arg), |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
174 |
scheduler(NULL), |
175 |
scheduler_arg(NULL), |
|
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
176 |
lock_id(&main_lock_id), |
177 |
user_time(0), |
|
1273.1.30
by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager |
178 |
ha_data(plugin::num_trx_monitored_objects), |
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
179 |
arg_of_last_insert_id_function(false), |
180 |
first_successful_insert_id_in_prev_stmt(0), |
|
181 |
first_successful_insert_id_in_cur_stmt(0), |
|
1055.2.17
by Jay Pipes
More style cleanups in Session |
182 |
limit_found_rows(0), |
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
183 |
global_read_lock(0), |
1055.2.17
by Jay Pipes
More style cleanups in Session |
184 |
some_tables_deleted(false), |
185 |
no_errors(false), |
|
186 |
password(false), |
|
187 |
is_fatal_error(false), |
|
188 |
transaction_rollback_request(false), |
|
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
189 |
is_fatal_sub_stmt_error(0), |
190 |
derived_tables_processing(false), |
|
1055.2.17
by Jay Pipes
More style cleanups in Session |
191 |
tablespace_op(false), |
1055.2.16
by Jay Pipes
Removes dead Session::catalog member variable |
192 |
m_lip(NULL), |
1143.2.11
by Jay Pipes
Fixes a bug appearing on hades b/c forgot to initalize statement_message and transaction_message members of Session to NULL |
193 |
cached_table(0), |
194 |
transaction_message(NULL), |
|
1502.5.2
by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin. |
195 |
statement_message(NULL), |
196 |
session_event_observers(NULL) |
|
1
by brian
clean slate |
197 |
{
|
1014
by Brian Aker
Fix for processlist (Eric found). |
198 |
memset(process_list_info, 0, PROCESS_LIST_WIDTH); |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
199 |
client->setSession(this); |
961.1.3
by Brian Aker
Remove additional lock for proceslist. |
200 |
|
1
by brian
clean slate |
201 |
/*
|
202 |
Pass nominal parameters to init_alloc_root only to ensure that
|
|
203 |
the destructor works OK in case of an error. The main_mem_root
|
|
204 |
will be re-initialized in init_for_queries().
|
|
205 |
*/
|
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
206 |
memory::init_sql_alloc(&main_mem_root, memory::ROOT_MIN_BLOCK_SIZE, 0); |
1055.2.17
by Jay Pipes
More style cleanups in Session |
207 |
thread_stack= NULL; |
1
by brian
clean slate |
208 |
count_cuted_fields= CHECK_FIELD_IGNORE; |
209 |
killed= NOT_KILLED; |
|
1055.2.17
by Jay Pipes
More style cleanups in Session |
210 |
col_access= 0; |
211 |
tmp_table= 0; |
|
212 |
used_tables= 0; |
|
1
by brian
clean slate |
213 |
cuted_fields= sent_row_count= row_count= 0L; |
214 |
row_count_func= -1; |
|
215 |
statement_id_counter= 0UL; |
|
520.1.21
by Brian Aker
THD -> Session rename |
216 |
// Must be reset to handle error with Session's created for init of mysqld
|
1
by brian
clean slate |
217 |
lex->current_select= 0; |
218 |
start_time=(time_t) 0; |
|
219 |
start_utime= 0L; |
|
220 |
utime_after_lock= 0L; |
|
212.6.1
by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file. |
221 |
memset(&variables, 0, sizeof(variables)); |
1
by brian
clean slate |
222 |
thread_id= 0; |
223 |
file_id = 0; |
|
224 |
query_id= 0; |
|
1273.1.1
by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id |
225 |
warn_query_id= 0; |
1055.2.17
by Jay Pipes
More style cleanups in Session |
226 |
mysys_var= 0; |
1561.3.20
by Joe Daly
add a index in session.h this will allow repeated lookups without having to iterate through the scoreboard looking for our slot |
227 |
scoreboard_index= -1; |
520.1.21
by Brian Aker
THD -> Session rename |
228 |
dbug_sentry=Session_SENTRY_MAGIC; |
947
by Brian Aker
Merge fix |
229 |
cleanup_done= abort_on_warning= no_warnings_for_error= false; |
1
by brian
clean slate |
230 |
pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST); |
231 |
||
232 |
/* Variables with default values */
|
|
233 |
proc_info="login"; |
|
520.1.21
by Brian Aker
THD -> Session rename |
234 |
where= Session::DEFAULT_WHERE; |
1055.2.17
by Jay Pipes
More style cleanups in Session |
235 |
command= COM_CONNECT; |
1
by brian
clean slate |
236 |
|
1039.1.13
by Brian Aker
Removed dead bit in Session. |
237 |
plugin_sessionvar_init(this); |
238 |
/*
|
|
239 |
variables= global_system_variables above has reset
|
|
240 |
variables.pseudo_thread_id to 0. We need to correct it here to
|
|
241 |
avoid temporary tables replication failure.
|
|
242 |
*/
|
|
243 |
variables.pseudo_thread_id= thread_id; |
|
244 |
server_status= SERVER_STATUS_AUTOCOMMIT; |
|
245 |
options= session_startup_options; |
|
246 |
||
247 |
if (variables.max_join_size == HA_POS_ERROR) |
|
248 |
options |= OPTION_BIG_SELECTS; |
|
249 |
else
|
|
250 |
options &= ~OPTION_BIG_SELECTS; |
|
251 |
||
252 |
open_options=ha_open_options; |
|
253 |
update_lock_default= TL_WRITE; |
|
254 |
session_tx_isolation= (enum_tx_isolation) variables.tx_isolation; |
|
255 |
warn_list.empty(); |
|
256 |
memset(warn_count, 0, sizeof(warn_count)); |
|
257 |
total_warn_count= 0; |
|
258 |
memset(&status_var, 0, sizeof(status_var)); |
|
259 |
||
1
by brian
clean slate |
260 |
/* Initialize sub structures */
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
261 |
memory::init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE); |
1
by brian
clean slate |
262 |
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, |
263 |
(hash_get_key) get_var_key, |
|
264 |
(hash_free_key) free_user_var, 0); |
|
265 |
||
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
266 |
substitute_null_with_insert_id = false; |
1
by brian
clean slate |
267 |
thr_lock_info_init(&lock_info); /* safety: will be reset after start */ |
268 |
thr_lock_owner_init(&main_lock_id, &lock_info); |
|
269 |
||
270 |
m_internal_handler= NULL; |
|
1502.5.2
by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin. |
271 |
|
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
272 |
plugin::EventObserver::registerSessionEvents(*this); |
1
by brian
clean slate |
273 |
}
|
274 |
||
1100.3.29
by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by |
275 |
void Session::free_items() |
1055.2.13
by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore. |
276 |
{
|
277 |
Item *next; |
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
278 |
/* This works because items are allocated with memory::sql_alloc() */
|
1055.2.13
by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore. |
279 |
for (; free_list; free_list= next) |
280 |
{
|
|
281 |
next= free_list->next; |
|
282 |
free_list->delete_self(); |
|
283 |
}
|
|
284 |
}
|
|
1
by brian
clean slate |
285 |
|
520.1.21
by Brian Aker
THD -> Session rename |
286 |
void Session::push_internal_handler(Internal_error_handler *handler) |
1
by brian
clean slate |
287 |
{
|
288 |
/*
|
|
289 |
TODO: The current implementation is limited to 1 handler at a time only.
|
|
520.1.21
by Brian Aker
THD -> Session rename |
290 |
Session and sp_rcontext need to be modified to use a common handler stack.
|
1
by brian
clean slate |
291 |
*/
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
292 |
assert(m_internal_handler == NULL); |
1
by brian
clean slate |
293 |
m_internal_handler= handler; |
294 |
}
|
|
295 |
||
520.1.21
by Brian Aker
THD -> Session rename |
296 |
bool Session::handle_error(uint32_t sql_errno, const char *message, |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
297 |
DRIZZLE_ERROR::enum_warning_level level) |
1
by brian
clean slate |
298 |
{
|
299 |
if (m_internal_handler) |
|
300 |
{
|
|
301 |
return m_internal_handler->handle_error(sql_errno, message, level, this); |
|
302 |
}
|
|
303 |
||
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
304 |
return false; // 'false', as per coding style |
1
by brian
clean slate |
305 |
}
|
306 |
||
520.1.21
by Brian Aker
THD -> Session rename |
307 |
void Session::pop_internal_handler() |
1
by brian
clean slate |
308 |
{
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
309 |
assert(m_internal_handler != NULL); |
1
by brian
clean slate |
310 |
m_internal_handler= NULL; |
311 |
}
|
|
312 |
||
1490
by Brian Aker
Updates to remove a fe bits of dead code around C support for plugins |
313 |
void Session::get_xid(DRIZZLE_XID *xid) |
314 |
{
|
|
315 |
*xid = *(DRIZZLE_XID *) &transaction.xid_state.xid; |
|
316 |
}
|
|
317 |
||
1
by brian
clean slate |
318 |
/* Do operations that may take a long time */
|
319 |
||
520.1.21
by Brian Aker
THD -> Session rename |
320 |
void Session::cleanup(void) |
1
by brian
clean slate |
321 |
{
|
947
by Brian Aker
Merge fix |
322 |
assert(cleanup_done == false); |
1
by brian
clean slate |
323 |
|
324 |
killed= KILL_CONNECTION; |
|
325 |
#ifdef ENABLE_WHEN_BINLOG_WILL_BE_ABLE_TO_PREPARE
|
|
326 |
if (transaction.xid_state.xa_state == XA_PREPARED) |
|
327 |
{
|
|
328 |
#error xid_state in the cache should be replaced by the allocated value
|
|
329 |
}
|
|
330 |
#endif
|
|
331 |
{
|
|
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
332 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
333 |
transaction_services.rollbackTransaction(this, true); |
1
by brian
clean slate |
334 |
xid_cache_delete(&transaction.xid_state); |
335 |
}
|
|
336 |
hash_free(&user_vars); |
|
793
by Brian Aker
Pass through on refactoring functions to clases. |
337 |
close_temporary_tables(); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
338 |
|
1
by brian
clean slate |
339 |
if (global_read_lock) |
340 |
unlock_global_read_lock(this); |
|
341 |
||
947
by Brian Aker
Merge fix |
342 |
cleanup_done= true; |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
343 |
}
|
1
by brian
clean slate |
344 |
|
520.1.21
by Brian Aker
THD -> Session rename |
345 |
Session::~Session() |
1
by brian
clean slate |
346 |
{
|
1377.6.3
by pawel
changed function-like defines into functions in some files |
347 |
this->checkSentry(); |
1
by brian
clean slate |
348 |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
349 |
if (client->isConnected()) |
942.1.2
by Monty Taylor
Started trying to sort out session lifecycle. |
350 |
{
|
351 |
if (global_system_variables.log_warnings) |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
352 |
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),internal::my_progname, |
942.1.2
by Monty Taylor
Started trying to sort out session lifecycle. |
353 |
thread_id, |
1273.11.5
by Dennis Schoen
add getSecurityContext() |
354 |
(getSecurityContext().getUser().c_str() ? |
355 |
getSecurityContext().getUser().c_str() : "")); |
|
942.1.2
by Monty Taylor
Started trying to sort out session lifecycle. |
356 |
disconnect(0, false); |
357 |
}
|
|
358 |
||
1
by brian
clean slate |
359 |
/* Close connection */
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
360 |
client->close(); |
361 |
delete client; |
|
971.3.6
by Eric Day
Moved the last of the libdrizzleclient calls into Protocol. |
362 |
|
947
by Brian Aker
Merge fix |
363 |
if (cleanup_done == false) |
1
by brian
clean slate |
364 |
cleanup(); |
365 |
||
1152.1.4
by Brian Aker
Remove wrappers from SE |
366 |
plugin::StorageEngine::closeConnection(this); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
367 |
plugin_sessionvar_cleanup(this); |
1
by brian
clean slate |
368 |
|
1487
by Brian Aker
More updates for memory::Root |
369 |
warn_root.free_root(MYF(0)); |
1
by brian
clean slate |
370 |
mysys_var=0; // Safety (shouldn't be needed) |
520.1.21
by Brian Aker
THD -> Session rename |
371 |
dbug_sentry= Session_SENTRY_GONE; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
372 |
|
1487
by Brian Aker
More updates for memory::Root |
373 |
main_mem_root.free_root(MYF(0)); |
670.2.1
by Monty Taylor
Moved pthread keys |
374 |
pthread_setspecific(THR_Session, 0); |
942.1.2
by Monty Taylor
Started trying to sort out session lifecycle. |
375 |
|
1316.1.1
by Joe Daly
add plugin handle to logging to indicate when the session destructor is called |
376 |
plugin::Logging::postEndDo(this); |
1502.5.8
by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention. |
377 |
plugin::EventObserver::deregisterSessionEvents(*this); |
948
by Brian Aker
Restoring code Monty deleted. |
378 |
|
379 |
/* Ensure that no one is using Session */
|
|
380 |
pthread_mutex_unlock(&LOCK_delete); |
|
942.1.2
by Monty Taylor
Started trying to sort out session lifecycle. |
381 |
pthread_mutex_destroy(&LOCK_delete); |
1
by brian
clean slate |
382 |
}
|
383 |
||
520.1.21
by Brian Aker
THD -> Session rename |
384 |
void Session::awake(Session::killed_state state_to_set) |
1
by brian
clean slate |
385 |
{
|
1377.6.3
by pawel
changed function-like defines into functions in some files |
386 |
this->checkSentry(); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
387 |
safe_mutex_assert_owner(&LOCK_delete); |
1
by brian
clean slate |
388 |
|
389 |
killed= state_to_set; |
|
520.1.21
by Brian Aker
THD -> Session rename |
390 |
if (state_to_set != Session::KILL_QUERY) |
1
by brian
clean slate |
391 |
{
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
392 |
scheduler->killSession(this); |
1126.10.18
by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled. |
393 |
DRIZZLE_CONNECTION_DONE(thread_id); |
1
by brian
clean slate |
394 |
}
|
395 |
if (mysys_var) |
|
396 |
{
|
|
397 |
pthread_mutex_lock(&mysys_var->mutex); |
|
398 |
/*
|
|
399 |
This broadcast could be up in the air if the victim thread
|
|
400 |
exits the cond in the time between read and broadcast, but that is
|
|
401 |
ok since all we want to do is to make the victim thread get out
|
|
402 |
of waiting on current_cond.
|
|
403 |
If we see a non-zero current_cond: it cannot be an old value (because
|
|
404 |
then exit_cond() should have run and it can't because we have mutex); so
|
|
405 |
it is the true value but maybe current_mutex is not yet non-zero (we're
|
|
406 |
in the middle of enter_cond() and there is a "memory order
|
|
407 |
inversion"). So we test the mutex too to not lock 0.
|
|
408 |
||
409 |
Note that there is a small chance we fail to kill. If victim has locked
|
|
410 |
current_mutex, but hasn't yet entered enter_cond() (which means that
|
|
411 |
current_cond and current_mutex are 0), then the victim will not get
|
|
412 |
a signal and it may wait "forever" on the cond (until
|
|
413 |
we issue a second KILL or the status it's waiting for happens).
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
414 |
It's true that we have set its session->killed but it may not
|
1
by brian
clean slate |
415 |
see it immediately and so may have time to reach the cond_wait().
|
416 |
*/
|
|
417 |
if (mysys_var->current_cond && mysys_var->current_mutex) |
|
418 |
{
|
|
419 |
pthread_mutex_lock(mysys_var->current_mutex); |
|
420 |
pthread_cond_broadcast(mysys_var->current_cond); |
|
421 |
pthread_mutex_unlock(mysys_var->current_mutex); |
|
422 |
}
|
|
423 |
pthread_mutex_unlock(&mysys_var->mutex); |
|
424 |
}
|
|
425 |
}
|
|
426 |
||
427 |
/*
|
|
428 |
Remember the location of thread info, the structure needed for
|
|
1253.1.6
by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace. |
429 |
memory::sql_alloc() and the structure for the net buffer
|
1
by brian
clean slate |
430 |
*/
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
431 |
bool Session::storeGlobals() |
1
by brian
clean slate |
432 |
{
|
433 |
/*
|
|
434 |
Assert that thread_stack is initialized: it's necessary to be able
|
|
435 |
to track stack overrun.
|
|
436 |
*/
|
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
437 |
assert(thread_stack); |
1
by brian
clean slate |
438 |
|
520.1.21
by Brian Aker
THD -> Session rename |
439 |
if (pthread_setspecific(THR_Session, this) || |
670.2.1
by Monty Taylor
Moved pthread keys |
440 |
pthread_setspecific(THR_Mem_root, &mem_root)) |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
441 |
return true; |
442 |
||
1
by brian
clean slate |
443 |
mysys_var=my_thread_var; |
960.1.1
by Monty Taylor
First pass at scheduler plugin. |
444 |
|
1
by brian
clean slate |
445 |
/*
|
446 |
Let mysqld define the thread id (not mysys)
|
|
520.1.21
by Brian Aker
THD -> Session rename |
447 |
This allows us to move Session to different threads if needed.
|
1
by brian
clean slate |
448 |
*/
|
449 |
mysys_var->id= thread_id; |
|
450 |
real_id= pthread_self(); // For debugging |
|
451 |
||
452 |
/*
|
|
520.1.21
by Brian Aker
THD -> Session rename |
453 |
We have to call thr_lock_info_init() again here as Session may have been
|
1
by brian
clean slate |
454 |
created in another thread
|
455 |
*/
|
|
456 |
thr_lock_info_init(&lock_info); |
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
457 |
return false; |
1
by brian
clean slate |
458 |
}
|
459 |
||
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
460 |
/*
|
461 |
Init Session for query processing.
|
|
462 |
This has to be called once before we call mysql_parse.
|
|
463 |
See also comments in session.h.
|
|
464 |
*/
|
|
465 |
||
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
466 |
void Session::prepareForQueries() |
467 |
{
|
|
468 |
if (variables.max_join_size == HA_POS_ERROR) |
|
469 |
options |= OPTION_BIG_SELECTS; |
|
470 |
||
471 |
version= refresh_version; |
|
961.1.4
by Brian Aker
Remove another lock for processlist. |
472 |
set_proc_info(NULL); |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
473 |
command= COM_SLEEP; |
474 |
set_time(); |
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
475 |
|
1485
by Brian Aker
Updates to confine memroot |
476 |
mem_root->reset_root_defaults(variables.query_alloc_block_size, |
477 |
variables.query_prealloc_size); |
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
478 |
transaction.xid_state.xid.null(); |
479 |
transaction.xid_state.in_session=1; |
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
480 |
}
|
481 |
||
482 |
bool Session::initGlobals() |
|
483 |
{
|
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
484 |
if (storeGlobals()) |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
485 |
{
|
486 |
disconnect(ER_OUT_OF_RESOURCES, true); |
|
1537.2.1
by Joe Daly
add statistics_variables.h |
487 |
status_var_increment(current_global_counters.aborted_connects); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
488 |
return true; |
489 |
}
|
|
490 |
return false; |
|
491 |
}
|
|
492 |
||
493 |
void Session::run() |
|
494 |
{
|
|
495 |
if (initGlobals() || authenticate()) |
|
496 |
{
|
|
497 |
disconnect(0, true); |
|
498 |
return; |
|
499 |
}
|
|
500 |
||
501 |
prepareForQueries(); |
|
502 |
||
971.6.4
by Eric Day
Merged cleanup from my merge branch. |
503 |
while (! client->haveError() && killed != KILL_CONNECTION) |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
504 |
{
|
971.3.70
by Eric Day
Fixed style issues found by Jay. |
505 |
if (! executeStatement()) |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
506 |
break; |
507 |
}
|
|
508 |
||
509 |
disconnect(0, true); |
|
510 |
}
|
|
511 |
||
512 |
bool Session::schedule() |
|
513 |
{
|
|
1152.1.5
by Brian Aker
Remove Factory/make scheduler work like everything else. |
514 |
scheduler= plugin::Scheduler::getScheduler(); |
515 |
assert(scheduler); |
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
516 |
|
1260.1.2
by Monty Taylor
Replaced operator overloads with methods since we can't actually usefully follow the proper semantics for the operators. |
517 |
connection_count.increment(); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
518 |
|
1537.2.1
by Joe Daly
add statistics_variables.h |
519 |
if (connection_count > current_global_counters.max_used_connections) |
520 |
{
|
|
521 |
current_global_counters.max_used_connections= connection_count; |
|
522 |
}
|
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
523 |
|
971.3.66
by Eric Day
Fixed thread_id bug from session refactoring work. |
524 |
thread_id= variables.pseudo_thread_id= global_thread_id++; |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
525 |
|
526 |
pthread_mutex_lock(&LOCK_thread_count); |
|
1241.9.17
by Monty Taylor
Removed more bits from server_includes. |
527 |
getSessionList().push_back(this); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
528 |
pthread_mutex_unlock(&LOCK_thread_count); |
529 |
||
530 |
if (scheduler->addSession(this)) |
|
531 |
{
|
|
1126.10.18
by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled. |
532 |
DRIZZLE_CONNECTION_START(thread_id); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
533 |
char error_message_buff[DRIZZLE_ERRMSG_SIZE]; |
534 |
||
535 |
killed= Session::KILL_CONNECTION; |
|
536 |
||
1537.2.1
by Joe Daly
add statistics_variables.h |
537 |
status_var_increment(current_global_counters.aborted_connects); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
538 |
|
539 |
/* Can't use my_error() since store_globals has not been called. */
|
|
540 |
/* TODO replace will better error message */
|
|
541 |
snprintf(error_message_buff, sizeof(error_message_buff), |
|
542 |
ER(ER_CANT_CREATE_THREAD), 1); |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
543 |
client->sendError(ER_CANT_CREATE_THREAD, error_message_buff); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
544 |
return true; |
545 |
}
|
|
546 |
||
547 |
return false; |
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
548 |
}
|
549 |
||
1241.9.55
by Monty Taylor
Moved tree into drizzled/ |
550 |
|
551 |
const char* Session::enter_cond(pthread_cond_t *cond, |
|
552 |
pthread_mutex_t* mutex, |
|
553 |
const char* msg) |
|
554 |
{
|
|
555 |
const char* old_msg = get_proc_info(); |
|
556 |
safe_mutex_assert_owner(mutex); |
|
557 |
mysys_var->current_mutex = mutex; |
|
558 |
mysys_var->current_cond = cond; |
|
559 |
this->set_proc_info(msg); |
|
560 |
return old_msg; |
|
561 |
}
|
|
562 |
||
563 |
void Session::exit_cond(const char* old_msg) |
|
564 |
{
|
|
565 |
/*
|
|
566 |
Putting the mutex unlock in exit_cond() ensures that
|
|
567 |
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
|
|
568 |
locked (if that would not be the case, you'll get a deadlock if someone
|
|
569 |
does a Session::awake() on you).
|
|
570 |
*/
|
|
571 |
pthread_mutex_unlock(mysys_var->current_mutex); |
|
572 |
pthread_mutex_lock(&mysys_var->mutex); |
|
573 |
mysys_var->current_mutex = 0; |
|
574 |
mysys_var->current_cond = 0; |
|
575 |
this->set_proc_info(old_msg); |
|
576 |
pthread_mutex_unlock(&mysys_var->mutex); |
|
577 |
}
|
|
578 |
||
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
579 |
bool Session::authenticate() |
580 |
{
|
|
581 |
lex_start(this); |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
582 |
if (client->authenticate()) |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
583 |
return false; |
971.3.6
by Eric Day
Moved the last of the libdrizzleclient calls into Protocol. |
584 |
|
1537.2.1
by Joe Daly
add statistics_variables.h |
585 |
status_var_increment(current_global_counters.aborted_connects); |
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
586 |
return true; |
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
587 |
}
|
588 |
||
965
by Brian Aker
Merge with Jay |
589 |
bool Session::checkUser(const char *passwd, uint32_t passwd_len, const char *in_db) |
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
590 |
{
|
1317.1.3
by Monty Taylor
Fixed Authentication plugin interface to use SecurityContext rather than the |
591 |
const string passwd_str(passwd, passwd_len); |
592 |
bool is_authenticated= |
|
593 |
plugin::Authentication::isAuthenticated(getSecurityContext(), |
|
594 |
passwd_str); |
|
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
595 |
|
596 |
if (is_authenticated != true) |
|
597 |
{
|
|
1317.1.3
by Monty Taylor
Fixed Authentication plugin interface to use SecurityContext rather than the |
598 |
/* isAuthenticated has pushed the error message */
|
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
599 |
return false; |
600 |
}
|
|
601 |
||
602 |
/* Change database if necessary */
|
|
603 |
if (in_db && in_db[0]) |
|
604 |
{
|
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
605 |
SchemaIdentifier identifier(in_db); |
606 |
if (mysql_change_db(this, identifier)) |
|
934.2.4
by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false... |
607 |
{
|
608 |
/* mysql_change_db() has pushed the error message. */
|
|
609 |
return false; |
|
610 |
}
|
|
611 |
}
|
|
612 |
my_ok(); |
|
613 |
password= test(passwd_len); // remember for error messages |
|
614 |
||
615 |
/* Ready to handle queries */
|
|
616 |
return true; |
|
617 |
}
|
|
1
by brian
clean slate |
618 |
|
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
619 |
bool Session::executeStatement() |
620 |
{
|
|
621 |
char *l_packet= 0; |
|
622 |
uint32_t packet_length; |
|
623 |
||
624 |
enum enum_server_command l_command; |
|
625 |
||
626 |
/*
|
|
627 |
indicator of uninitialized lex => normal flow of errors handling
|
|
628 |
(see my_message_sql)
|
|
629 |
*/
|
|
630 |
lex->current_select= 0; |
|
971.6.7
by Eric Day
Reworked listen interface to not require binding of TCP ports. |
631 |
clear_error(); |
632 |
main_da.reset_diagnostics_area(); |
|
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
633 |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
634 |
if (client->readCommand(&l_packet, &packet_length) == false) |
971.3.6
by Eric Day
Moved the last of the libdrizzleclient calls into Protocol. |
635 |
return false; |
636 |
||
637 |
if (packet_length == 0) |
|
638 |
return true; |
|
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
639 |
|
640 |
l_command= (enum enum_server_command) (unsigned char) l_packet[0]; |
|
641 |
||
642 |
if (command >= COM_END) |
|
643 |
command= COM_END; // Wrong command |
|
644 |
||
645 |
assert(packet_length); |
|
971.3.6
by Eric Day
Moved the last of the libdrizzleclient calls into Protocol. |
646 |
return ! dispatch_command(l_command, this, l_packet+1, (uint32_t) (packet_length-1)); |
934.2.8
by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object. |
647 |
}
|
934.2.9
by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class. |
648 |
|
649 |
bool Session::readAndStoreQuery(const char *in_packet, uint32_t in_packet_length) |
|
650 |
{
|
|
651 |
/* Remove garbage at start and end of query */
|
|
652 |
while (in_packet_length > 0 && my_isspace(charset(), in_packet[0])) |
|
653 |
{
|
|
654 |
in_packet++; |
|
655 |
in_packet_length--; |
|
656 |
}
|
|
657 |
const char *pos= in_packet + in_packet_length; /* Point at end null */ |
|
658 |
while (in_packet_length > 0 && |
|
659 |
(pos[-1] == ';' || my_isspace(charset() ,pos[-1]))) |
|
660 |
{
|
|
661 |
pos--; |
|
662 |
in_packet_length--; |
|
663 |
}
|
|
664 |
||
1280.3.11
by Padraig O'Sullivan
Changed the query member of Session to be std::string |
665 |
query.assign(in_packet, in_packet + in_packet_length); |
934.2.9
by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class. |
666 |
|
667 |
return true; |
|
668 |
}
|
|
669 |
||
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
670 |
bool Session::endTransaction(enum enum_mysql_completiontype completion) |
671 |
{
|
|
672 |
bool do_release= 0; |
|
673 |
bool result= true; |
|
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
674 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
675 |
|
676 |
if (transaction.xid_state.xa_state != XA_NOTR) |
|
677 |
{
|
|
678 |
my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[transaction.xid_state.xa_state]); |
|
679 |
return false; |
|
680 |
}
|
|
971.3.64
by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code. |
681 |
switch (completion) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
682 |
{
|
683 |
case COMMIT: |
|
684 |
/*
|
|
685 |
* We don't use endActiveTransaction() here to ensure that this works
|
|
686 |
* even if there is a problem with the OPTION_AUTO_COMMIT flag
|
|
687 |
* (Which of course should never happen...)
|
|
688 |
*/
|
|
689 |
server_status&= ~SERVER_STATUS_IN_TRANS; |
|
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
690 |
if (transaction_services.commitTransaction(this, true)) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
691 |
result= false; |
1172.1.2
by Brian Aker
Remove worthless call (ok... for not current replication system). |
692 |
options&= ~(OPTION_BEGIN); |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
693 |
break; |
694 |
case COMMIT_RELEASE: |
|
695 |
do_release= 1; /* fall through */ |
|
696 |
case COMMIT_AND_CHAIN: |
|
697 |
result= endActiveTransaction(); |
|
698 |
if (result == true && completion == COMMIT_AND_CHAIN) |
|
699 |
result= startTransaction(); |
|
700 |
break; |
|
701 |
case ROLLBACK_RELEASE: |
|
702 |
do_release= 1; /* fall through */ |
|
703 |
case ROLLBACK: |
|
704 |
case ROLLBACK_AND_CHAIN: |
|
705 |
{
|
|
706 |
server_status&= ~SERVER_STATUS_IN_TRANS; |
|
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
707 |
if (transaction_services.rollbackTransaction(this, true)) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
708 |
result= false; |
1172.1.2
by Brian Aker
Remove worthless call (ok... for not current replication system). |
709 |
options&= ~(OPTION_BEGIN); |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
710 |
if (result == true && (completion == ROLLBACK_AND_CHAIN)) |
711 |
result= startTransaction(); |
|
712 |
break; |
|
713 |
}
|
|
714 |
default: |
|
715 |
my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); |
|
716 |
return false; |
|
717 |
}
|
|
718 |
||
719 |
if (result == false) |
|
720 |
my_error(killed_errno(), MYF(0)); |
|
721 |
else if ((result == true) && do_release) |
|
722 |
killed= Session::KILL_CONNECTION; |
|
723 |
||
724 |
return result; |
|
725 |
}
|
|
726 |
||
727 |
bool Session::endActiveTransaction() |
|
728 |
{
|
|
729 |
bool result= true; |
|
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
730 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
731 |
|
732 |
if (transaction.xid_state.xa_state != XA_NOTR) |
|
733 |
{
|
|
734 |
my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[transaction.xid_state.xa_state]); |
|
735 |
return false; |
|
736 |
}
|
|
1054.1.8
by Brian Aker
Remove lock_tables list from session. |
737 |
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
738 |
{
|
739 |
server_status&= ~SERVER_STATUS_IN_TRANS; |
|
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
740 |
if (transaction_services.commitTransaction(this, true)) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
741 |
result= false; |
742 |
}
|
|
1172.1.2
by Brian Aker
Remove worthless call (ok... for not current replication system). |
743 |
options&= ~(OPTION_BEGIN); |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
744 |
return result; |
745 |
}
|
|
746 |
||
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
747 |
bool Session::startTransaction(start_transaction_option_t opt) |
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
748 |
{
|
749 |
bool result= true; |
|
750 |
||
751 |
if (! endActiveTransaction()) |
|
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
752 |
{
|
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
753 |
result= false; |
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
754 |
}
|
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
755 |
else
|
756 |
{
|
|
757 |
options|= OPTION_BEGIN; |
|
758 |
server_status|= SERVER_STATUS_IN_TRANS; |
|
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
759 |
|
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
760 |
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt)) |
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
761 |
{
|
1273.1.27
by Jay Pipes
Completes the work of removing the weirdness around transaction |
762 |
result= false; |
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
763 |
}
|
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
764 |
}
|
1206.1.3
by Brian Aker
Valgrind fix for startTransaction() |
765 |
|
934.2.11
by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object. |
766 |
return result; |
767 |
}
|
|
768 |
||
520.1.21
by Brian Aker
THD -> Session rename |
769 |
void Session::cleanup_after_query() |
1
by brian
clean slate |
770 |
{
|
771 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
772 |
Reset rand_used so that detection of calls to rand() will save random
|
1
by brian
clean slate |
773 |
seeds if needed by the slave.
|
774 |
*/
|
|
775 |
{
|
|
776 |
/* Forget those values, for next binlogger: */
|
|
777 |
auto_inc_intervals_in_cur_stmt_for_binlog.empty(); |
|
778 |
}
|
|
779 |
if (first_successful_insert_id_in_cur_stmt > 0) |
|
780 |
{
|
|
781 |
/* set what LAST_INSERT_ID() will return */
|
|
1055.2.17
by Jay Pipes
More style cleanups in Session |
782 |
first_successful_insert_id_in_prev_stmt= first_successful_insert_id_in_cur_stmt; |
1
by brian
clean slate |
783 |
first_successful_insert_id_in_cur_stmt= 0; |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
784 |
substitute_null_with_insert_id= true; |
1
by brian
clean slate |
785 |
}
|
1055.2.17
by Jay Pipes
More style cleanups in Session |
786 |
arg_of_last_insert_id_function= false; |
1
by brian
clean slate |
787 |
/* Free Items that were created during this execution */
|
788 |
free_items(); |
|
789 |
/* Reset where. */
|
|
520.1.21
by Brian Aker
THD -> Session rename |
790 |
where= Session::DEFAULT_WHERE; |
1532.1.1
by Brian Aker
Merge of change to flip table instance to be share instance |
791 |
|
792 |
/* Reset the temporary shares we built */
|
|
793 |
for (std::vector<TableShareInstance *>::iterator iter= temporary_shares.begin(); |
|
794 |
iter != temporary_shares.end(); iter++) |
|
795 |
{
|
|
796 |
delete *iter; |
|
797 |
}
|
|
798 |
temporary_shares.clear(); |
|
1
by brian
clean slate |
799 |
}
|
800 |
||
801 |
/**
|
|
802 |
Create a LEX_STRING in this connection.
|
|
803 |
||
804 |
@param lex_str pointer to LEX_STRING object to be initialized
|
|
805 |
@param str initializer to be copied into lex_str
|
|
806 |
@param length length of str, in bytes
|
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
807 |
@param allocate_lex_string if true, allocate new LEX_STRING object,
|
1
by brian
clean slate |
808 |
instead of using lex_str value
|
809 |
@return NULL on failure, or pointer to the LEX_STRING object
|
|
810 |
*/
|
|
520.1.21
by Brian Aker
THD -> Session rename |
811 |
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str, |
1273.13.38
by Brian Aker
Add in new show work. |
812 |
const std::string &str, |
813 |
bool allocate_lex_string) |
|
814 |
{
|
|
815 |
return make_lex_string(lex_str, str.c_str(), str.length(), allocate_lex_string); |
|
816 |
}
|
|
817 |
||
818 |
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str, |
|
819 |
const char* str, uint32_t length, |
|
820 |
bool allocate_lex_string) |
|
1
by brian
clean slate |
821 |
{
|
822 |
if (allocate_lex_string) |
|
823 |
if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING)))) |
|
824 |
return 0; |
|
1487
by Brian Aker
More updates for memory::Root |
825 |
if (!(lex_str->str= mem_root->strmake_root(str, length))) |
1
by brian
clean slate |
826 |
return 0; |
827 |
lex_str->length= length; |
|
828 |
return lex_str; |
|
829 |
}
|
|
830 |
||
520.1.21
by Brian Aker
THD -> Session rename |
831 |
int Session::send_explain_fields(select_result *result) |
1
by brian
clean slate |
832 |
{
|
833 |
List<Item> field_list; |
|
834 |
Item *item; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
835 |
const CHARSET_INFO * const cs= system_charset_info; |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
836 |
field_list.push_back(new Item_return_int("id",3, DRIZZLE_TYPE_LONGLONG)); |
1
by brian
clean slate |
837 |
field_list.push_back(new Item_empty_string("select_type", 19, cs)); |
838 |
field_list.push_back(item= new Item_empty_string("table", NAME_CHAR_LEN, cs)); |
|
839 |
item->maybe_null= 1; |
|
840 |
field_list.push_back(item= new Item_empty_string("type", 10, cs)); |
|
841 |
item->maybe_null= 1; |
|
842 |
field_list.push_back(item=new Item_empty_string("possible_keys", |
|
843 |
NAME_CHAR_LEN*MAX_KEY, cs)); |
|
844 |
item->maybe_null=1; |
|
845 |
field_list.push_back(item=new Item_empty_string("key", NAME_CHAR_LEN, cs)); |
|
846 |
item->maybe_null=1; |
|
847 |
field_list.push_back(item= |
|
848 |
new Item_empty_string("key_len", |
|
849 |
MAX_KEY * |
|
850 |
(MAX_KEY_LENGTH_DECIMAL_WIDTH + 1 /* for comma */), |
|
851 |
cs)); |
|
852 |
item->maybe_null=1; |
|
853 |
field_list.push_back(item=new Item_empty_string("ref", |
|
854 |
NAME_CHAR_LEN*MAX_REF_PARTS, |
|
855 |
cs)); |
|
856 |
item->maybe_null=1; |
|
857 |
field_list.push_back(item= new Item_return_int("rows", 10, |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
858 |
DRIZZLE_TYPE_LONGLONG)); |
1
by brian
clean slate |
859 |
if (lex->describe & DESCRIBE_EXTENDED) |
860 |
{
|
|
861 |
field_list.push_back(item= new Item_float("filtered", 0.1234, 2, 4)); |
|
862 |
item->maybe_null=1; |
|
863 |
}
|
|
864 |
item->maybe_null= 1; |
|
865 |
field_list.push_back(new Item_empty_string("Extra", 255, cs)); |
|
971.3.63
by Eric Day
Removed protocol field flags. |
866 |
return (result->send_fields(field_list)); |
1
by brian
clean slate |
867 |
}
|
868 |
||
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
869 |
void select_result::send_error(uint32_t errcode, const char *err) |
870 |
{
|
|
871 |
my_message(errcode, err, MYF(0)); |
|
872 |
}
|
|
873 |
||
1
by brian
clean slate |
874 |
/************************************************************************
|
875 |
Handling writing to file
|
|
876 |
************************************************************************/
|
|
877 |
||
482
by Brian Aker
Remove uint. |
878 |
void select_to_file::send_error(uint32_t errcode,const char *err) |
1
by brian
clean slate |
879 |
{
|
880 |
my_message(errcode, err, MYF(0)); |
|
881 |
if (file > 0) |
|
882 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
883 |
(void) end_io_cache(cache); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
884 |
(void) internal::my_close(file, MYF(0)); |
885 |
(void) internal::my_delete(path, MYF(0)); // Delete file on error |
|
1
by brian
clean slate |
886 |
file= -1; |
887 |
}
|
|
888 |
}
|
|
889 |
||
890 |
||
891 |
bool select_to_file::send_eof() |
|
892 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
893 |
int error= test(end_io_cache(cache)); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
894 |
if (internal::my_close(file, MYF(MY_WME))) |
1
by brian
clean slate |
895 |
error= 1; |
896 |
if (!error) |
|
897 |
{
|
|
898 |
/*
|
|
899 |
In order to remember the value of affected rows for ROW_COUNT()
|
|
900 |
function, SELECT INTO has to have an own SQLCOM.
|
|
901 |
TODO: split from SQLCOM_SELECT
|
|
902 |
*/
|
|
836
by Brian Aker
Fixed session call from function to method. |
903 |
session->my_ok(row_count); |
1
by brian
clean slate |
904 |
}
|
905 |
file= -1; |
|
906 |
return error; |
|
907 |
}
|
|
908 |
||
909 |
||
910 |
void select_to_file::cleanup() |
|
911 |
{
|
|
912 |
/* In case of error send_eof() may be not called: close the file here. */
|
|
913 |
if (file >= 0) |
|
914 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
915 |
(void) end_io_cache(cache); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
916 |
(void) internal::my_close(file, MYF(0)); |
1
by brian
clean slate |
917 |
file= -1; |
918 |
}
|
|
919 |
path[0]= '\0'; |
|
920 |
row_count= 0; |
|
921 |
}
|
|
922 |
||
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
923 |
select_to_file::select_to_file(file_exchange *ex) |
1241.9.52
by Monty Taylor
Fixed valgrind issue. |
924 |
: exchange(ex), |
925 |
file(-1), |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
926 |
cache(static_cast<internal::IO_CACHE *>(memory::sql_calloc(sizeof(internal::IO_CACHE)))), |
1241.9.52
by Monty Taylor
Fixed valgrind issue. |
927 |
row_count(0L) |
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
928 |
{
|
929 |
path[0]=0; |
|
930 |
}
|
|
1
by brian
clean slate |
931 |
|
932 |
select_to_file::~select_to_file() |
|
933 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
934 |
cleanup(); |
1
by brian
clean slate |
935 |
}
|
936 |
||
937 |
/***************************************************************************
|
|
938 |
** Export of select to textfile
|
|
939 |
***************************************************************************/
|
|
940 |
||
941 |
select_export::~select_export() |
|
942 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
943 |
session->sent_row_count=row_count; |
1
by brian
clean slate |
944 |
}
|
945 |
||
946 |
||
947 |
/*
|
|
948 |
Create file with IO cache
|
|
949 |
||
950 |
SYNOPSIS
|
|
951 |
create_file()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
952 |
session Thread handle
|
1
by brian
clean slate |
953 |
path File name
|
954 |
exchange Excange class
|
|
955 |
cache IO cache
|
|
956 |
||
957 |
RETURN
|
|
958 |
>= 0 File handle
|
|
959 |
-1 Error
|
|
960 |
*/
|
|
961 |
||
962 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
963 |
static int create_file(Session *session, char *path, file_exchange *exchange, internal::IO_CACHE *cache) |
1
by brian
clean slate |
964 |
{
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
965 |
int file; |
482
by Brian Aker
Remove uint. |
966 |
uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH; |
1
by brian
clean slate |
967 |
|
968 |
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
|
|
969 |
option|= MY_REPLACE_DIR; // Force use of db directory |
|
970 |
#endif
|
|
971 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
972 |
if (!internal::dirname_length(exchange->file_name)) |
1
by brian
clean slate |
973 |
{
|
1300.5.3
by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're |
974 |
strcpy(path, data_home_real); |
1220.1.9
by Brian Aker
Remove char *db from session, and replaces it with std::string. |
975 |
if (! session->db.empty()) |
1300.5.3
by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're |
976 |
strncat(path, session->db.c_str(), FN_REFLEN-strlen(data_home_real)-1); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
977 |
(void) internal::fn_format(path, exchange->file_name, path, "", option); |
1
by brian
clean slate |
978 |
}
|
979 |
else
|
|
1300.5.3
by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're |
980 |
(void) internal::fn_format(path, exchange->file_name, data_home_real, "", option); |
1
by brian
clean slate |
981 |
|
982 |
if (opt_secure_file_priv && |
|
983 |
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv))) |
|
984 |
{
|
|
985 |
/* Write only allowed to dir or subdir specified by secure_file_priv */
|
|
986 |
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv"); |
|
987 |
return -1; |
|
988 |
}
|
|
989 |
||
990 |
if (!access(path, F_OK)) |
|
991 |
{
|
|
992 |
my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); |
|
993 |
return -1; |
|
994 |
}
|
|
995 |
/* Create the file world readable */
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
996 |
if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0) |
1
by brian
clean slate |
997 |
return file; |
998 |
(void) fchmod(file, 0666); // Because of umask() |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
999 |
if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME))) |
1
by brian
clean slate |
1000 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
1001 |
internal::my_close(file, MYF(0)); |
1002 |
internal::my_delete(path, MYF(0)); // Delete file on error, it was just created |
|
1
by brian
clean slate |
1003 |
return -1; |
1004 |
}
|
|
1005 |
return file; |
|
1006 |
}
|
|
1007 |
||
1008 |
||
1009 |
int
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1010 |
select_export::prepare(List<Item> &list, Select_Lex_Unit *u) |
1
by brian
clean slate |
1011 |
{
|
1012 |
bool blob_flag=0; |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1013 |
bool string_results= false, non_string_results= false; |
1
by brian
clean slate |
1014 |
unit= u; |
895
by Brian Aker
Completion (?) of uint conversion. |
1015 |
if ((uint32_t) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) |
629.5.4
by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls |
1016 |
strncpy(path,exchange->file_name,FN_REFLEN-1); |
1
by brian
clean slate |
1017 |
|
1018 |
/* Check if there is any blobs in data */
|
|
1019 |
{
|
|
1020 |
List_iterator_fast<Item> li(list); |
|
1021 |
Item *item; |
|
1022 |
while ((item=li++)) |
|
1023 |
{
|
|
1024 |
if (item->max_length >= MAX_BLOB_WIDTH) |
|
1025 |
{
|
|
1026 |
blob_flag=1; |
|
1027 |
break; |
|
1028 |
}
|
|
1029 |
if (item->result_type() == STRING_RESULT) |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1030 |
string_results= true; |
1
by brian
clean slate |
1031 |
else
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1032 |
non_string_results= true; |
1
by brian
clean slate |
1033 |
}
|
1034 |
}
|
|
1035 |
field_term_length=exchange->field_term->length(); |
|
1036 |
field_term_char= field_term_length ? |
|
481
by Brian Aker
Remove all of uchar. |
1037 |
(int) (unsigned char) (*exchange->field_term)[0] : INT_MAX; |
1
by brian
clean slate |
1038 |
if (!exchange->line_term->length()) |
1039 |
exchange->line_term=exchange->field_term; // Use this if it exists |
|
1040 |
field_sep_char= (exchange->enclosed->length() ? |
|
481
by Brian Aker
Remove all of uchar. |
1041 |
(int) (unsigned char) (*exchange->enclosed)[0] : field_term_char); |
1
by brian
clean slate |
1042 |
escape_char= (exchange->escaped->length() ? |
481
by Brian Aker
Remove all of uchar. |
1043 |
(int) (unsigned char) (*exchange->escaped)[0] : -1); |
1
by brian
clean slate |
1044 |
is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char)); |
1045 |
is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char)); |
|
1046 |
line_sep_char= (exchange->line_term->length() ? |
|
481
by Brian Aker
Remove all of uchar. |
1047 |
(int) (unsigned char) (*exchange->line_term)[0] : INT_MAX); |
1
by brian
clean slate |
1048 |
if (!field_term_length) |
1049 |
exchange->opt_enclosed=0; |
|
1050 |
if (!exchange->enclosed->length()) |
|
1051 |
exchange->opt_enclosed=1; // A little quicker loop |
|
1052 |
fixed_row_size= (!field_term_length && !exchange->enclosed->length() && |
|
1053 |
!blob_flag); |
|
1054 |
if ((is_ambiguous_field_sep && exchange->enclosed->is_empty() && |
|
1055 |
(string_results || is_unsafe_field_sep)) || |
|
1056 |
(exchange->opt_enclosed && non_string_results && |
|
1057 |
field_term_length && strchr(NUMERIC_CHARS, field_term_char))) |
|
1058 |
{
|
|
673.3.8
by Stewart Smith
fix outfile_loaddata test for drizzle. |
1059 |
my_error(ER_AMBIGUOUS_FIELD_TERM, MYF(0)); |
1060 |
return 1; |
|
1
by brian
clean slate |
1061 |
}
|
673.3.8
by Stewart Smith
fix outfile_loaddata test for drizzle. |
1062 |
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1063 |
if ((file= create_file(session, path, exchange, cache)) < 0) |
673.3.8
by Stewart Smith
fix outfile_loaddata test for drizzle. |
1064 |
return 1; |
1
by brian
clean slate |
1065 |
|
1066 |
return 0; |
|
1067 |
}
|
|
1068 |
||
1069 |
bool select_export::send_data(List<Item> &items) |
|
1070 |
{
|
|
1071 |
char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH]; |
|
1072 |
bool space_inited=0; |
|
1073 |
String tmp(buff,sizeof(buff),&my_charset_bin),*res; |
|
1074 |
tmp.length(0); |
|
1075 |
||
1076 |
if (unit->offset_limit_cnt) |
|
1077 |
{ // using limit offset,count |
|
1078 |
unit->offset_limit_cnt--; |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1079 |
return(0); |
1
by brian
clean slate |
1080 |
}
|
1081 |
row_count++; |
|
1082 |
Item *item; |
|
482
by Brian Aker
Remove uint. |
1083 |
uint32_t used_length=0,items_left=items.elements; |
1
by brian
clean slate |
1084 |
List_iterator_fast<Item> li(items); |
1085 |
||
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1086 |
if (my_b_write(cache,(unsigned char*) exchange->line_start->ptr(), |
1208.3.2
by brian
Update for Cursor renaming. |
1087 |
exchange->line_start->length())) |
1
by brian
clean slate |
1088 |
goto err; |
1089 |
while ((item=li++)) |
|
1090 |
{
|
|
1091 |
Item_result result_type=item->result_type(); |
|
1092 |
bool enclosed = (exchange->enclosed->length() && |
|
1093 |
(!exchange->opt_enclosed || result_type == STRING_RESULT)); |
|
1094 |
res=item->str_result(&tmp); |
|
1095 |
if (res && enclosed) |
|
1096 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1097 |
if (my_b_write(cache,(unsigned char*) exchange->enclosed->ptr(), |
1208.3.2
by brian
Update for Cursor renaming. |
1098 |
exchange->enclosed->length())) |
1099 |
goto err; |
|
1
by brian
clean slate |
1100 |
}
|
1101 |
if (!res) |
|
1102 |
{ // NULL |
|
1103 |
if (!fixed_row_size) |
|
1104 |
{
|
|
1208.3.2
by brian
Update for Cursor renaming. |
1105 |
if (escape_char != -1) // Use \N syntax |
1106 |
{
|
|
1107 |
null_buff[0]=escape_char; |
|
1108 |
null_buff[1]='N'; |
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1109 |
if (my_b_write(cache,(unsigned char*) null_buff,2)) |
1208.3.2
by brian
Update for Cursor renaming. |
1110 |
goto err; |
1111 |
}
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1112 |
else if (my_b_write(cache,(unsigned char*) "NULL",4)) |
1208.3.2
by brian
Update for Cursor renaming. |
1113 |
goto err; |
1
by brian
clean slate |
1114 |
}
|
1115 |
else
|
|
1116 |
{
|
|
1208.3.2
by brian
Update for Cursor renaming. |
1117 |
used_length=0; // Fill with space |
1
by brian
clean slate |
1118 |
}
|
1119 |
}
|
|
1120 |
else
|
|
1121 |
{
|
|
1122 |
if (fixed_row_size) |
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
1123 |
used_length= min(res->length(),item->max_length); |
1
by brian
clean slate |
1124 |
else
|
1067.4.1
by Nathan Williams
First few changes at converting cmin to std::min. |
1125 |
used_length= res->length(); |
1126 |
||
1
by brian
clean slate |
1127 |
if ((result_type == STRING_RESULT || is_unsafe_field_sep) && |
1208.3.2
by brian
Update for Cursor renaming. |
1128 |
escape_char != -1) |
1
by brian
clean slate |
1129 |
{
|
1130 |
char *pos, *start, *end; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1131 |
const CHARSET_INFO * const res_charset= res->charset(); |
748
by Brian Aker
Removal of client side collation. |
1132 |
const CHARSET_INFO * const character_set_client= default_charset_info; |
1133 |
||
1
by brian
clean slate |
1134 |
bool check_second_byte= (res_charset == &my_charset_bin) && |
1208.3.2
by brian
Update for Cursor renaming. |
1135 |
character_set_client-> |
1136 |
escape_with_backslash_is_dangerous; |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1137 |
assert(character_set_client->mbmaxlen == 2 || |
748
by Brian Aker
Removal of client side collation. |
1138 |
!character_set_client->escape_with_backslash_is_dangerous); |
1208.3.2
by brian
Update for Cursor renaming. |
1139 |
for (start=pos=(char*) res->ptr(),end=pos+used_length ; |
1140 |
pos != end ; |
|
1141 |
pos++) |
|
1142 |
{
|
|
1143 |
if (use_mb(res_charset)) |
|
1144 |
{
|
|
1145 |
int l; |
|
1146 |
if ((l=my_ismbchar(res_charset, pos, end))) |
|
1147 |
{
|
|
1148 |
pos += l-1; |
|
1149 |
continue; |
|
1150 |
}
|
|
1151 |
}
|
|
1
by brian
clean slate |
1152 |
|
1153 |
/*
|
|
1154 |
Special case when dumping BINARY/VARBINARY/BLOB values
|
|
1155 |
for the clients with character sets big5, cp932, gbk and sjis,
|
|
1156 |
which can have the escape character (0x5C "\" by default)
|
|
1157 |
as the second byte of a multi-byte sequence.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1158 |
|
1
by brian
clean slate |
1159 |
If
|
1160 |
- pos[0] is a valid multi-byte head (e.g 0xEE) and
|
|
1161 |
- pos[1] is 0x00, which will be escaped as "\0",
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1162 |
|
1
by brian
clean slate |
1163 |
then we'll get "0xEE + 0x5C + 0x30" in the output file.
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1164 |
|
1
by brian
clean slate |
1165 |
If this file is later loaded using this sequence of commands:
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1166 |
|
1
by brian
clean slate |
1167 |
mysql> create table t1 (a varchar(128)) character set big5;
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
1168 |
mysql> LOAD DATA INFILE 'dump.txt' INTO Table t1;
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1169 |
|
1
by brian
clean slate |
1170 |
then 0x5C will be misinterpreted as the second byte
|
1171 |
of a multi-byte character "0xEE + 0x5C", instead of
|
|
1172 |
escape character for 0x00.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1173 |
|
1
by brian
clean slate |
1174 |
To avoid this confusion, we'll escape the multi-byte
|
1175 |
head character too, so the sequence "0xEE + 0x00" will be
|
|
1176 |
dumped as "0x5C + 0xEE + 0x5C + 0x30".
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1177 |
|
1
by brian
clean slate |
1178 |
Note, in the condition below we only check if
|
1179 |
mbcharlen is equal to 2, because there are no
|
|
1180 |
character sets with mbmaxlen longer than 2
|
|
1181 |
and with escape_with_backslash_is_dangerous set.
|
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1182 |
assert before the loop makes that sure.
|
1
by brian
clean slate |
1183 |
*/
|
1184 |
||
1377.6.3
by pawel
changed function-like defines into functions in some files |
1185 |
if ((needs_escaping(*pos, enclosed) || |
1
by brian
clean slate |
1186 |
(check_second_byte && |
481
by Brian Aker
Remove all of uchar. |
1187 |
my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 && |
1
by brian
clean slate |
1188 |
pos + 1 < end && |
1377.6.3
by pawel
changed function-like defines into functions in some files |
1189 |
needs_escaping(pos[1], enclosed))) && |
1
by brian
clean slate |
1190 |
/*
|
1208.3.2
by brian
Update for Cursor renaming. |
1191 |
Don't escape field_term_char by doubling - doubling is only
|
1192 |
valid for ENCLOSED BY characters:
|
|
1
by brian
clean slate |
1193 |
*/
|
1194 |
(enclosed || !is_ambiguous_field_term || |
|
481
by Brian Aker
Remove all of uchar. |
1195 |
(int) (unsigned char) *pos != field_term_char)) |
1
by brian
clean slate |
1196 |
{
|
1208.3.2
by brian
Update for Cursor renaming. |
1197 |
char tmp_buff[2]; |
481
by Brian Aker
Remove all of uchar. |
1198 |
tmp_buff[0]= ((int) (unsigned char) *pos == field_sep_char && |
1
by brian
clean slate |
1199 |
is_ambiguous_field_sep) ? |
1208.3.2
by brian
Update for Cursor renaming. |
1200 |
field_sep_char : escape_char; |
1201 |
tmp_buff[1]= *pos ? *pos : '0'; |
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1202 |
if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start)) || |
1203 |
my_b_write(cache,(unsigned char*) tmp_buff,2)) |
|
1208.3.2
by brian
Update for Cursor renaming. |
1204 |
goto err; |
1205 |
start=pos+1; |
|
1206 |
}
|
|
1207 |
}
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1208 |
if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start))) |
1208.3.2
by brian
Update for Cursor renaming. |
1209 |
goto err; |
1
by brian
clean slate |
1210 |
}
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1211 |
else if (my_b_write(cache,(unsigned char*) res->ptr(),used_length)) |
1208.3.2
by brian
Update for Cursor renaming. |
1212 |
goto err; |
1
by brian
clean slate |
1213 |
}
|
1214 |
if (fixed_row_size) |
|
1215 |
{ // Fill with space |
|
1216 |
if (item->max_length > used_length) |
|
1217 |
{
|
|
1208.3.2
by brian
Update for Cursor renaming. |
1218 |
/* QQ: Fix by adding a my_b_fill() function */
|
1219 |
if (!space_inited) |
|
1220 |
{
|
|
1221 |
space_inited=1; |
|
1222 |
memset(space, ' ', sizeof(space)); |
|
1223 |
}
|
|
1224 |
uint32_t length=item->max_length-used_length; |
|
1225 |
for (; length > sizeof(space) ; length-=sizeof(space)) |
|
1226 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1227 |
if (my_b_write(cache,(unsigned char*) space,sizeof(space))) |
1208.3.2
by brian
Update for Cursor renaming. |
1228 |
goto err; |
1229 |
}
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1230 |
if (my_b_write(cache,(unsigned char*) space,length)) |
1208.3.2
by brian
Update for Cursor renaming. |
1231 |
goto err; |
1
by brian
clean slate |
1232 |
}
|
1233 |
}
|
|
1234 |
if (res && enclosed) |
|
1235 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1236 |
if (my_b_write(cache, (unsigned char*) exchange->enclosed->ptr(), |
1
by brian
clean slate |
1237 |
exchange->enclosed->length())) |
1238 |
goto err; |
|
1239 |
}
|
|
1240 |
if (--items_left) |
|
1241 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1242 |
if (my_b_write(cache, (unsigned char*) exchange->field_term->ptr(), |
1
by brian
clean slate |
1243 |
field_term_length)) |
1244 |
goto err; |
|
1245 |
}
|
|
1246 |
}
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1247 |
if (my_b_write(cache,(unsigned char*) exchange->line_term->ptr(), |
1208.3.2
by brian
Update for Cursor renaming. |
1248 |
exchange->line_term->length())) |
1
by brian
clean slate |
1249 |
goto err; |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1250 |
return(0); |
1
by brian
clean slate |
1251 |
err: |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1252 |
return(1); |
1
by brian
clean slate |
1253 |
}
|
1254 |
||
1255 |
||
1256 |
/***************************************************************************
|
|
1257 |
** Dump of select to a binary file
|
|
1258 |
***************************************************************************/
|
|
1259 |
||
1260 |
||
1261 |
int
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1262 |
select_dump::prepare(List<Item> &, Select_Lex_Unit *u) |
1
by brian
clean slate |
1263 |
{
|
1264 |
unit= u; |
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1265 |
return (int) ((file= create_file(session, path, exchange, cache)) < 0); |
1
by brian
clean slate |
1266 |
}
|
1267 |
||
1268 |
||
1269 |
bool select_dump::send_data(List<Item> &items) |
|
1270 |
{
|
|
1271 |
List_iterator_fast<Item> li(items); |
|
1272 |
char buff[MAX_FIELD_WIDTH]; |
|
1273 |
String tmp(buff,sizeof(buff),&my_charset_bin),*res; |
|
1274 |
tmp.length(0); |
|
1275 |
Item *item; |
|
1276 |
||
1277 |
if (unit->offset_limit_cnt) |
|
1278 |
{ // using limit offset,count |
|
1279 |
unit->offset_limit_cnt--; |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1280 |
return(0); |
1
by brian
clean slate |
1281 |
}
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1282 |
if (row_count++ > 1) |
1
by brian
clean slate |
1283 |
{
|
1284 |
my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); |
|
1285 |
goto err; |
|
1286 |
}
|
|
1287 |
while ((item=li++)) |
|
1288 |
{
|
|
1289 |
res=item->str_result(&tmp); |
|
1290 |
if (!res) // If NULL |
|
1291 |
{
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1292 |
if (my_b_write(cache,(unsigned char*) "",1)) |
1
by brian
clean slate |
1293 |
goto err; |
1294 |
}
|
|
1241.9.49
by Monty Taylor
Removed one more public IO_CACHE. |
1295 |
else if (my_b_write(cache,(unsigned char*) res->ptr(),res->length())) |
1
by brian
clean slate |
1296 |
{
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
1297 |
my_error(ER_ERROR_ON_WRITE, MYF(0), path, errno); |
1
by brian
clean slate |
1298 |
goto err; |
1299 |
}
|
|
1300 |
}
|
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1301 |
return(0); |
1
by brian
clean slate |
1302 |
err: |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1303 |
return(1); |
1
by brian
clean slate |
1304 |
}
|
1305 |
||
1306 |
||
1307 |
select_subselect::select_subselect(Item_subselect *item_arg) |
|
1308 |
{
|
|
1309 |
item= item_arg; |
|
1310 |
}
|
|
1311 |
||
1312 |
||
1313 |
bool select_singlerow_subselect::send_data(List<Item> &items) |
|
1314 |
{
|
|
1315 |
Item_singlerow_subselect *it= (Item_singlerow_subselect *)item; |
|
1316 |
if (it->assigned()) |
|
1317 |
{
|
|
1318 |
my_message(ER_SUBQUERY_NO_1_ROW, ER(ER_SUBQUERY_NO_1_ROW), MYF(0)); |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1319 |
return(1); |
1
by brian
clean slate |
1320 |
}
|
1321 |
if (unit->offset_limit_cnt) |
|
1322 |
{ // Using limit offset,count |
|
1323 |
unit->offset_limit_cnt--; |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1324 |
return(0); |
1
by brian
clean slate |
1325 |
}
|
1326 |
List_iterator_fast<Item> li(items); |
|
1327 |
Item *val_item; |
|
482
by Brian Aker
Remove uint. |
1328 |
for (uint32_t i= 0; (val_item= li++); i++) |
1
by brian
clean slate |
1329 |
it->store(i, val_item); |
1330 |
it->assigned(1); |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1331 |
return(0); |
1
by brian
clean slate |
1332 |
}
|
1333 |
||
1334 |
||
1335 |
void select_max_min_finder_subselect::cleanup() |
|
1336 |
{
|
|
1337 |
cache= 0; |
|
1338 |
}
|
|
1339 |
||
1340 |
||
1341 |
bool select_max_min_finder_subselect::send_data(List<Item> &items) |
|
1342 |
{
|
|
1343 |
Item_maxmin_subselect *it= (Item_maxmin_subselect *)item; |
|
1344 |
List_iterator_fast<Item> li(items); |
|
1345 |
Item *val_item= li++; |
|
1346 |
it->register_value(); |
|
1347 |
if (it->assigned()) |
|
1348 |
{
|
|
1349 |
cache->store(val_item); |
|
1350 |
if ((this->*op)()) |
|
1351 |
it->store(0, cache); |
|
1352 |
}
|
|
1353 |
else
|
|
1354 |
{
|
|
1355 |
if (!cache) |
|
1356 |
{
|
|
1357 |
cache= Item_cache::get_cache(val_item); |
|
1358 |
switch (val_item->result_type()) |
|
1359 |
{
|
|
1360 |
case REAL_RESULT: |
|
1361 |
op= &select_max_min_finder_subselect::cmp_real; |
|
1362 |
break; |
|
1363 |
case INT_RESULT: |
|
1364 |
op= &select_max_min_finder_subselect::cmp_int; |
|
1365 |
break; |
|
1366 |
case STRING_RESULT: |
|
1367 |
op= &select_max_min_finder_subselect::cmp_str; |
|
1368 |
break; |
|
1369 |
case DECIMAL_RESULT: |
|
1370 |
op= &select_max_min_finder_subselect::cmp_decimal; |
|
1371 |
break; |
|
1372 |
case ROW_RESULT: |
|
1373 |
// This case should never be choosen
|
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1374 |
assert(0); |
1
by brian
clean slate |
1375 |
op= 0; |
1376 |
}
|
|
1377 |
}
|
|
1378 |
cache->store(val_item); |
|
1379 |
it->store(0, cache); |
|
1380 |
}
|
|
1381 |
it->assigned(1); |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1382 |
return(0); |
1
by brian
clean slate |
1383 |
}
|
1384 |
||
1385 |
bool select_max_min_finder_subselect::cmp_real() |
|
1386 |
{
|
|
1387 |
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0); |
|
1388 |
double val1= cache->val_real(), val2= maxmin->val_real(); |
|
1389 |
if (fmax) |
|
1390 |
return (cache->null_value && !maxmin->null_value) || |
|
1391 |
(!cache->null_value && !maxmin->null_value && |
|
1392 |
val1 > val2); |
|
1393 |
return (maxmin->null_value && !cache->null_value) || |
|
1394 |
(!cache->null_value && !maxmin->null_value && |
|
1395 |
val1 < val2); |
|
1396 |
}
|
|
1397 |
||
1398 |
bool select_max_min_finder_subselect::cmp_int() |
|
1399 |
{
|
|
1400 |
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0); |
|
152
by Brian Aker
longlong replacement |
1401 |
int64_t val1= cache->val_int(), val2= maxmin->val_int(); |
1
by brian
clean slate |
1402 |
if (fmax) |
1403 |
return (cache->null_value && !maxmin->null_value) || |
|
1404 |
(!cache->null_value && !maxmin->null_value && |
|
1405 |
val1 > val2); |
|
1406 |
return (maxmin->null_value && !cache->null_value) || |
|
1407 |
(!cache->null_value && !maxmin->null_value && |
|
1408 |
val1 < val2); |
|
1409 |
}
|
|
1410 |
||
1411 |
bool select_max_min_finder_subselect::cmp_decimal() |
|
1412 |
{
|
|
1413 |
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0); |
|
1414 |
my_decimal cval, *cvalue= cache->val_decimal(&cval); |
|
1415 |
my_decimal mval, *mvalue= maxmin->val_decimal(&mval); |
|
1416 |
if (fmax) |
|
1417 |
return (cache->null_value && !maxmin->null_value) || |
|
1418 |
(!cache->null_value && !maxmin->null_value && |
|
1419 |
my_decimal_cmp(cvalue, mvalue) > 0) ; |
|
1420 |
return (maxmin->null_value && !cache->null_value) || |
|
1421 |
(!cache->null_value && !maxmin->null_value && |
|
1422 |
my_decimal_cmp(cvalue,mvalue) < 0); |
|
1423 |
}
|
|
1424 |
||
1425 |
bool select_max_min_finder_subselect::cmp_str() |
|
1426 |
{
|
|
1427 |
String *val1, *val2, buf1, buf2; |
|
1428 |
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0); |
|
1429 |
/*
|
|
1430 |
as far as both operand is Item_cache buf1 & buf2 will not be used,
|
|
1431 |
but added for safety
|
|
1432 |
*/
|
|
1433 |
val1= cache->val_str(&buf1); |
|
1434 |
val2= maxmin->val_str(&buf1); |
|
1435 |
if (fmax) |
|
1436 |
return (cache->null_value && !maxmin->null_value) || |
|
1437 |
(!cache->null_value && !maxmin->null_value && |
|
1438 |
sortcmp(val1, val2, cache->collation.collation) > 0) ; |
|
1439 |
return (maxmin->null_value && !cache->null_value) || |
|
1440 |
(!cache->null_value && !maxmin->null_value && |
|
1441 |
sortcmp(val1, val2, cache->collation.collation) < 0); |
|
1442 |
}
|
|
1443 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1444 |
bool select_exists_subselect::send_data(List<Item> &) |
1
by brian
clean slate |
1445 |
{
|
1446 |
Item_exists_subselect *it= (Item_exists_subselect *)item; |
|
1447 |
if (unit->offset_limit_cnt) |
|
77.1.45
by Monty Taylor
Warning fixes. |
1448 |
{ // Using limit offset,count |
1
by brian
clean slate |
1449 |
unit->offset_limit_cnt--; |
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1450 |
return(0); |
1
by brian
clean slate |
1451 |
}
|
1452 |
it->value= 1; |
|
1453 |
it->assigned(1); |
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1454 |
return(0); |
1
by brian
clean slate |
1455 |
}
|
1456 |
||
406
by Brian Aker
Cleanup around Query_arena. |
1457 |
/*
|
1458 |
Don't free mem_root, as mem_root is freed in the end of dispatch_command
|
|
1459 |
(once for any command).
|
|
1460 |
*/
|
|
520.1.21
by Brian Aker
THD -> Session rename |
1461 |
void Session::end_statement() |
1
by brian
clean slate |
1462 |
{
|
1463 |
/* Cleanup SQL processing state to reuse this statement in next query. */
|
|
1464 |
lex_end(lex); |
|
1465 |
}
|
|
1466 |
||
520.1.21
by Brian Aker
THD -> Session rename |
1467 |
bool Session::copy_db_to(char **p_db, size_t *p_db_length) |
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
1468 |
{
|
1220.1.9
by Brian Aker
Remove char *db from session, and replaces it with std::string. |
1469 |
if (db.empty()) |
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
1470 |
{
|
1471 |
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); |
|
1472 |
return true; |
|
1473 |
}
|
|
1220.1.9
by Brian Aker
Remove char *db from session, and replaces it with std::string. |
1474 |
*p_db= strmake(db.c_str(), db.length()); |
1475 |
*p_db_length= db.length(); |
|
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
1476 |
return false; |
1477 |
}
|
|
1478 |
||
1101.1.16
by Monty Taylor
Reverted 1103 |
1479 |
/****************************************************************************
|
1480 |
Tmp_Table_Param
|
|
1481 |
****************************************************************************/
|
|
1482 |
||
1483 |
void Tmp_Table_Param::init() |
|
1484 |
{
|
|
1485 |
field_count= sum_func_count= func_count= hidden_field_count= 0; |
|
1486 |
group_parts= group_length= group_null_parts= 0; |
|
1487 |
quick_group= 1; |
|
1488 |
table_charset= 0; |
|
1489 |
precomputed_group_by= 0; |
|
1490 |
}
|
|
1491 |
||
1492 |
void Tmp_Table_Param::cleanup(void) |
|
1493 |
{
|
|
1494 |
/* Fix for Intel compiler */
|
|
1495 |
if (copy_field) |
|
1496 |
{
|
|
1497 |
delete [] copy_field; |
|
1498 |
save_copy_field= copy_field= 0; |
|
1499 |
}
|
|
1500 |
}
|
|
1501 |
||
520.1.21
by Brian Aker
THD -> Session rename |
1502 |
void Session::send_kill_message() const |
202.3.6
by Monty Taylor
First pass at gettexizing the error messages. |
1503 |
{
|
1504 |
int err= killed_errno(); |
|
1505 |
if (err) |
|
1506 |
my_message(err, ER(err), MYF(0)); |
|
1507 |
}
|
|
1
by brian
clean slate |
1508 |
|
520.1.21
by Brian Aker
THD -> Session rename |
1509 |
void Session::set_status_var_init() |
1
by brian
clean slate |
1510 |
{
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
1511 |
memset(&status_var, 0, sizeof(status_var)); |
1
by brian
clean slate |
1512 |
}
|
1513 |
||
1514 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
1515 |
bool Session::set_db(const std::string &new_db) |
656.1.22
by Monty Taylor
Removed my_malloc related stuff from log_event and session. |
1516 |
{
|
1273
by Brian Aker
Revert db patch. |
1517 |
/* Do not reallocate memory if current chunk is big enough. */
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
1518 |
if (new_db.length()) |
1273
by Brian Aker
Revert db patch. |
1519 |
db= new_db; |
1520 |
else
|
|
1521 |
db.clear(); |
|
1220.1.9
by Brian Aker
Remove char *db from session, and replaces it with std::string. |
1522 |
|
1523 |
return false; |
|
656.1.22
by Monty Taylor
Removed my_malloc related stuff from log_event and session. |
1524 |
}
|
1525 |
||
1273
by Brian Aker
Revert db patch. |
1526 |
|
1235.4.2
by Stewart Smith
start using a set of classes for database names, enforcing type safety when converting from what user entered to a normalised form. |
1527 |
|
656.1.22
by Monty Taylor
Removed my_malloc related stuff from log_event and session. |
1528 |
|
1
by brian
clean slate |
1529 |
/**
|
1530 |
Check the killed state of a user thread
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1531 |
@param session user thread
|
1
by brian
clean slate |
1532 |
@retval 0 the user thread is active
|
1533 |
@retval 1 the user thread has been killed
|
|
1534 |
*/
|
|
1471.5.2
by mordred
Removed some extern "C" bits that were screwing with the callstack. |
1535 |
int session_killed(const Session *session) |
1
by brian
clean slate |
1536 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1537 |
return(session->killed); |
1
by brian
clean slate |
1538 |
}
|
1539 |
||
1540 |
||
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
1541 |
const struct charset_info_st *session_charset(Session *session) |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1542 |
{
|
1543 |
return(session->charset()); |
|
1544 |
}
|
|
1545 |
||
1
by brian
clean slate |
1546 |
/**
|
1547 |
Mark transaction to rollback and mark error as fatal to a sub-statement.
|
|
1548 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1549 |
@param session Thread handle
|
51.1.50
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1550 |
@param all true <=> rollback main transaction.
|
1
by brian
clean slate |
1551 |
*/
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1552 |
void mark_transaction_to_rollback(Session *session, bool all) |
1
by brian
clean slate |
1553 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1554 |
if (session) |
1
by brian
clean slate |
1555 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1556 |
session->is_fatal_sub_stmt_error= true; |
1557 |
session->transaction_rollback_request= all; |
|
1
by brian
clean slate |
1558 |
}
|
1559 |
}
|
|
1560 |
||
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1561 |
void Session::disconnect(uint32_t errcode, bool should_lock) |
575.4.7
by Monty Taylor
More header cleanup. |
1562 |
{
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1563 |
/* Allow any plugins to cleanup their session variables */
|
1564 |
plugin_sessionvar_cleanup(this); |
|
1565 |
||
1566 |
/* If necessary, log any aborted or unauthorized connections */
|
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
1567 |
if (killed || client->wasAborted()) |
1537.2.1
by Joe Daly
add statistics_variables.h |
1568 |
{
|
1569 |
status_var_increment(current_global_counters.aborted_threads); |
|
1570 |
}
|
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1571 |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
1572 |
if (client->wasAborted()) |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1573 |
{
|
1574 |
if (! killed && variables.log_warnings > 1) |
|
1575 |
{
|
|
1273.11.1
by Dennis Schoen
rename class |
1576 |
SecurityContext *sctx= &security_ctx; |
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1577 |
|
1578 |
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION) |
|
1579 |
, thread_id |
|
1220.1.9
by Brian Aker
Remove char *db from session, and replaces it with std::string. |
1580 |
, (db.empty() ? "unconnected" : db.c_str()) |
1273.11.2
by Dennis Schoen
make data members private |
1581 |
, sctx->getUser().empty() == false ? sctx->getUser().c_str() : "unauthenticated" |
1582 |
, sctx->getIp().c_str() |
|
934.2.6
by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h |
1583 |
, (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR))); |
1584 |
}
|
|
1585 |
}
|
|
1586 |
||
1587 |
/* Close out our connection to the client */
|
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
1588 |
if (should_lock) |
575.4.7
by Monty Taylor
More header cleanup. |
1589 |
(void) pthread_mutex_lock(&LOCK_thread_count); |
693
by Brian Aker
Cleaning up session class. |
1590 |
killed= Session::KILL_CONNECTION; |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
1591 |
if (client->isConnected()) |
575.4.7
by Monty Taylor
More header cleanup. |
1592 |
{
|
1593 |
if (errcode) |
|
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
1594 |
{
|
1595 |
/*my_error(errcode, ER(errcode));*/
|
|
971.6.11
by Eric Day
Removed purecov messages. |
1596 |
client->sendError(errcode, ER(errcode)); |
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
1597 |
}
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
1598 |
client->close(); |
575.4.7
by Monty Taylor
More header cleanup. |
1599 |
}
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
1600 |
if (should_lock) |
575.4.7
by Monty Taylor
More header cleanup. |
1601 |
(void) pthread_mutex_unlock(&LOCK_thread_count); |
1602 |
}
|
|
735
by Brian Aker
Refactor session. |
1603 |
|
1604 |
void Session::reset_for_next_command() |
|
1605 |
{
|
|
1606 |
free_list= 0; |
|
1607 |
select_number= 1; |
|
1608 |
/*
|
|
1609 |
Those two lines below are theoretically unneeded as
|
|
1610 |
Session::cleanup_after_query() should take care of this already.
|
|
1611 |
*/
|
|
1612 |
auto_inc_intervals_in_cur_stmt_for_binlog.empty(); |
|
1613 |
||
1055.2.17
by Jay Pipes
More style cleanups in Session |
1614 |
is_fatal_error= false; |
735
by Brian Aker
Refactor session. |
1615 |
server_status&= ~ (SERVER_MORE_RESULTS_EXISTS | |
1616 |
SERVER_QUERY_NO_INDEX_USED | |
|
1617 |
SERVER_QUERY_NO_GOOD_INDEX_USED); |
|
1618 |
||
1619 |
clear_error(); |
|
1620 |
main_da.reset_diagnostics_area(); |
|
1621 |
total_warn_count=0; // Warnings for this query |
|
1622 |
sent_row_count= examined_row_count= 0; |
|
1623 |
}
|
|
793
by Brian Aker
Pass through on refactoring functions to clases. |
1624 |
|
1625 |
/*
|
|
1626 |
Close all temporary tables created by 'CREATE TEMPORARY TABLE' for thread
|
|
1627 |
*/
|
|
1628 |
||
1629 |
void Session::close_temporary_tables() |
|
1630 |
{
|
|
1631 |
Table *table; |
|
798.2.20
by Brian Aker
More cleanup of binlog.isopen |
1632 |
Table *tmp_next; |
793
by Brian Aker
Pass through on refactoring functions to clases. |
1633 |
|
1395.1.11
by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking |
1634 |
if (not temporary_tables) |
793
by Brian Aker
Pass through on refactoring functions to clases. |
1635 |
return; |
1636 |
||
798.2.20
by Brian Aker
More cleanup of binlog.isopen |
1637 |
for (table= temporary_tables; table; table= tmp_next) |
1638 |
{
|
|
1608
by Brian Aker
This encapsulates prev/next. |
1639 |
tmp_next= table->getNext(); |
1395.1.11
by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking |
1640 |
nukeTable(table); |
798.2.20
by Brian Aker
More cleanup of binlog.isopen |
1641 |
}
|
1046.1.6
by Brian Aker
Formatting/style cleanup. |
1642 |
temporary_tables= NULL; |
793
by Brian Aker
Pass through on refactoring functions to clases. |
1643 |
}
|
855
by Brian Aker
Refactor reset of status. |
1644 |
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1645 |
/*
|
1646 |
unlink from session->temporary tables and close temporary table
|
|
1647 |
*/
|
|
1648 |
||
1216.1.1
by Brian Aker
Move print_error up to Engine. |
1649 |
void Session::close_temporary_table(Table *table) |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1650 |
{
|
1608
by Brian Aker
This encapsulates prev/next. |
1651 |
if (table->getPrev()) |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1652 |
{
|
1608
by Brian Aker
This encapsulates prev/next. |
1653 |
table->getPrev()->setNext(table->getNext()); |
1654 |
if (table->getPrev()->getNext()) |
|
1655 |
{
|
|
1656 |
table->getNext()->setPrev(table->getPrev()); |
|
1657 |
}
|
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1658 |
}
|
1659 |
else
|
|
1660 |
{
|
|
1661 |
/* removing the item from the list */
|
|
1662 |
assert(table == temporary_tables); |
|
1663 |
/*
|
|
1664 |
slave must reset its temporary list pointer to zero to exclude
|
|
1665 |
passing non-zero value to end_slave via rli->save_temporary_tables
|
|
1666 |
when no temp tables opened, see an invariant below.
|
|
1667 |
*/
|
|
1608
by Brian Aker
This encapsulates prev/next. |
1668 |
temporary_tables= table->getNext(); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1669 |
if (temporary_tables) |
1608
by Brian Aker
This encapsulates prev/next. |
1670 |
{
|
1671 |
table->getNext()->setPrev(NULL); |
|
1672 |
}
|
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1673 |
}
|
1395.1.11
by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking |
1674 |
nukeTable(table); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1675 |
}
|
1676 |
||
1677 |
/*
|
|
1395.1.11
by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking |
1678 |
Close and drop a temporary table
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1679 |
|
1680 |
NOTE
|
|
1681 |
This dosn't unlink table from session->temporary
|
|
1682 |
If this is needed, use close_temporary_table()
|
|
1683 |
*/
|
|
1684 |
||
1395.1.11
by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking |
1685 |
void Session::nukeTable(Table *table) |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1686 |
{
|
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1687 |
plugin::StorageEngine *table_type= table->getShare()->db_type(); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1688 |
|
1109.1.4
by Brian Aker
More Table refactor |
1689 |
table->free_io_cache(); |
1502.1.3
by Brian Aker
Cleanup to use references. |
1690 |
table->delete_table(false); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1691 |
|
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1692 |
TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath()); |
1395.1.8
by Brian Aker
Cleanup usage of TI so that the NULL ones no longer exist. |
1693 |
rm_temporary_table(table_type, identifier); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1694 |
|
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1695 |
delete table->getMutableShare(); |
1237.6.12
by Brian Aker
Adding patch for engine methods for definition files. |
1696 |
|
1216.1.1
by Brian Aker
Move print_error up to Engine. |
1697 |
/* This makes me sad, but we're allocating it via malloc */
|
1220.1.8
by Brian Aker
Fix for Valgrind. |
1698 |
free(table); |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1699 |
}
|
855
by Brian Aker
Refactor reset of status. |
1700 |
|
1701 |
/** Clear most status variables. */
|
|
1702 |
extern time_t flush_status_time; |
|
1703 |
||
1704 |
void Session::refresh_status() |
|
1705 |
{
|
|
1706 |
pthread_mutex_lock(&LOCK_status); |
|
1707 |
||
1708 |
/* Reset thread's status variables */
|
|
1709 |
memset(&status_var, 0, sizeof(status_var)); |
|
1710 |
||
1711 |
/* Reset the counters of all key caches (default and named). */
|
|
1106.4.2
by Brian Aker
Remove multi key cache |
1712 |
reset_key_cache_counters(); |
855
by Brian Aker
Refactor reset of status. |
1713 |
flush_status_time= time((time_t*) 0); |
1537.2.1
by Joe Daly
add statistics_variables.h |
1714 |
current_global_counters.max_used_connections= 1; /* We set it to one, because we know we exist */ |
855
by Brian Aker
Refactor reset of status. |
1715 |
pthread_mutex_unlock(&LOCK_status); |
1716 |
}
|
|
995
by Brian Aker
Refactor get_variable to session |
1717 |
|
1718 |
user_var_entry *Session::getVariable(LEX_STRING &name, bool create_if_not_exists) |
|
1719 |
{
|
|
1720 |
user_var_entry *entry= NULL; |
|
1721 |
||
1722 |
entry= (user_var_entry*) hash_search(&user_vars, (unsigned char*) name.str, name.length); |
|
1723 |
||
1724 |
if ((entry == NULL) && create_if_not_exists) |
|
1725 |
{
|
|
1726 |
if (!hash_inited(&user_vars)) |
|
1089.1.5
by Brian Aker
Cleanup of user_var |
1727 |
return NULL; |
1728 |
entry= new (nothrow) user_var_entry(name.str, query_id); |
|
1729 |
||
1730 |
if (entry == NULL) |
|
1731 |
return NULL; |
|
1732 |
||
995
by Brian Aker
Refactor get_variable to session |
1733 |
if (my_hash_insert(&user_vars, (unsigned char*) entry)) |
1734 |
{
|
|
1735 |
assert(1); |
|
1510.3.1
by mordred
Fixed error found by cppcheck - entry here is allocated using new, thus should be deleted. |
1736 |
delete entry; |
995
by Brian Aker
Refactor get_variable to session |
1737 |
return 0; |
1738 |
}
|
|
1739 |
||
1740 |
}
|
|
1741 |
||
1742 |
return entry; |
|
1743 |
}
|
|
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1744 |
|
1745 |
void Session::mark_temp_tables_as_free_for_reuse() |
|
1746 |
{
|
|
1608
by Brian Aker
This encapsulates prev/next. |
1747 |
for (Table *table= temporary_tables ; table ; table= table->getNext()) |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1748 |
{
|
1749 |
if (table->query_id == query_id) |
|
1750 |
{
|
|
1751 |
table->query_id= 0; |
|
1208.3.2
by brian
Update for Cursor renaming. |
1752 |
table->cursor->ha_reset(); |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1753 |
}
|
1754 |
}
|
|
1755 |
}
|
|
1756 |
||
1757 |
void Session::mark_used_tables_as_free_for_reuse(Table *table) |
|
1758 |
{
|
|
1608
by Brian Aker
This encapsulates prev/next. |
1759 |
for (; table ; table= table->getNext()) |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1760 |
{
|
1761 |
if (table->query_id == query_id) |
|
1762 |
{
|
|
1763 |
table->query_id= 0; |
|
1208.3.2
by brian
Update for Cursor renaming. |
1764 |
table->cursor->ha_reset(); |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1765 |
}
|
1766 |
}
|
|
1767 |
}
|
|
1768 |
||
1769 |
/*
|
|
1055.2.24
by Jay Pipes
Merge with trunk and resolve conflicts. |
1770 |
Unlocks tables and frees derived tables.
|
1771 |
Put all normal tables used by thread in free list.
|
|
1772 |
||
1773 |
It will only close/mark as free for reuse tables opened by this
|
|
1774 |
substatement, it will also check if we are closing tables after
|
|
1775 |
execution of complete query (i.e. we are on upper level) and will
|
|
1776 |
leave prelocked mode if needed.
|
|
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1777 |
*/
|
1778 |
void Session::close_thread_tables() |
|
1779 |
{
|
|
1780 |
if (derived_tables) |
|
1532.1.1
by Brian Aker
Merge of change to flip table instance to be share instance |
1781 |
derived_tables= NULL; // They should all be invalid by this point |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1782 |
|
1783 |
/*
|
|
1784 |
Mark all temporary tables used by this statement as free for reuse.
|
|
1785 |
*/
|
|
1786 |
mark_temp_tables_as_free_for_reuse(); |
|
1787 |
/*
|
|
1788 |
Let us commit transaction for statement. Since in 5.0 we only have
|
|
1789 |
one statement transaction and don't allow several nested statement
|
|
1790 |
transactions this call will do nothing if we are inside of stored
|
|
1791 |
function or trigger (i.e. statement transaction is already active and
|
|
1792 |
does not belong to statement for which we do close_thread_tables()).
|
|
1793 |
TODO: This should be fixed in later releases.
|
|
1794 |
*/
|
|
1795 |
{
|
|
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
1796 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1797 |
main_da.can_overwrite_status= true; |
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
1798 |
transaction_services.autocommitOrRollback(this, is_error()); |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
1799 |
main_da.can_overwrite_status= false; |
1800 |
transaction.stmt.reset(); |
|
1801 |
}
|
|
1802 |
||
1803 |
if (lock) |
|
1804 |
{
|
|
1805 |
/*
|
|
1806 |
For RBR we flush the pending event just before we unlock all the
|
|
1807 |
tables. This means that we are at the end of a topmost
|
|
1808 |
statement, so we ensure that the STMT_END_F flag is set on the
|
|
1809 |
pending event. For statements that are *inside* stored
|
|
1810 |
functions, the pending event will not be flushed: that will be
|
|
1811 |
handled either before writing a query log event (inside
|
|
1812 |
binlog_query()) or when preparing a pending event.
|
|
1813 |
*/
|
|
1814 |
mysql_unlock_tables(this, lock); |
|
1815 |
lock= 0; |
|
1816 |
}
|
|
1817 |
/*
|
|
1818 |
Note that we need to hold LOCK_open while changing the
|
|
1819 |
open_tables list. Another thread may work on it.
|
|
1820 |
(See: remove_table_from_cache(), mysql_wait_completed_table())
|
|
1821 |
Closing a MERGE child before the parent would be fatal if the
|
|
1822 |
other thread tries to abort the MERGE lock in between.
|
|
1823 |
*/
|
|
1824 |
if (open_tables) |
|
1825 |
close_open_tables(); |
|
1826 |
}
|
|
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1827 |
|
1828 |
void Session::close_tables_for_reopen(TableList **tables) |
|
1829 |
{
|
|
1830 |
/*
|
|
1831 |
If table list consists only from tables from prelocking set, table list
|
|
1832 |
for new attempt should be empty, so we have to update list's root pointer.
|
|
1833 |
*/
|
|
1834 |
if (lex->first_not_own_table() == *tables) |
|
1835 |
*tables= 0; |
|
1836 |
lex->chop_off_not_own_tables(); |
|
1837 |
for (TableList *tmp= *tables; tmp; tmp= tmp->next_global) |
|
1838 |
tmp->table= 0; |
|
1839 |
close_thread_tables(); |
|
1840 |
}
|
|
1841 |
||
1109.1.3
by Brian Aker
Move names around a bit (to align similar methods) |
1842 |
bool Session::openTablesLock(TableList *tables) |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1843 |
{
|
1844 |
uint32_t counter; |
|
1845 |
bool need_reopen; |
|
1846 |
||
1847 |
for ( ; ; ) |
|
1848 |
{
|
|
1109.1.2
by Brian Aker
More from the table patch |
1849 |
if (open_tables_from_list(&tables, &counter)) |
1850 |
return true; |
|
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1851 |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
1852 |
if (not lock_tables(tables, counter, &need_reopen)) |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1853 |
break; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
1854 |
if (not need_reopen) |
1109.1.2
by Brian Aker
More from the table patch |
1855 |
return true; |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1856 |
close_tables_for_reopen(&tables); |
1857 |
}
|
|
1858 |
if ((mysql_handle_derived(lex, &mysql_derived_prepare) || |
|
1859 |
(fill_derived_tables() && |
|
1860 |
mysql_handle_derived(lex, &mysql_derived_filling)))) |
|
971.6.11
by Eric Day
Removed purecov messages. |
1861 |
return true; |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1862 |
|
1109.1.2
by Brian Aker
More from the table patch |
1863 |
return false; |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1864 |
}
|
1865 |
||
1109.1.3
by Brian Aker
Move names around a bit (to align similar methods) |
1866 |
bool Session::openTables(TableList *tables, uint32_t flags) |
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1867 |
{
|
1868 |
uint32_t counter; |
|
1090.1.3
by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart. |
1869 |
bool ret= fill_derived_tables(); |
1870 |
assert(ret == false); |
|
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1871 |
if (open_tables_from_list(&tables, &counter, flags) || |
1872 |
mysql_handle_derived(lex, &mysql_derived_prepare)) |
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
1873 |
{
|
971.6.11
by Eric Day
Removed purecov messages. |
1874 |
return true; |
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
1875 |
}
|
1054.1.9
by Brian Aker
This is a large number of refactors against the Session class for its |
1876 |
return false; |
1877 |
}
|
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1878 |
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
1879 |
/*
|
1880 |
@note "best_effort" is used in cases were if a failure occurred on this
|
|
1881 |
operation it would not be surprising because we are only removing because there
|
|
1882 |
might be an issue (lame engines).
|
|
1883 |
*/
|
|
1884 |
||
1885 |
bool Session::rm_temporary_table(TableIdentifier &identifier, bool best_effort) |
|
1223.4.8
by Brian Aker
More table identifier love :) |
1886 |
{
|
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1887 |
if (plugin::StorageEngine::dropTable(*this, identifier)) |
1223.4.8
by Brian Aker
More table identifier love :) |
1888 |
{
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
1889 |
if (not best_effort) |
1890 |
{
|
|
1891 |
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"), |
|
1892 |
identifier.getSQLPath().c_str(), errno); |
|
1893 |
}
|
|
1320.1.9
by Brian Aker
Removing special case dropTable() |
1894 |
|
1895 |
return true; |
|
1223.4.8
by Brian Aker
More table identifier love :) |
1896 |
}
|
1320.1.9
by Brian Aker
Removing special case dropTable() |
1897 |
|
1898 |
return false; |
|
1223.4.8
by Brian Aker
More table identifier love :) |
1899 |
}
|
1900 |
||
1395.1.8
by Brian Aker
Cleanup usage of TI so that the NULL ones no longer exist. |
1901 |
bool Session::rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier) |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1902 |
{
|
1903 |
assert(base); |
|
1904 |
||
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1905 |
if (plugin::StorageEngine::dropTable(*this, *base, identifier)) |
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1906 |
{
|
1907 |
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"), |
|
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1908 |
identifier.getSQLPath().c_str(), errno); |
1909 |
||
1910 |
return true; |
|
1911 |
}
|
|
1912 |
||
1913 |
return false; |
|
1914 |
}
|
|
1915 |
||
1916 |
/**
|
|
1917 |
@note this will be removed, I am looking through Hudson to see if it is finding
|
|
1918 |
any tables that are missed during cleanup.
|
|
1919 |
*/
|
|
1920 |
void Session::dumpTemporaryTableNames(const char *foo) |
|
1921 |
{
|
|
1922 |
Table *table; |
|
1923 |
||
1924 |
if (not temporary_tables) |
|
1925 |
return; |
|
1926 |
||
1927 |
cerr << "Begin Run: " << foo << "\n"; |
|
1608
by Brian Aker
This encapsulates prev/next. |
1928 |
for (table= temporary_tables; table; table= table->getNext()) |
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1929 |
{
|
1930 |
bool have_proto= false; |
|
1931 |
||
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1932 |
message::Table *proto= table->getShare()->getTableProto(); |
1933 |
if (table->getShare()->getTableProto()) |
|
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1934 |
have_proto= true; |
1935 |
||
1936 |
const char *answer= have_proto ? "true" : "false"; |
|
1937 |
||
1938 |
if (have_proto) |
|
1939 |
{
|
|
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1940 |
cerr << "\tTable Name " << table->getShare()->getSchemaName() << "." << table->getShare()->getTableName() << " : " << answer << "\n"; |
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1941 |
cerr << "\t\t Proto " << proto->schema() << " " << proto->name() << "\n"; |
1942 |
}
|
|
1943 |
else
|
|
1532.1.15
by Brian Aker
Partial encapsulation of TableShare from Table. |
1944 |
cerr << "\tTabl;e Name " << table->getShare()->getSchemaName() << "." << table->getShare()->getTableName() << " : " << answer << "\n"; |
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
1945 |
}
|
1109.1.1
by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be |
1946 |
}
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
1947 |
|
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1948 |
bool Session::storeTableMessage(TableIdentifier &identifier, message::Table &table_message) |
1949 |
{
|
|
1950 |
table_message_cache.insert(make_pair(identifier.getPath(), table_message)); |
|
1951 |
||
1952 |
return true; |
|
1953 |
}
|
|
1954 |
||
1955 |
bool Session::removeTableMessage(TableIdentifier &identifier) |
|
1956 |
{
|
|
1957 |
TableMessageCache::iterator iter; |
|
1958 |
||
1959 |
iter= table_message_cache.find(identifier.getPath()); |
|
1960 |
||
1372.1.4
by Brian Aker
Update to remove cache in enginges for per session (which also means... no |
1961 |
if (iter == table_message_cache.end()) |
1962 |
return false; |
|
1963 |
||
1964 |
table_message_cache.erase(iter); |
|
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1965 |
|
1966 |
return true; |
|
1967 |
}
|
|
1968 |
||
1969 |
bool Session::getTableMessage(TableIdentifier &identifier, message::Table &table_message) |
|
1970 |
{
|
|
1971 |
TableMessageCache::iterator iter; |
|
1972 |
||
1973 |
iter= table_message_cache.find(identifier.getPath()); |
|
1974 |
||
1372.1.4
by Brian Aker
Update to remove cache in enginges for per session (which also means... no |
1975 |
if (iter == table_message_cache.end()) |
1976 |
return false; |
|
1977 |
||
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1978 |
table_message.CopyFrom(((*iter).second)); |
1979 |
||
1980 |
return true; |
|
1981 |
}
|
|
1982 |
||
1983 |
bool Session::doesTableMessageExist(TableIdentifier &identifier) |
|
1984 |
{
|
|
1985 |
TableMessageCache::iterator iter; |
|
1986 |
||
1987 |
iter= table_message_cache.find(identifier.getPath()); |
|
1988 |
||
1372.1.4
by Brian Aker
Update to remove cache in enginges for per session (which also means... no |
1989 |
if (iter == table_message_cache.end()) |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1990 |
{
|
1372.1.4
by Brian Aker
Update to remove cache in enginges for per session (which also means... no |
1991 |
return false; |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1992 |
}
|
1993 |
||
1372.1.4
by Brian Aker
Update to remove cache in enginges for per session (which also means... no |
1994 |
return true; |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
1995 |
}
|
1996 |
||
1395.1.1
by Brian Aker
Fixes for alter table to make sure that the proto on disk is valid. |
1997 |
bool Session::renameTableMessage(TableIdentifier &from, TableIdentifier &to) |
1390
by Brian Aker
Update interface to use Identifiers directly. |
1998 |
{
|
1999 |
TableMessageCache::iterator iter; |
|
2000 |
||
2001 |
table_message_cache[to.getPath()]= table_message_cache[from.getPath()]; |
|
2002 |
||
1395.1.1
by Brian Aker
Fixes for alter table to make sure that the proto on disk is valid. |
2003 |
iter= table_message_cache.find(to.getPath()); |
2004 |
||
2005 |
if (iter == table_message_cache.end()) |
|
2006 |
{
|
|
2007 |
return false; |
|
2008 |
}
|
|
2009 |
||
1395.1.12
by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error |
2010 |
(*iter).second.set_schema(to.getSchemaName()); |
2011 |
(*iter).second.set_name(to.getTableName()); |
|
1390
by Brian Aker
Update interface to use Identifiers directly. |
2012 |
|
2013 |
return true; |
|
2014 |
}
|
|
2015 |
||
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
2016 |
TableShareInstance *Session::getTemporaryShare(TableIdentifier::Type type_arg) |
2017 |
{
|
|
2018 |
temporary_shares.push_back(new TableShareInstance(type_arg)); // This will not go into the tableshare cache, so no key is used. |
|
1532.1.1
by Brian Aker
Merge of change to flip table instance to be share instance |
2019 |
|
2020 |
TableShareInstance *tmp_share= temporary_shares.back(); |
|
2021 |
||
2022 |
assert(tmp_share); |
|
2023 |
||
2024 |
return tmp_share; |
|
2025 |
}
|
|
2026 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
2027 |
} /* namespace drizzled */ |