~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
564
const char* Session::enter_cond(pthread_cond_t *cond,
565
                                pthread_mutex_t* mutex,
566
                                const char* msg)
567
{
568
  const char* old_msg = get_proc_info();
569
  safe_mutex_assert_owner(mutex);
570
  mysys_var->current_mutex = mutex;
571
  mysys_var->current_cond = cond;
572
  this->set_proc_info(msg);
573
  return old_msg;
574
}
575
576
void Session::exit_cond(const char* old_msg)
577
{
578
  /*
579
    Putting the mutex unlock in exit_cond() ensures that
580
    mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
581
    locked (if that would not be the case, you'll get a deadlock if someone
582
    does a Session::awake() on you).
583
  */
584
  pthread_mutex_unlock(mysys_var->current_mutex);
585
  pthread_mutex_lock(&mysys_var->mutex);
586
  mysys_var->current_mutex = 0;
587
  mysys_var->current_cond = 0;
588
  this->set_proc_info(old_msg);
589
  pthread_mutex_unlock(&mysys_var->mutex);
590
}
591
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...
592
bool Session::authenticate()
593
{
594
  lex_start(this);
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
595
  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.
596
    return false;
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
597
1689.5.1 by Joseph Daly
remove increment calls
598
  status_var.aborted_connects++;
1625.2.1 by Joe Daly
initial user stats impl
599
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.
600
  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...
601
}
602
965 by Brian Aker
Merge with Jay
603
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...
604
{
1317.1.3 by Monty Taylor
Fixed Authentication plugin interface to use SecurityContext rather than the
605
  const string passwd_str(passwd, passwd_len);
606
  bool is_authenticated=
607
    plugin::Authentication::isAuthenticated(getSecurityContext(),
608
                                            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...
609
610
  if (is_authenticated != true)
611
  {
1689.5.1 by Joseph Daly
remove increment calls
612
    status_var.access_denied++;
1317.1.3 by Monty Taylor
Fixed Authentication plugin interface to use SecurityContext rather than the
613
    /* 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...
614
    return false;
615
  }
616
617
  /* Change database if necessary */
618
  if (in_db && in_db[0])
619
  {
1415 by Brian Aker
Mass overhaul to use schema_identifier.
620
    SchemaIdentifier identifier(in_db);
621
    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...
622
    {
623
      /* mysql_change_db() has pushed the error message. */
624
      return false;
625
    }
626
  }
627
  my_ok();
628
  password= test(passwd_len);          // remember for error messages
629
630
  /* Ready to handle queries */
631
  return true;
632
}
1 by brian
clean slate
633
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.
634
bool Session::executeStatement()
635
{
636
  char *l_packet= 0;
637
  uint32_t packet_length;
638
639
  enum enum_server_command l_command;
640
641
  /*
642
    indicator of uninitialized lex => normal flow of errors handling
643
    (see my_message_sql)
644
  */
645
  lex->current_select= 0;
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
646
  clear_error();
647
  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.
648
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
649
  if (client->readCommand(&l_packet, &packet_length) == false)
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
650
    return false;
651
652
  if (packet_length == 0)
653
    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.
654
655
  l_command= (enum enum_server_command) (unsigned char) l_packet[0];
656
657
  if (command >= COM_END)
658
    command= COM_END;                           // Wrong command
659
660
  assert(packet_length);
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
661
  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.
662
}
934.2.9 by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class.
663
664
bool Session::readAndStoreQuery(const char *in_packet, uint32_t in_packet_length)
665
{
666
  /* Remove garbage at start and end of query */
667
  while (in_packet_length > 0 && my_isspace(charset(), in_packet[0]))
668
  {
669
    in_packet++;
670
    in_packet_length--;
671
  }
672
  const char *pos= in_packet + in_packet_length; /* Point at end null */
673
  while (in_packet_length > 0 &&
674
	 (pos[-1] == ';' || my_isspace(charset() ,pos[-1])))
675
  {
676
    pos--;
677
    in_packet_length--;
678
  }
679
1280.3.11 by Padraig O'Sullivan
Changed the query member of Session to be std::string
680
  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.
681
682
  return true;
683
}
684
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.
685
bool Session::endTransaction(enum enum_mysql_completiontype completion)
686
{
687
  bool do_release= 0;
688
  bool result= true;
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
689
  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.
690
691
  if (transaction.xid_state.xa_state != XA_NOTR)
692
  {
693
    my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[transaction.xid_state.xa_state]);
694
    return false;
695
  }
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.
696
  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.
697
  {
698
    case COMMIT:
699
      /*
700
       * We don't use endActiveTransaction() here to ensure that this works
701
       * even if there is a problem with the OPTION_AUTO_COMMIT flag
702
       * (Which of course should never happen...)
703
       */
704
      server_status&= ~SERVER_STATUS_IN_TRANS;
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
705
      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.
706
        result= false;
1172.1.2 by Brian Aker
Remove worthless call (ok... for not current replication system).
707
      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.
708
      break;
709
    case COMMIT_RELEASE:
710
      do_release= 1; /* fall through */
711
    case COMMIT_AND_CHAIN:
712
      result= endActiveTransaction();
713
      if (result == true && completion == COMMIT_AND_CHAIN)
714
        result= startTransaction();
715
      break;
716
    case ROLLBACK_RELEASE:
717
      do_release= 1; /* fall through */
718
    case ROLLBACK:
719
    case ROLLBACK_AND_CHAIN:
720
    {
721
      server_status&= ~SERVER_STATUS_IN_TRANS;
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
722
      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.
723
        result= false;
1172.1.2 by Brian Aker
Remove worthless call (ok... for not current replication system).
724
      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.
725
      if (result == true && (completion == ROLLBACK_AND_CHAIN))
726
        result= startTransaction();
727
      break;
728
    }
729
    default:
730
      my_error(ER_UNKNOWN_COM_ERROR, MYF(0));
731
      return false;
732
  }
733
734
  if (result == false)
735
    my_error(killed_errno(), MYF(0));
736
  else if ((result == true) && do_release)
737
    killed= Session::KILL_CONNECTION;
738
739
  return result;
740
}
741
742
bool Session::endActiveTransaction()
743
{
744
  bool result= true;
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
745
  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.
746
747
  if (transaction.xid_state.xa_state != XA_NOTR)
748
  {
749
    my_error(ER_XAER_RMFAIL, MYF(0), xa_state_names[transaction.xid_state.xa_state]);
750
    return false;
751
  }
1054.1.8 by Brian Aker
Remove lock_tables list from session.
752
  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.
753
  {
754
    server_status&= ~SERVER_STATUS_IN_TRANS;
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
755
    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.
756
      result= false;
757
  }
1172.1.2 by Brian Aker
Remove worthless call (ok... for not current replication system).
758
  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.
759
  return result;
760
}
761
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
762
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.
763
{
764
  bool result= true;
765
766
  if (! endActiveTransaction())
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
    result= false;
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
769
  }
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.
770
  else
771
  {
772
    options|= OPTION_BEGIN;
773
    server_status|= SERVER_STATUS_IN_TRANS;
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
    if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
776
    {
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
777
      result= false;
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
  }
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
780
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.
781
  return result;
782
}
783
520.1.21 by Brian Aker
THD -> Session rename
784
void Session::cleanup_after_query()
1 by brian
clean slate
785
{
786
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
787
    Reset rand_used so that detection of calls to rand() will save random
1 by brian
clean slate
788
    seeds if needed by the slave.
789
  */
790
  {
791
    /* Forget those values, for next binlogger: */
792
    auto_inc_intervals_in_cur_stmt_for_binlog.empty();
793
  }
794
  if (first_successful_insert_id_in_cur_stmt > 0)
795
  {
796
    /* set what LAST_INSERT_ID() will return */
1055.2.17 by Jay Pipes
More style cleanups in Session
797
    first_successful_insert_id_in_prev_stmt= first_successful_insert_id_in_cur_stmt;
1 by brian
clean slate
798
    first_successful_insert_id_in_cur_stmt= 0;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
799
    substitute_null_with_insert_id= true;
1 by brian
clean slate
800
  }
1055.2.17 by Jay Pipes
More style cleanups in Session
801
  arg_of_last_insert_id_function= false;
1 by brian
clean slate
802
  /* Free Items that were created during this execution */
803
  free_items();
804
  /* Reset where. */
520.1.21 by Brian Aker
THD -> Session rename
805
  where= Session::DEFAULT_WHERE;
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
806
807
  /* Reset the temporary shares we built */
808
  for (std::vector<TableShareInstance *>::iterator iter= temporary_shares.begin();
809
       iter != temporary_shares.end(); iter++)
810
  {
811
    delete *iter;
812
  }
813
  temporary_shares.clear();
1 by brian
clean slate
814
}
815
816
/**
817
  Create a LEX_STRING in this connection.
818
819
  @param lex_str  pointer to LEX_STRING object to be initialized
820
  @param str      initializer to be copied into lex_str
821
  @param length   length of str, in bytes
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
822
  @param allocate_lex_string  if true, allocate new LEX_STRING object,
1 by brian
clean slate
823
                              instead of using lex_str value
824
  @return  NULL on failure, or pointer to the LEX_STRING object
825
*/
520.1.21 by Brian Aker
THD -> Session rename
826
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
1273.13.38 by Brian Aker
Add in new show work.
827
                                     const std::string &str,
828
                                     bool allocate_lex_string)
