~drizzle-trunk/drizzle/development

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