829
{
830
  return make_lex_string(lex_str, str.c_str(), str.length(), allocate_lex_string);
831
}
832
833
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
834
                                     const char* str, uint32_t length,
835
                                     bool allocate_lex_string)
1 by brian
clean slate
836
{
837
  if (allocate_lex_string)
838
    if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
839
      return 0;
1487 by Brian Aker
More updates for memory::Root
840
  if (!(lex_str->str= mem_root->strmake_root(str, length)))
1 by brian
clean slate
841
    return 0;
842
  lex_str->length= length;
843
  return lex_str;
844
}
845
520.1.21 by Brian Aker
THD -> Session rename
846
int Session::send_explain_fields(select_result *result)
1 by brian
clean slate
847
{
848
  List<Item> field_list;
849
  Item *item;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
850
  const CHARSET_INFO * const cs= system_charset_info;
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
851
  field_list.push_back(new Item_return_int("id",3, DRIZZLE_TYPE_LONGLONG));
1 by brian
clean slate
852
  field_list.push_back(new Item_empty_string("select_type", 19, cs));
853
  field_list.push_back(item= new Item_empty_string("table", NAME_CHAR_LEN, cs));
854
  item->maybe_null= 1;
855
  field_list.push_back(item= new Item_empty_string("type", 10, cs));
856
  item->maybe_null= 1;
857
  field_list.push_back(item=new Item_empty_string("possible_keys",
858
						  NAME_CHAR_LEN*MAX_KEY, cs));
859
  item->maybe_null=1;
860
  field_list.push_back(item=new Item_empty_string("key", NAME_CHAR_LEN, cs));
861
  item->maybe_null=1;
862
  field_list.push_back(item=
863
    new Item_empty_string("key_len",
864
                          MAX_KEY *
865
                          (MAX_KEY_LENGTH_DECIMAL_WIDTH + 1 /* for comma */),
866
                          cs));
867
  item->maybe_null=1;
868
  field_list.push_back(item=new Item_empty_string("ref",
869
                                                  NAME_CHAR_LEN*MAX_REF_PARTS,
870
                                                  cs));
871
  item->maybe_null=1;
872
  field_list.push_back(item= new Item_return_int("rows", 10,
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
873
                                                 DRIZZLE_TYPE_LONGLONG));
1 by brian
clean slate
874
  if (lex->describe & DESCRIBE_EXTENDED)
875
  {
876
    field_list.push_back(item= new Item_float("filtered", 0.1234, 2, 4));
877
    item->maybe_null=1;
878
  }
879
  item->maybe_null= 1;
880
  field_list.push_back(new Item_empty_string("Extra", 255, cs));
971.3.63 by Eric Day
Removed protocol field flags.
881
  return (result->send_fields(field_list));
1 by brian
clean slate
882
}
883
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
884
void select_result::send_error(uint32_t errcode, const char *err)
885
{
886
  my_message(errcode, err, MYF(0));
887
}
888
1 by brian
clean slate
889
/************************************************************************
890
  Handling writing to file
891
************************************************************************/
892
482 by Brian Aker
Remove uint.
893
void select_to_file::send_error(uint32_t errcode,const char *err)
1 by brian
clean slate
894
{
895
  my_message(errcode, err, MYF(0));
896
  if (file > 0)
897
  {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
898
    (void) end_io_cache(cache);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
899
    (void) internal::my_close(file, MYF(0));
900
    (void) internal::my_delete(path, MYF(0));		// Delete file on error
1 by brian
clean slate
901
    file= -1;
902
  }
903
}
904
905
906
bool select_to_file::send_eof()
907
{
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
908
  int error= test(end_io_cache(cache));
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
909
  if (internal::my_close(file, MYF(MY_WME)))
1 by brian
clean slate
910
    error= 1;
911
  if (!error)
912
  {
913
    /*
914
      In order to remember the value of affected rows for ROW_COUNT()
915
      function, SELECT INTO has to have an own SQLCOM.
916
      TODO: split from SQLCOM_SELECT
917
    */
836 by Brian Aker
Fixed session call from function to method.
918
    session->my_ok(row_count);
1 by brian
clean slate
919
  }
920
  file= -1;
921
  return error;
922
}
923
924
925
void select_to_file::cleanup()
926
{
927
  /* In case of error send_eof() may be not called: close the file here. */
928
  if (file >= 0)
929
  {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
930
    (void) end_io_cache(cache);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
931
    (void) internal::my_close(file, MYF(0));
1 by brian
clean slate
932
    file= -1;
933
  }
934
  path[0]= '\0';
935
  row_count= 0;
936
}
937
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
938
select_to_file::select_to_file(file_exchange *ex)
1241.9.52 by Monty Taylor
Fixed valgrind issue.
939
  : exchange(ex),
940
    file(-1),
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
941
    cache(static_cast<internal::IO_CACHE *>(memory::sql_calloc(sizeof(internal::IO_CACHE)))),
1241.9.52 by Monty Taylor
Fixed valgrind issue.
942
    row_count(0L)
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
943
{
944
  path[0]=0;
945
}
1 by brian
clean slate
946
947
select_to_file::~select_to_file()
948
{
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
949
  cleanup();
1 by brian
clean slate
950
}
951
952
/***************************************************************************
953
** Export of select to textfile
954
***************************************************************************/
955
956
select_export::~select_export()
957
{
520.1.22 by Brian Aker
Second pass of thd cleanup
958
  session->sent_row_count=row_count;
1 by brian
clean slate
959
}
960
961
962
/*
963
  Create file with IO cache
964
965
  SYNOPSIS
966
    create_file()
520.1.22 by Brian Aker
Second pass of thd cleanup
967
    session			Thread handle
1 by brian
clean slate
968
    path		File name
969
    exchange		Excange class
970
    cache		IO cache
971
972
  RETURN
973
    >= 0 	File handle
974
   -1		Error
975
*/
976
977
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
978
static int create_file(Session *session, char *path, file_exchange *exchange, internal::IO_CACHE *cache)
1 by brian
clean slate
979
{
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
980
  int file;
482 by Brian Aker
Remove uint.
981
  uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1 by brian
clean slate
982
983
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
984
  option|= MY_REPLACE_DIR;			// Force use of db directory
985
#endif
986
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
987
  if (!internal::dirname_length(exchange->file_name))
1 by brian
clean slate
988
  {
1300.5.3 by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're
989
    strcpy(path, data_home_real);
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
990
    if (! session->db.empty())
1300.5.3 by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're
991
      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.
992
    (void) internal::fn_format(path, exchange->file_name, path, "", option);
1 by brian
clean slate
993
  }
994
  else
1300.5.3 by Monty Taylor
Removed drizzle_ prefix from some things that don't need it since they're
995
    (void) internal::fn_format(path, exchange->file_name, data_home_real, "", option);
1 by brian
clean slate
996
997
  if (opt_secure_file_priv &&
998
      strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
999
  {
1000
    /* Write only allowed to dir or subdir specified by secure_file_priv */
1001
    my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
1002
    return -1;
1003
  }
1004
1005
  if (!access(path, F_OK))
1006
  {
1007
    my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);
1008
    return -1;
1009
  }
1010
  /* Create the file world readable */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1011
  if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1 by brian
clean slate
1012
    return file;
1013
  (void) fchmod(file, 0666);			// Because of umask()
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1014
  if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1 by brian
clean slate
1015
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1016
    internal::my_close(file, MYF(0));
1017
    internal::my_delete(path, MYF(0));  // Delete file on error, it was just created
1 by brian
clean slate
1018
    return -1;
1019
  }
1020
  return file;
1021
}
1022
1023
1024
int
848 by Brian Aker
typdef class removal (just... use the name of the class).
1025
select_export::prepare(List<Item> &list, Select_Lex_Unit *u)
1 by brian
clean slate
1026
{
1027
  bool blob_flag=0;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1028
  bool string_results= false, non_string_results= false;
1 by brian
clean slate
1029
  unit= u;
895 by Brian Aker
Completion (?) of uint conversion.
1030
  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
1031
    strncpy(path,exchange->file_name,FN_REFLEN-1);
1 by brian
clean slate
1032
1033
  /* Check if there is any blobs in data */
1034
  {
1035
    List_iterator_fast<Item> li(list);
1036
    Item *item;
1037
    while ((item=li++))
1038
    {
1039
      if (item->max_length >= MAX_BLOB_WIDTH)
1040
      {
1041
	blob_flag=1;
1042
	break;
1043
      }
1044
      if (item->result_type() == STRING_RESULT)
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1045
        string_results= true;
1 by brian
clean slate
1046
      else
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1047
        non_string_results= true;
1 by brian
clean slate
1048
    }
1049
  }
1050
  field_term_length=exchange->field_term->length();
1051
  field_term_char= field_term_length ?
481 by Brian Aker
Remove all of uchar.
1052
                   (int) (unsigned char) (*exchange->field_term)[0] : INT_MAX;
1 by brian
clean slate
1053
  if (!exchange->line_term->length())
1054
    exchange->line_term=exchange->field_term;	// Use this if it exists
1055
  field_sep_char= (exchange->enclosed->length() ?
481 by Brian Aker
Remove all of uchar.
1056
                  (int) (unsigned char) (*exchange->enclosed)[0] : field_term_char);
1 by brian
clean slate
1057
  escape_char=	(exchange->escaped->length() ?
481 by Brian Aker
Remove all of uchar.
1058
                (int) (unsigned char) (*exchange->escaped)[0] : -1);
1 by brian
clean slate
1059
  is_ambiguous_field_sep= test(strchr(ESCAPE_CHARS, field_sep_char));
1060
  is_unsafe_field_sep= test(strchr(NUMERIC_CHARS, field_sep_char));
1061
  line_sep_char= (exchange->line_term->length() ?
481 by Brian Aker
Remove all of uchar.
1062
                 (int) (unsigned char) (*exchange->line_term)[0] : INT_MAX);
1 by brian
clean slate
1063
  if (!field_term_length)
1064
    exchange->opt_enclosed=0;
1065
  if (!exchange->enclosed->length())
1066
    exchange->opt_enclosed=1;			// A little quicker loop
1067
  fixed_row_size= (!field_term_length && !exchange->enclosed->length() &&
1068
		   !blob_flag);
1069
  if ((is_ambiguous_field_sep && exchange->enclosed->is_empty() &&
1070
       (string_results || is_unsafe_field_sep)) ||
1071
      (exchange->opt_enclosed && non_string_results &&
1072
       field_term_length && strchr(NUMERIC_CHARS, field_term_char)))
1073
  {
673.3.8 by Stewart Smith
fix outfile_loaddata test for drizzle.
1074
    my_error(ER_AMBIGUOUS_FIELD_TERM, MYF(0));
1075
    return 1;
1 by brian
clean slate
1076
  }
673.3.8 by Stewart Smith
fix outfile_loaddata test for drizzle.
1077
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1078
  if ((file= create_file(session, path, exchange, cache)) < 0)
673.3.8 by Stewart Smith
fix outfile_loaddata test for drizzle.
1079
    return 1;
1 by brian
clean slate
1080
1081
  return 0;
1082
}
1083
1084
bool select_export::send_data(List<Item> &items)
1085
{
1086
  char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
1087
  bool space_inited=0;
1088
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1089
  tmp.length(0);
1090
1091
  if (unit->offset_limit_cnt)
1092
  {						// using limit offset,count
1093
    unit->offset_limit_cnt--;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1094
    return(0);
1 by brian
clean slate
1095
  }
1096
  row_count++;
1097
  Item *item;
482 by Brian Aker
Remove uint.
1098
  uint32_t used_length=0,items_left=items.elements;
1 by brian
clean slate
1099
  List_iterator_fast<Item> li(items);
1100
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1101
  if (my_b_write(cache,(unsigned char*) exchange->line_start->ptr(),
1208.3.2 by brian
Update for Cursor renaming.
1102
                 exchange->line_start->length()))
1 by brian
clean slate
1103
    goto err;
1104
  while ((item=li++))
1105
  {
1106
    Item_result result_type=item->result_type();
1107
    bool enclosed = (exchange->enclosed->length() &&
1108
                     (!exchange->opt_enclosed || result_type == STRING_RESULT));
1109
    res=item->str_result(&tmp);
1110
    if (res && enclosed)
1111
    {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1112
      if (my_b_write(cache,(unsigned char*) exchange->enclosed->ptr(),
1208.3.2 by brian
Update for Cursor renaming.
1113
                     exchange->enclosed->length()))
1114
        goto err;
1 by brian
clean slate
1115
    }
1116
    if (!res)
1117
    {						// NULL
1118
      if (!fixed_row_size)
1119
      {
1208.3.2 by brian
Update for Cursor renaming.
1120
        if (escape_char != -1)			// Use \N syntax
1121
        {
1122
          null_buff[0]=escape_char;
1123
          null_buff[1]='N';
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1124
          if (my_b_write(cache,(unsigned char*) null_buff,2))
1208.3.2 by brian
Update for Cursor renaming.
1125
            goto err;
1126
        }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1127
        else if (my_b_write(cache,(unsigned char*) "NULL",4))
1208.3.2 by brian
Update for Cursor renaming.
1128
          goto err;
1 by brian
clean slate
1129
      }
1130
      else
1131
      {
1208.3.2 by brian
Update for Cursor renaming.
1132
        used_length=0;				// Fill with space
1 by brian
clean slate
1133
      }
1134
    }
1135
    else
1136
    {
1137
      if (fixed_row_size)
1067.4.1 by Nathan Williams
First few changes at converting cmin to std::min.
1138
        used_length= min(res->length(),item->max_length);
1 by brian
clean slate
1139
      else
1067.4.1 by Nathan Williams
First few changes at converting cmin to std::min.
1140
        used_length= res->length();
1141
1 by brian
clean slate
1142
      if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
1208.3.2 by brian
Update for Cursor renaming.
1143
          escape_char != -1)
1 by brian
clean slate
1144
      {
1145
        char *pos, *start, *end;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
1146
        const CHARSET_INFO * const res_charset= res->charset();
748 by Brian Aker
Removal of client side collation.
1147
        const CHARSET_INFO * const character_set_client= default_charset_info;
1148
1 by brian
clean slate
1149
        bool check_second_byte= (res_charset == &my_charset_bin) &&
1208.3.2 by brian
Update for Cursor renaming.
1150
          character_set_client->
1151
          escape_with_backslash_is_dangerous;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1152
        assert(character_set_client->mbmaxlen == 2 ||
748 by Brian Aker
Removal of client side collation.
1153
               !character_set_client->escape_with_backslash_is_dangerous);
1208.3.2 by brian
Update for Cursor renaming.
1154
        for (start=pos=(char*) res->ptr(),end=pos+used_length ;
1155
             pos != end ;
1156
             pos++)
1157
        {
1158
          if (use_mb(res_charset))
1159
          {
1160
            int l;
1161
            if ((l=my_ismbchar(res_charset, pos, end)))
1162
            {
1163
              pos += l-1;
1164
              continue;
1165
            }
1166
          }
1 by brian
clean slate
1167
1168
          /*
1169
            Special case when dumping BINARY/VARBINARY/BLOB values
1170
            for the clients with character sets big5, cp932, gbk and sjis,
1171
            which can have the escape character (0x5C "\" by default)
1172
            as the second byte of a multi-byte sequence.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1173
1 by brian
clean slate
1174
            If
1175
            - pos[0] is a valid multi-byte head (e.g 0xEE) and
1176
            - pos[1] is 0x00, which will be escaped as "\0",
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1177
1 by brian
clean slate
1178
            then we'll get "0xEE + 0x5C + 0x30" in the output file.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1179
1 by brian
clean slate
1180
            If this file is later loaded using this sequence of commands:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1181
1 by brian
clean slate
1182
            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
1183
            mysql> LOAD DATA INFILE 'dump.txt' INTO Table t1;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1184
1 by brian
clean slate
1185
            then 0x5C will be misinterpreted as the second byte
1186
            of a multi-byte character "0xEE + 0x5C", instead of
1187
            escape character for 0x00.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1188
1 by brian
clean slate
1189
            To avoid this confusion, we'll escape the multi-byte
1190
            head character too, so the sequence "0xEE + 0x00" will be
1191
            dumped as "0x5C + 0xEE + 0x5C + 0x30".
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1192
1 by brian
clean slate
1193
            Note, in the condition below we only check if
1194
            mbcharlen is equal to 2, because there are no
1195
            character sets with mbmaxlen longer than 2
1196
            and with escape_with_backslash_is_dangerous set.
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1197
            assert before the loop makes that sure.
1 by brian
clean slate
1198
          */
1199
1377.6.3 by pawel
changed function-like defines into functions in some files
1200
          if ((needs_escaping(*pos, enclosed) ||
1 by brian
clean slate
1201
               (check_second_byte &&
481 by Brian Aker
Remove all of uchar.
1202
                my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 &&
1 by brian
clean slate
1203
                pos + 1 < end &&
1377.6.3 by pawel
changed function-like defines into functions in some files
1204
                needs_escaping(pos[1], enclosed))) &&
1 by brian
clean slate
1205
              /*
1208.3.2 by brian
Update for Cursor renaming.
1206
                Don't escape field_term_char by doubling - doubling is only
1207
                valid for ENCLOSED BY characters:
1 by brian
clean slate
1208
              */
1209
              (enclosed || !is_ambiguous_field_term ||
481 by Brian Aker
Remove all of uchar.
1210
               (int) (unsigned char) *pos != field_term_char))
1 by brian
clean slate
1211
          {
1208.3.2 by brian
Update for Cursor renaming.
1212
            char tmp_buff[2];
481 by Brian Aker
Remove all of uchar.
1213
            tmp_buff[0]= ((int) (unsigned char) *pos == field_sep_char &&
1 by brian
clean slate
1214
                          is_ambiguous_field_sep) ?
1208.3.2 by brian
Update for Cursor renaming.
1215
              field_sep_char : escape_char;
1216
            tmp_buff[1]= *pos ? *pos : '0';
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1217
            if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start)) ||
1218
                my_b_write(cache,(unsigned char*) tmp_buff,2))
1208.3.2 by brian
Update for Cursor renaming.
1219
              goto err;
1220
            start=pos+1;
1221
          }
1222
        }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1223
        if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start)))
1208.3.2 by brian
Update for Cursor renaming.
1224
          goto err;
1 by brian
clean slate
1225
      }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1226
      else if (my_b_write(cache,(unsigned char*) res->ptr(),used_length))
1208.3.2 by brian
Update for Cursor renaming.
1227
        goto err;
1 by brian
clean slate
1228
    }
1229
    if (fixed_row_size)
1230
    {						// Fill with space
1231
      if (item->max_length > used_length)
1232
      {
1208.3.2 by brian
Update for Cursor renaming.
1233
        /* QQ:  Fix by adding a my_b_fill() function */
1234
        if (!space_inited)
1235
        {
1236
          space_inited=1;
1237
          memset(space, ' ', sizeof(space));
1238
        }
1239
        uint32_t length=item->max_length-used_length;
1240
        for (; length > sizeof(space) ; length-=sizeof(space))
1241
        {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1242
          if (my_b_write(cache,(unsigned char*) space,sizeof(space)))
1208.3.2 by brian
Update for Cursor renaming.
1243
            goto err;
1244
        }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1245
        if (my_b_write(cache,(unsigned char*) space,length))
1208.3.2 by brian
Update for Cursor renaming.
1246
          goto err;
1 by brian
clean slate
1247
      }
1248
    }
1249
    if (res && enclosed)
1250
    {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1251
      if (my_b_write(cache, (unsigned char*) exchange->enclosed->ptr(),
1 by brian
clean slate
1252
                     exchange->enclosed->length()))
1253
        goto err;
1254
    }
1255
    if (--items_left)
1256
    {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1257
      if (my_b_write(cache, (unsigned char*) exchange->field_term->ptr(),
1 by brian
clean slate
1258
                     field_term_length))
1259
        goto err;
1260
    }
1261
  }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1262
  if (my_b_write(cache,(unsigned char*) exchange->line_term->ptr(),
1208.3.2 by brian
Update for Cursor renaming.
1263
                 exchange->line_term->length()))
1 by brian
clean slate
1264
    goto err;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1265
  return(0);
1 by brian
clean slate
1266
err:
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1267
  return(1);
1 by brian
clean slate
1268
}
1269
1270
1271
/***************************************************************************
1272
** Dump  of select to a binary file
1273
***************************************************************************/
1274
1275
1276
int
848 by Brian Aker
typdef class removal (just... use the name of the class).
1277
select_dump::prepare(List<Item> &, Select_Lex_Unit *u)
1 by brian
clean slate
1278
{
1279
  unit= u;
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1280
  return (int) ((file= create_file(session, path, exchange, cache)) < 0);
1 by brian
clean slate
1281
}
1282
1283
1284
bool select_dump::send_data(List<Item> &items)
1285
{
1286
  List_iterator_fast<Item> li(items);
1287
  char buff[MAX_FIELD_WIDTH];
1288
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1289
  tmp.length(0);
1290
  Item *item;
1291
1292
  if (unit->offset_limit_cnt)
1293
  {						// using limit offset,count
1294
    unit->offset_limit_cnt--;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1295
    return(0);
1 by brian
clean slate
1296
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1297
  if (row_count++ > 1)
1 by brian
clean slate
1298
  {
1299
    my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
1300
    goto err;
1301
  }
1302
  while ((item=li++))
1303
  {
1304
    res=item->str_result(&tmp);
1305
    if (!res)					// If NULL
1306
    {
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1307
      if (my_b_write(cache,(unsigned char*) "",1))
1 by brian
clean slate
1308
	goto err;
1309
    }
1241.9.49 by Monty Taylor
Removed one more public IO_CACHE.
1310
    else if (my_b_write(cache,(unsigned char*) res->ptr(),res->length()))
1 by brian
clean slate
1311
    {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
1312
      my_error(ER_ERROR_ON_WRITE, MYF(0), path, errno);
1 by brian
clean slate
1313
      goto err;
1314
    }
1315
  }
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1316
  return(0);
1 by brian
clean slate
1317
err:
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1318
  return(1);
1 by brian
clean slate
1319
}
1320
1321
1322
select_subselect::select_subselect(Item_subselect *item_arg)
1323
{
1324
  item= item_arg;
1325
}
1326
1327
1328
bool select_singlerow_subselect::send_data(List<Item> &items)
1329
{
1330
  Item_singlerow_subselect *it= (Item_singlerow_subselect *)item;
1331
  if (it->assigned())
1332
  {
1333
    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
1334
    return(1);
1 by brian
clean slate
1335
  }
1336
  if (unit->offset_limit_cnt)
1337
  {				          // Using limit offset,count
1338
    unit->offset_limit_cnt--;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1339
    return(0);
1 by brian
clean slate
1340
  }
1341
  List_iterator_fast<Item> li(items);
1342
  Item *val_item;
482 by Brian Aker
Remove uint.
1343
  for (uint32_t i= 0; (val_item= li++); i++)
1 by brian
clean slate
1344
    it->store(i, val_item);
1345
  it->assigned(1);
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1346
  return(0);
1 by brian
clean slate
1347
}
1348
1349
1350
void select_max_min_finder_subselect::cleanup()
1351
{
1352
  cache= 0;
1353
}
1354
1355
1356
bool select_max_min_finder_subselect::send_data(List<Item> &items)
1357
{
1358
  Item_maxmin_subselect *it= (Item_maxmin_subselect *)item;
1359
  List_iterator_fast<Item> li(items);
1360
  Item *val_item= li++;
1361
  it->register_value();
1362
  if (it->assigned())
1363
  {
1364
    cache->store(val_item);
1365
    if ((this->*op)())
1366
      it->store(0, cache);
1367
  }
1368
  else
1369
  {
1370
    if (!cache)
1371
    {
1372
      cache= Item_cache::get_cache(val_item);
1373
      switch (val_item->result_type())
1374
      {
1375
      case REAL_RESULT:
1376
	op= &select_max_min_finder_subselect::cmp_real;
1377
	break;
1378
      case INT_RESULT:
1379
	op= &select_max_min_finder_subselect::cmp_int;
1380
	break;
1381
      case STRING_RESULT:
1382
	op= &select_max_min_finder_subselect::cmp_str;
1383
	break;
1384
      case DECIMAL_RESULT:
1385
        op= &select_max_min_finder_subselect::cmp_decimal;
1386
        break;
1387
      case ROW_RESULT:
1388
        // This case should never be choosen
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1389
	assert(0);
1 by brian
clean slate
1390
	op= 0;
1391
      }
1392
    }
1393
    cache->store(val_item);
1394
    it->store(0, cache);
1395
  }
1396
  it->assigned(1);
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1397
  return(0);
1 by brian
clean slate
1398
}
1399
1400
bool select_max_min_finder_subselect::cmp_real()
1401
{
1402
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1403
  double val1= cache->val_real(), val2= maxmin->val_real();
1404
  if (fmax)
1405
    return (cache->null_value && !maxmin->null_value) ||
1406
      (!cache->null_value && !maxmin->null_value &&
1407
       val1 > val2);
1408
  return (maxmin->null_value && !cache->null_value) ||
1409
    (!cache->null_value && !maxmin->null_value &&
1410
     val1 < val2);
1411
}
1412
1413
bool select_max_min_finder_subselect::cmp_int()
1414
{
1415
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
152 by Brian Aker
longlong replacement
1416
  int64_t val1= cache->val_int(), val2= maxmin->val_int();
1 by brian
clean slate
1417
  if (fmax)
1418
    return (cache->null_value && !maxmin->null_value) ||
1419
      (!cache->null_value && !maxmin->null_value &&
1420
       val1 > val2);
1421
  return (maxmin->null_value && !cache->null_value) ||
1422
    (!cache->null_value && !maxmin->null_value &&
1423
     val1 < val2);
1424
}
1425
1426
bool select_max_min_finder_subselect::cmp_decimal()
1427
{
1428
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1429
  my_decimal cval, *cvalue= cache->val_decimal(&cval);
1430
  my_decimal mval, *mvalue= maxmin->val_decimal(&mval);
1431
  if (fmax)
1432
    return (cache->null_value && !maxmin->null_value) ||
1433
      (!cache->null_value && !maxmin->null_value &&
1434
       my_decimal_cmp(cvalue, mvalue) > 0) ;
1435
  return (maxmin->null_value && !cache->null_value) ||
1436
    (!cache->null_value && !maxmin->null_value &&
1437
     my_decimal_cmp(cvalue,mvalue) < 0);
1438
}
1439
1440
bool select_max_min_finder_subselect::cmp_str()
1441
{
1442
  String *val1, *val2, buf1, buf2;
1443
  Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1444
  /*
1445
    as far as both operand is Item_cache buf1 & buf2 will not be used,
1446
    but added for safety
1447
  */
1448
  val1= cache->val_str(&buf1);
1449
  val2= maxmin->val_str(&buf1);
1450
  if (fmax)
1451
    return (cache->null_value && !maxmin->null_value) ||
1452
      (!cache->null_value && !maxmin->null_value &&
1453
       sortcmp(val1, val2, cache->collation.collation) > 0) ;
1454
  return (maxmin->null_value && !cache->null_value) ||
1455
    (!cache->null_value && !maxmin->null_value &&
1456
     sortcmp(val1, val2, cache->collation.collation) < 0);
1457
}
1458
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
1459
bool select_exists_subselect::send_data(List<Item> &)
1 by brian
clean slate
1460
{
1461
  Item_exists_subselect *it= (Item_exists_subselect *)item;
1462
  if (unit->offset_limit_cnt)
77.1.45 by Monty Taylor
Warning fixes.
1463
  { // Using limit offset,count
1 by brian
clean slate
1464
    unit->offset_limit_cnt--;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1465
    return(0);
1 by brian
clean slate
1466
  }
1467
  it->value= 1;
1468
  it->assigned(1);
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1469
  return(0);
1 by brian
clean slate
1470
}
1471
406 by Brian Aker
Cleanup around Query_arena.
1472
/*
1473
  Don't free mem_root, as mem_root is freed in the end of dispatch_command
1474
  (once for any command).
1475
*/
520.1.21 by Brian Aker
THD -> Session rename
1476
void Session::end_statement()
1 by brian
clean slate
1477
{
1478
  /* Cleanup SQL processing state to reuse this statement in next query. */
1479
  lex_end(lex);
1480
}
1481
520.1.21 by Brian Aker
THD -> Session rename
1482
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.
1483
{
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
1484
  if (db.empty())
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1485
  {
1486
    my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
1487
    return true;
1488
  }
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
1489
  *p_db= strmake(db.c_str(), db.length());
1490
  *p_db_length= db.length();
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1491
  return false;
1492
}
1493
1101.1.16 by Monty Taylor
Reverted 1103
1494
/****************************************************************************
1495
  Tmp_Table_Param
1496
****************************************************************************/
1497
1498
void Tmp_Table_Param::init()
1499
{
1500
  field_count= sum_func_count= func_count= hidden_field_count= 0;
1501
  group_parts= group_length= group_null_parts= 0;
1502
  quick_group= 1;
1503
  table_charset= 0;
1504
  precomputed_group_by= 0;
1505
}
1506
1507
void Tmp_Table_Param::cleanup(void)
1508
{
1509
  /* Fix for Intel compiler */
1510
  if (copy_field)
1511
  {
1512
    delete [] copy_field;
1513
    save_copy_field= copy_field= 0;
1514
  }
1515
}
1516
520.1.21 by Brian Aker
THD -> Session rename
1517
void Session::send_kill_message() const
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1518
{
1519
  int err= killed_errno();
1520
  if (err)
1521
    my_message(err, ER(err), MYF(0));
1522
}
1 by brian
clean slate
1523
520.1.21 by Brian Aker
THD -> Session rename
1524
void Session::set_status_var_init()
1 by brian
clean slate
1525
{
212.6.6 by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove().
1526
  memset(&status_var, 0, sizeof(status_var));
1 by brian
clean slate
1527
}
1528
1529
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1530
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.
1531
{
1273 by Brian Aker
Revert db patch.
1532
  /* Do not reallocate memory if current chunk is big enough. */
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1533
  if (new_db.length())
1273 by Brian Aker
Revert db patch.
1534
    db= new_db;
1535
  else
1536
    db.clear();
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
1537
1538
  return false;
656.1.22 by Monty Taylor
Removed my_malloc related stuff from log_event and session.
1539
}
1540
1273 by Brian Aker
Revert db patch.
1541
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.
1542
656.1.22 by Monty Taylor
Removed my_malloc related stuff from log_event and session.
1543
1 by brian
clean slate
1544
/**
1545
  Check the killed state of a user thread
520.1.22 by Brian Aker
Second pass of thd cleanup
1546
  @param session  user thread
1 by brian
clean slate
1547
  @retval 0 the user thread is active
1548
  @retval 1 the user thread has been killed
1549
*/
1471.5.2 by mordred
Removed some extern "C" bits that were screwing with the callstack.
1550
int session_killed(const Session *session)
1 by brian
clean slate
1551
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1552
  return(session->killed);
1 by brian
clean slate
1553
}
1554
1555
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
1556
const struct charset_info_st *session_charset(Session *session)
520.1.22 by Brian Aker
Second pass of thd cleanup
1557
{
1558
  return(session->charset());
1559
}
1560
1 by brian
clean slate
1561
/**
1562
  Mark transaction to rollback and mark error as fatal to a sub-statement.
1563
520.1.22 by Brian Aker
Second pass of thd cleanup
1564
  @param  session   Thread handle
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1565
  @param  all   true <=> rollback main transaction.
1 by brian
clean slate
1566
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
1567
void mark_transaction_to_rollback(Session *session, bool all)
1 by brian
clean slate
1568
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1569
  if (session)
1 by brian
clean slate
1570
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1571
    session->is_fatal_sub_stmt_error= true;
1572
    session->transaction_rollback_request= all;
1 by brian
clean slate
1573
  }
1574
}
1575
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1576
void Session::disconnect(uint32_t errcode, bool should_lock)
575.4.7 by Monty Taylor
More header cleanup.
1577
{
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1578
  /* Allow any plugins to cleanup their session variables */
1579
  plugin_sessionvar_cleanup(this);
1580
1581
  /* 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.
1582
  if (killed || client->wasAborted())
1537.2.1 by Joe Daly
add statistics_variables.h
1583
  {
1689.5.1 by Joseph Daly
remove increment calls
1584
    status_var.aborted_threads++;
1537.2.1 by Joe Daly
add statistics_variables.h
1585
  }
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1586
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
1587
  if (client->wasAborted())
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1588
  {
1589
    if (! killed && variables.log_warnings > 1)
1590
    {
1273.11.1 by Dennis Schoen
rename class
1591
      SecurityContext *sctx= &security_ctx;
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1592
1593
      errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1594
                  , thread_id
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
1595
                  , (db.empty() ? "unconnected" : db.c_str())
1273.11.2 by Dennis Schoen
make data members private
1596
                  , sctx->getUser().empty() == false ? sctx->getUser().c_str() : "unauthenticated"
1597
                  , sctx->getIp().c_str()
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1598
                  , (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR)));
1599
    }
1600
  }
1601
1602
  /* Close out our connection to the client */
779.3.10 by Monty Taylor
Turned on -Wshadow.
1603
  if (should_lock)
1689.2.8 by Brian Aker
LOCK_thread_count -> boost.
1604
    LOCK_thread_count.lock();
693 by Brian Aker
Cleaning up session class.
1605
  killed= Session::KILL_CONNECTION;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
1606
  if (client->isConnected())
575.4.7 by Monty Taylor
More header cleanup.
1607
  {
1608
    if (errcode)
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
1609
    {
1610
      /*my_error(errcode, ER(errcode));*/
971.6.11 by Eric Day
Removed purecov messages.
1611
      client->sendError(errcode, ER(errcode));
971.3.12 by Eric Day
Started abstracting Protocol, removed init_connect, init_file.
1612
    }
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
1613
    client->close();
575.4.7 by Monty Taylor
More header cleanup.
1614
  }
779.3.10 by Monty Taylor
Turned on -Wshadow.
1615
  if (should_lock)
1689.2.8 by Brian Aker
LOCK_thread_count -> boost.
1616
    (void) LOCK_thread_count.unlock();
575.4.7 by Monty Taylor
More header cleanup.
1617
}
735 by Brian Aker
Refactor session.
1618
1619
void Session::reset_for_next_command()
1620
{
1621
  free_list= 0;
1622
  select_number= 1;
1623
  /*
1624
    Those two lines below are theoretically unneeded as
1625
    Session::cleanup_after_query() should take care of this already.
1626
  */
1627
  auto_inc_intervals_in_cur_stmt_for_binlog.empty();
1628
1055.2.17 by Jay Pipes
More style cleanups in Session
1629
  is_fatal_error= false;
735 by Brian Aker
Refactor session.
1630
  server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
1631
                          SERVER_QUERY_NO_INDEX_USED |
1632
                          SERVER_QUERY_NO_GOOD_INDEX_USED);
1633
1634
  clear_error();
1635
  main_da.reset_diagnostics_area();
1636
  total_warn_count=0;			// Warnings for this query
1637
  sent_row_count= examined_row_count= 0;
1638
}
793 by Brian Aker
Pass through on refactoring functions to clases.
1639
1640
/*
1641
  Close all temporary tables created by 'CREATE TEMPORARY TABLE' for thread
1642
*/
1643
1644
void Session::close_temporary_tables()
1645
{
1646
  Table *table;
798.2.20 by Brian Aker
More cleanup of binlog.isopen
1647
  Table *tmp_next;
793 by Brian Aker
Pass through on refactoring functions to clases.
1648
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1649
  if (not temporary_tables)
793 by Brian Aker
Pass through on refactoring functions to clases.
1650
    return;
1651
798.2.20 by Brian Aker
More cleanup of binlog.isopen
1652
  for (table= temporary_tables; table; table= tmp_next)
1653
  {
1608 by Brian Aker
This encapsulates prev/next.
1654
    tmp_next= table->getNext();
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1655
    nukeTable(table);
798.2.20 by Brian Aker
More cleanup of binlog.isopen
1656
  }
1046.1.6 by Brian Aker
Formatting/style cleanup.
1657
  temporary_tables= NULL;
793 by Brian Aker
Pass through on refactoring functions to clases.
1658
}
855 by Brian Aker
Refactor reset of status.
1659
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1660
/*
1661
  unlink from session->temporary tables and close temporary table
1662
*/
1663
1216.1.1 by Brian Aker
Move print_error up to Engine.
1664
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
1665
{
1608 by Brian Aker
This encapsulates prev/next.
1666
  if (table->getPrev())
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1667
  {
1608 by Brian Aker
This encapsulates prev/next.
1668
    table->getPrev()->setNext(table->getNext());
1669
    if (table->getPrev()->getNext())
1670
    {
1671
      table->getNext()->setPrev(table->getPrev());
1672
    }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1673
  }
1674
  else
1675
  {
1676
    /* removing the item from the list */
1677
    assert(table == temporary_tables);
1678
    /*
1679
      slave must reset its temporary list pointer to zero to exclude
1680
      passing non-zero value to end_slave via rli->save_temporary_tables
1681
      when no temp tables opened, see an invariant below.
1682
    */
1608 by Brian Aker
This encapsulates prev/next.
1683
    temporary_tables= table->getNext();
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1684
    if (temporary_tables)
1608 by Brian Aker
This encapsulates prev/next.
1685
    {
1686
      table->getNext()->setPrev(NULL);
1687
    }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1688
  }
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1689
  nukeTable(table);
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1690
}
1691
1692
/*
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1693
  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
1694
1695
  NOTE
1696
  This dosn't unlink table from session->temporary
1697
  If this is needed, use close_temporary_table()
1698
*/
1699
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1700
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
1701
{
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1702
  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
1703
1109.1.4 by Brian Aker
More Table refactor
1704
  table->free_io_cache();
1672.3.2 by Brian Aker
Tiny little cleanup around Table.
1705
  table->delete_table();
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1706
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1707
  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.
1708
  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
1709
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1710
  delete table->getMutableShare();
1237.6.12 by Brian Aker
Adding patch for engine methods for definition files.
1711
1216.1.1 by Brian Aker
Move print_error up to Engine.
1712
  /* 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.
1713
  delete table;
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1714
}
855 by Brian Aker
Refactor reset of status.
1715
1716
/** Clear most status variables. */
1717
extern time_t flush_status_time;
1718
1719
void Session::refresh_status()
1720
{
1689.2.6 by Brian Aker
Convert LOCK_status to boost.
1721
  LOCK_status.lock();
855 by Brian Aker
Refactor reset of status.
1722
1723
  /* Reset thread's status variables */
1724
  memset(&status_var, 0, sizeof(status_var));
1725
1726
  /* Reset the counters of all key caches (default and named). */
1727
  flush_status_time= time((time_t*) 0);
1537.2.1 by Joe Daly
add statistics_variables.h
1728
  current_global_counters.max_used_connections= 1; /* We set it to one, because we know we exist */
1689.2.6 by Brian Aker
Convert LOCK_status to boost.
1729
  LOCK_status.unlock();
855 by Brian Aker
Refactor reset of status.
1730
}
995 by Brian Aker
Refactor get_variable to session
1731
1732
user_var_entry *Session::getVariable(LEX_STRING &name, bool create_if_not_exists)
1733
{
1734
  user_var_entry *entry= NULL;
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
1735
  UserVarsRange ppp= user_vars.equal_range(std::string(name.str, name.length));
995 by Brian Aker
Refactor get_variable to session
1736
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
1737
  for (UserVars::iterator iter= ppp.first;
1738
         iter != ppp.second; ++iter)
1739
  {
1740
    entry= (*iter).second;
1741
  }
995 by Brian Aker
Refactor get_variable to session
1742
1743
  if ((entry == NULL) && create_if_not_exists)
1744
  {
1089.1.5 by Brian Aker
Cleanup of user_var
1745
    entry= new (nothrow) user_var_entry(name.str, query_id);
1746
1747
    if (entry == NULL)
1748
      return NULL;
1749
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
1750
    std::pair<UserVars::iterator, bool> returnable= user_vars.insert(make_pair(std::string(name.str, name.length), entry));
1751
1752
    if (not returnable.second)
995 by Brian Aker
Refactor get_variable to session
1753
    {
1510.3.1 by mordred
Fixed error found by cppcheck - entry here is allocated using new, thus should be deleted.
1754
      delete entry;
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
1755
      return NULL;
995 by Brian Aker
Refactor get_variable to session
1756
    }
1757
  }
1758
1759
  return entry;
1760
}
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1761
1762
void Session::mark_temp_tables_as_free_for_reuse()
1763
{
1608 by Brian Aker
This encapsulates prev/next.
1764
  for (Table *table= temporary_tables ; table ; table= table->getNext())
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1765
  {
1766
    if (table->query_id == query_id)
1767
    {
1768
      table->query_id= 0;
1208.3.2 by brian
Update for Cursor renaming.
1769
      table->cursor->ha_reset();
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1770
    }
1771
  }
1772
}
1773
1774
void Session::mark_used_tables_as_free_for_reuse(Table *table)
1775
{
1608 by Brian Aker
This encapsulates prev/next.
1776
  for (; table ; table= table->getNext())
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1777
  {
1778
    if (table->query_id == query_id)
1779
    {
1780
      table->query_id= 0;
1208.3.2 by brian
Update for Cursor renaming.
1781
      table->cursor->ha_reset();
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1782
    }
1783
  }
1784
}
1785
1786
/*
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1787
  Unlocks tables and frees derived tables.
1788
  Put all normal tables used by thread in free list.
1789
1790
  It will only close/mark as free for reuse tables opened by this
1791
  substatement, it will also check if we are closing tables after
1792
  execution of complete query (i.e. we are on upper level) and will
1793
  leave prelocked mode if needed.
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1794
*/
1795
void Session::close_thread_tables()
1796
{
1797
  if (derived_tables)
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1798
    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)
1799
1800
  /*
1801
    Mark all temporary tables used by this statement as free for reuse.
1802
  */
1803
  mark_temp_tables_as_free_for_reuse();
1804
  /*
1805
    Let us commit transaction for statement. Since in 5.0 we only have
1806
    one statement transaction and don't allow several nested statement
1807
    transactions this call will do nothing if we are inside of stored
1808
    function or trigger (i.e. statement transaction is already active and
1809
    does not belong to statement for which we do close_thread_tables()).
1810
    TODO: This should be fixed in later releases.
1811
   */
1812
  {
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
1813
    TransactionServices &transaction_services= TransactionServices::singleton();
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1814
    main_da.can_overwrite_status= true;
1405.3.5 by Jay Pipes
TransactionServices method names now meet code style guidelines.
1815
    transaction_services.autocommitOrRollback(this, is_error());
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1816
    main_da.can_overwrite_status= false;
1817
    transaction.stmt.reset();
1818
  }
1819
1820
  if (lock)
1821
  {
1822
    /*
1823
      For RBR we flush the pending event just before we unlock all the
1824
      tables.  This means that we are at the end of a topmost
1825
      statement, so we ensure that the STMT_END_F flag is set on the
1826
      pending event.  For statements that are *inside* stored
1827
      functions, the pending event will not be flushed: that will be
1828
      handled either before writing a query log event (inside
1829
      binlog_query()) or when preparing a pending event.
1830
     */
1831
    mysql_unlock_tables(this, lock);
1832
    lock= 0;
1833
  }
1834
  /*
1835
    Note that we need to hold LOCK_open while changing the
1836
    open_tables list. Another thread may work on it.
1837
    (See: remove_table_from_cache(), mysql_wait_completed_table())
1838
    Closing a MERGE child before the parent would be fatal if the
1839
    other thread tries to abort the MERGE lock in between.
1840
  */
1841
  if (open_tables)
1842
    close_open_tables();
1843
}
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1844
1845
void Session::close_tables_for_reopen(TableList **tables)
1846
{
1847
  /*
1848
    If table list consists only from tables from prelocking set, table list
1849
    for new attempt should be empty, so we have to update list's root pointer.
1850
  */
1851
  if (lex->first_not_own_table() == *tables)
1852
    *tables= 0;
1853
  lex->chop_off_not_own_tables();
1854
  for (TableList *tmp= *tables; tmp; tmp= tmp->next_global)
1855
    tmp->table= 0;
1856
  close_thread_tables();
1857
}
1858
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1859
bool Session::openTablesLock(TableList *tables)
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1860
{
1861
  uint32_t counter;
1862
  bool need_reopen;
1863
1864
  for ( ; ; )
1865
  {
1109.1.2 by Brian Aker
More from the table patch
1866
    if (open_tables_from_list(&tables, &counter))
1867
      return true;
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1868
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1869
    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
1870
      break;
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1871
    if (not need_reopen)
1109.1.2 by Brian Aker
More from the table patch
1872
      return true;
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1873
    close_tables_for_reopen(&tables);
1874
  }
1875
  if ((mysql_handle_derived(lex, &mysql_derived_prepare) ||
1876
       (fill_derived_tables() &&
1877
        mysql_handle_derived(lex, &mysql_derived_filling))))
971.6.11 by Eric Day
Removed purecov messages.
1878
    return true;
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1879
1109.1.2 by Brian Aker
More from the table patch
1880
  return false;
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1881
}
1882
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1883
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
1884
{
1885
  uint32_t counter;
1090.1.3 by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart.
1886
  bool ret= fill_derived_tables();
1887
  assert(ret == false);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1888
  if (open_tables_from_list(&tables, &counter, flags) ||
1889
      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.
1890
  {
971.6.11 by Eric Day
Removed purecov messages.
1891
    return true;
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
1892
  }
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1893
  return false;
1894
}
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1895
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
1896
/*
1897
  @note "best_effort" is used in cases were if a failure occurred on this
1898
  operation it would not be surprising because we are only removing because there
1899
  might be an issue (lame engines).
1900
*/
1901
1902
bool Session::rm_temporary_table(TableIdentifier &identifier, bool best_effort)
1223.4.8 by Brian Aker
More table identifier love :)
1903
{
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
1904
  if (plugin::StorageEngine::dropTable(*this, identifier))
1223.4.8 by Brian Aker
More table identifier love :)
1905
  {
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
1906
    if (not best_effort)
1907
    {
1908
      errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
1909
                    identifier.getSQLPath().c_str(), errno);
1910
    }
1320.1.9 by Brian Aker
Removing special case dropTable()
1911
1912
    return true;
1223.4.8 by Brian Aker
More table identifier love :)
1913
  }
1320.1.9 by Brian Aker
Removing special case dropTable()
1914
1915
  return false;
1223.4.8 by Brian Aker
More table identifier love :)
1916
}
1917
1395.1.8 by Brian Aker
Cleanup usage of TI so that the NULL ones no longer exist.
1918
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
1919
{
1920
  assert(base);
1921
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
1922
  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
1923
  {
1924
    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
1925
                  identifier.getSQLPath().c_str(), errno);
1926
1927
    return true;
1928
  }
1929
1930
  return false;
1931
}
1932
1933
/**
1934
  @note this will be removed, I am looking through Hudson to see if it is finding
1935
  any tables that are missed during cleanup.
1936
*/
1937
void Session::dumpTemporaryTableNames(const char *foo)
1938
{
1939
  Table *table;
1940
1941
  if (not temporary_tables)
1942
    return;
1943
1944
  cerr << "Begin Run: " << foo << "\n";
1608 by Brian Aker
This encapsulates prev/next.
1945
  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
1946
  {
1947
    bool have_proto= false;
1948
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1949
    message::Table *proto= table->getShare()->getTableProto();
1950
    if (table->getShare()->getTableProto())
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
1951
      have_proto= true;
1952
1953
    const char *answer= have_proto ? "true" : "false";
1954
1955
    if (have_proto)
1956
    {
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1957
      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
1958
      cerr << "\t\t Proto " << proto->schema() << " " << proto->name() << "\n";
1959
    }
1960
    else
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
1961
      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
1962
  }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1963
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1964
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
1965
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.
1966
{
1967
  table_message_cache.insert(make_pair(identifier.getPath(), table_message));
1968
1969
  return true;
1970
}
1971
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
1972
bool Session::removeTableMessage(const TableIdentifier &identifier)
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1973
{
1974
  TableMessageCache::iterator iter;
1975
1976
  iter= table_message_cache.find(identifier.getPath());
1977
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
1978
  if (iter == table_message_cache.end())
1979
    return false;
1980
1981
  table_message_cache.erase(iter);
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1982
1983
  return true;
1984
}
1985
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
1986
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.
1987
{
1988
  TableMessageCache::iterator iter;
1989
1990
  iter= table_message_cache.find(identifier.getPath());
1991
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
1992
  if (iter == table_message_cache.end())
1993
    return false;
1994
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1995
  table_message.CopyFrom(((*iter).second));
1996
1997
  return true;
1998
}
1999
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
2000
bool Session::doesTableMessageExist(const TableIdentifier &identifier)
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
2001
{
2002
  TableMessageCache::iterator iter;
2003
2004
  iter= table_message_cache.find(identifier.getPath());
2005
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
2006
  if (iter == table_message_cache.end())
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
2007
  {
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
2008
    return false;
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
2009
  }
2010
1372.1.4 by Brian Aker
Update to remove cache in enginges for per session (which also means... no
2011
  return true;
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
2012
}
2013
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
2014
bool Session::renameTableMessage(const TableIdentifier &from, const TableIdentifier &to)
1390 by Brian Aker
Update interface to use Identifiers directly.
2015
{
2016
  TableMessageCache::iterator iter;
2017
2018
  table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
2019
1395.1.1 by Brian Aker
Fixes for alter table to make sure that the proto on disk is valid.
2020
  iter= table_message_cache.find(to.getPath());
2021
2022
  if (iter == table_message_cache.end())
2023
  {
2024
    return false;
2025
  }
2026
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
2027
  (*iter).second.set_schema(to.getSchemaName());
2028
  (*iter).second.set_name(to.getTableName());
1390 by Brian Aker
Update interface to use Identifiers directly.
2029
2030
  return true;
2031
}
2032
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
2033
TableShareInstance *Session::getTemporaryShare(TableIdentifier::Type type_arg)
2034
{
2035
  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
2036
2037
  TableShareInstance *tmp_share= temporary_shares.back();
2038
2039
  assert(tmp_share);
2040
2041
  return tmp_share;
2042
}
2043
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2044
} /* namespace drizzled */