~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
20
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.
21
#ifndef DRIZZLED_SESSION_H
22
#define DRIZZLED_SESSION_H
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
23
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
24
#include "drizzled/plugin.h"
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
25
#include "drizzled/sql_locale.h"
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
26
#include "drizzled/resource_context.h"
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
27
#include "drizzled/cursor.h"
28
#include "drizzled/current_session.h"
29
#include "drizzled/sql_error.h"
30
#include "drizzled/file_exchange.h"
31
#include "drizzled/select_result_interceptor.h"
32
#include "drizzled/statistics_variables.h"
33
#include "drizzled/xid.h"
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
34
#include "drizzled/query_id.h"
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
35
#include "drizzled/named_savepoint.h"
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
36
#include "drizzled/transaction_context.h"
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
37
#include "drizzled/util/storable.h"
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
38
#include "drizzled/my_hash.h"
1933.2.3 by Brian Aker
Have session store a copy of its current thread.
39
#include "drizzled/pthread_globals.h"
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...
40
#include <netdb.h>
1955.3.1 by Monty Taylor
Removed the need for getrusage.h by doing a define check and an AC_DEFINE in
41
#include <sys/time.h>
42
#include <sys/resource.h>
43
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
44
#include <algorithm>
45
#include <bitset>
46
#include <deque>
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
47
#include <map>
694 by Brian Aker
Refactor out char* strdup for string class in user.
48
#include <string>
1 by brian
clean slate
49
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
50
#include "drizzled/identifier.h"
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
51
#include "drizzled/open_tables_state.h"
52
#include "drizzled/internal_error_handler.h"
53
#include "drizzled/diagnostics_area.h"
54
#include "drizzled/plugin/authorization.h"
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
55
1669.3.4 by Brian Aker
Fix up a few additional cases around case insensitive usage for
56
#include <boost/unordered_map.hpp>
1933.2.1 by Brian Aker
Added a sessions table function, and a "THREAD_ID" column to it.
57
58
#include <boost/thread/thread.hpp>
1689.3.7 by Brian Aker
Covnert session lock
59
#include <boost/thread/mutex.hpp>
1812.3.7 by Brian Aker
Typdef our lock type.
60
#include <boost/thread/shared_mutex.hpp>
1703.1.1 by Brian Aker
Update lock interface.
61
#include <boost/thread/condition_variable.hpp>
1976.5.4 by Brian Aker
Update schema, make sure that it always ruturns a valid string (it just
62
#include <boost/make_shared.hpp>
63
1669.3.4 by Brian Aker
Fix up a few additional cases around case insensitive usage for
64
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...
65
#define MIN_HANDSHAKE_SIZE      6
66
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
67
namespace drizzled
68
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
69
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
70
namespace plugin
71
{
72
class Client;
73
class Scheduler;
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
74
class EventObserverList;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
75
}
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
76
1143.2.10 by Jay Pipes
Phase 2 new replication work:
77
namespace message
78
{
79
class Transaction;
80
class Statement;
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
81
class Resultset;
1143.2.10 by Jay Pipes
Phase 2 new replication work:
82
}
1877.2.1 by Brian Aker
Refactor table_cache_insert_placeholder.
83
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
84
namespace internal
85
{
86
struct st_my_thread_var;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
87
}
88
1877.2.1 by Brian Aker
Refactor table_cache_insert_placeholder.
89
namespace table
90
{
91
class Placeholder;
92
}
93
1 by brian
clean slate
94
class Lex_input_stream;
584.1.12 by Monty Taylor
HA! Removed item.h from common_includes. woot.
95
class user_var_entry;
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
96
class CopyField;
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.
97
class Table_ident;
1 by brian
clean slate
98
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
99
class TableShareInstance;
100
1 by brian
clean slate
101
extern char internal_table_name[2];
102
extern char empty_c_string[1];
103
extern const char **errmesg;
104
105
#define TC_HEURISTIC_RECOVER_COMMIT   1
106
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
482 by Brian Aker
Remove uint.
107
extern uint32_t tc_heuristic_recover;
1 by brian
clean slate
108
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.
109
/**
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
110
  @brief
111
  Local storage for proto that are tmp table. This should be enlarged
112
  to hande the entire table-share for a local table. Once Hash is done,
113
  we should consider exchanging the map for it.
114
*/
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
115
typedef std::map <std::string, message::Table> ProtoCache;
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
116
117
/**
1 by brian
clean slate
118
  The COPY_INFO structure is used by INSERT/REPLACE code.
119
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
120
  UPDATE code:
121
    If a row is inserted then the copied variable is incremented.
122
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
123
      new data differs from the old one then the copied and the updated
124
      variables are incremented.
125
    The touched variable is incremented if a row was touched by the update part
126
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
127
      was actually changed or not.
128
*/
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
129
class CopyInfo 
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.
130
{
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
131
public:
1 by brian
clean slate
132
  ha_rows records; /**< Number of processed records */
133
  ha_rows deleted; /**< Number of deleted records */
134
  ha_rows updated; /**< Number of updated records */
135
  ha_rows copied;  /**< Number of copied records */
136
  ha_rows error_count;
137
  ha_rows touched; /* Number of touched records */
138
  enum enum_duplicates handle_duplicates;
139
  int escape_char, last_errno;
140
  bool ignore;
141
  /* for INSERT ... UPDATE */
142
  List<Item> *update_fields;
143
  List<Item> *update_values;
144
  /* for VIEW ... WITH CHECK OPTION */
1711.6.1 by Brian Aker
Style on structure cleanup
145
146
  CopyInfo() :
147
    records(0),
148
    deleted(0),
149
    updated(0),
150
    copied(0),
151
    error_count(0),
152
    touched(0),
153
    escape_char(0),
154
    last_errno(0),
155
    ignore(0),
156
    update_fields(0),
157
    update_values(0)
158
  { }
159
160
};
161
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
162
} /* namespace drizzled */
163
164
/** @TODO why is this in the middle of the file */
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
165
#include <drizzled/lex_column.h>
1 by brian
clean slate
166
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
167
namespace drizzled
168
{
169
1 by brian
clean slate
170
class select_result;
171
class Time_zone;
172
520.1.21 by Brian Aker
THD -> Session rename
173
#define Session_SENTRY_MAGIC 0xfeedd1ff
174
#define Session_SENTRY_GONE  0xdeadbeef
1 by brian
clean slate
175
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
176
struct drizzle_system_variables
1 by brian
clean slate
177
{
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
178
  drizzle_system_variables()
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
179
  {}
1 by brian
clean slate
180
  /*
181
    How dynamically allocated system variables are handled:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
182
1 by brian
clean slate
183
    The global_system_variables and max_system_variables are "authoritative"
184
    They both should have the same 'version' and 'size'.
185
    When attempting to access a dynamic variable, if the session version
186
    is out of date, then the session version is updated and realloced if
187
    neccessary and bytes copied from global to make up for missing data.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
188
  */
1 by brian
clean slate
189
  ulong dynamic_variables_version;
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
190
  char * dynamic_variables_ptr;
482 by Brian Aker
Remove uint.
191
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
192
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
193
151 by Brian Aker
Ulonglong to uint64_t
194
  uint64_t myisam_max_extra_sort_file_size;
195
  uint64_t max_heap_table_size;
196
  uint64_t tmp_table_size;
1 by brian
clean slate
197
  ha_rows select_limit;
198
  ha_rows max_join_size;
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
199
  uint64_t auto_increment_increment;
200
  uint64_t auto_increment_offset;
616 by Brian Aker
ulong fixes.
201
  uint64_t bulk_insert_buff_size;
202
  uint64_t join_buff_size;
203
  uint32_t max_allowed_packet;
204
  uint64_t max_error_count;
205
  uint64_t max_length_for_sort_data;
910.4.4 by Stewart Smith
max_sort_length should be size_t everywhere. Causing numerous failures on SPARC and PowerPC due to strang value being retrieved in filesort. Basically, anything with filesort fails without this patch.
206
  size_t max_sort_length;
617 by Brian Aker
ulong fixes
207
  uint64_t min_examined_row_limit;
619 by Brian Aker
Removed ulong methods from vars.
208
  bool optimizer_prune_level;
1030.1.3 by Brian Aker
Final bits to structure alignment
209
  bool log_warnings;
210
619 by Brian Aker
Removed ulong methods from vars.
211
  uint32_t optimizer_search_depth;
1030.1.3 by Brian Aker
Final bits to structure alignment
212
  uint32_t div_precincrement;
619 by Brian Aker
Removed ulong methods from vars.
213
  uint64_t preload_buff_size;
214
  uint32_t read_buff_size;
215
  uint32_t read_rnd_buff_size;
1938.3.1 by David Shrewsbury
Add --replicate-query option.
216
  bool replicate_query;
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
217
  size_t sortbuff_size;
619 by Brian Aker
Removed ulong methods from vars.
218
  uint32_t thread_handling;
617 by Brian Aker
ulong fixes
219
  uint32_t tx_isolation;
1802.14.1 by Joseph Daly
add variable for gpb size
220
  size_t transaction_message_threshold;
619 by Brian Aker
Removed ulong methods from vars.
221
  uint32_t completion_type;
1 by brian
clean slate
222
  /* Determines which non-standard SQL behaviour should be enabled */
619 by Brian Aker
Removed ulong methods from vars.
223
  uint32_t sql_mode;
617 by Brian Aker
ulong fixes
224
  uint64_t max_seeks_for_key;
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
225
  size_t range_alloc_block_size;
615 by Brian Aker
Added 32bit system variable support
226
  uint32_t query_alloc_block_size;
227
  uint32_t query_prealloc_size;
617 by Brian Aker
ulong fixes
228
  uint64_t group_concat_max_len;
555 by Monty
Fixed 32-bit issues.
229
  uint64_t pseudo_thread_id;
1 by brian
clean slate
230
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
231
  plugin::StorageEngine *storage_engine;
1 by brian
clean slate
232
233
  /* Only charset part of these variables is sensible */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
234
  const CHARSET_INFO  *character_set_filesystem;
1 by brian
clean slate
235
236
  /* Both charset and collation parts of these variables are important */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
237
  const CHARSET_INFO	*collation_server;
748 by Brian Aker
Removal of client side collation.
238
239
  inline const CHARSET_INFO  *getCollation(void) 
240
  {
1014.3.2 by Brian Aker
Factor out need for session in many "schema" calls. Removed variable about
241
    return collation_server;
748 by Brian Aker
Removal of client side collation.
242
  }
1 by brian
clean slate
243
244
  /* Locale Support */
245
  MY_LOCALE *lc_time_names;
246
247
  Time_zone *time_zone;
248
};
249
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
250
extern struct drizzle_system_variables global_system_variables;
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
251
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
252
} /* namespace drizzled */
253
254
#include "drizzled/sql_lex.h"
255
256
namespace drizzled
257
{
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
520.1.22 by Brian Aker
Second pass of thd cleanup
259
void mark_transaction_to_rollback(Session *session, bool all);
1 by brian
clean slate
260
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
261
/**
262
  Storage engine specific thread local data.
263
*/
264
struct Ha_data
265
{
266
  /**
267
    Storage engine specific thread local data.
268
    Lifetime: one user connection.
269
  */
270
  void *ha_ptr;
271
  /**
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
272
   * Resource contexts for both the "statement" and "normal"
273
   * transactions.
274
   *
275
   * Resource context at index 0:
276
   *
277
   * Life time: one statement within a transaction. If @@autocommit is
278
   * on, also represents the entire transaction.
279
   *
280
   * Resource context at index 1:
281
   *
282
   * Life time: one transaction within a connection. 
283
   *
284
   * @note
285
   *
286
   * If the storage engine does not participate in a transaction, 
287
   * there will not be a resource context.
288
   */
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
289
  drizzled::ResourceContext resource_context[2];
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
290
291
  Ha_data() :ha_ptr(NULL) {}
292
};
293
294
/**
295
 * Represents a client connection to the database server.
296
 *
297
 * Contains the client/server protocol object, the current statement
298
 * being executed, local-to-session variables and status counters, and
299
 * a host of other information.
300
 *
301
 * @todo
302
 *
1100.3.34 by Padraig O'Sullivan
Various updates after great code review from Jay. Thanks Jay!
303
 * The Session class should have a vector of Statement object pointers which
304
 * comprise the statements executed on the Session. Until this architectural
305
 * change is done, we can forget about parallel operations inside a session.
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
306
 *
307
 * @todo
308
 *
309
 * Make member variables private and have inlined accessors and setters.  Hide
310
 * all member variables that are not critical to non-internal operations of the
311
 * session object.
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.
312
 */
1823.6.1 by Brian Aker
First pass through adding back user_locks.
313
typedef int64_t session_id_t;
314
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
315
class Session : public Open_tables_state
1 by brian
clean slate
316
{
317
public:
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
318
  // Plugin storage in Session.
319
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
1932.3.3 by Brian Aker
Pull in code to abstract out the session list a bit.
320
  typedef Session* Ptr;
1932.3.5 by Brian Aker
Finish change so that we use a shared_ptr for the session list.
321
  typedef boost::shared_ptr<Session> shared_ptr;
2041.3.1 by Brian Aker
Move temp table schema drop inside of API.
322
  typedef Session& reference;
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
323
  typedef const Session& const_reference;
324
  typedef const Session* const_pointer;
325
  typedef Session* pointer;
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
326
1 by brian
clean slate
327
  /*
328
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
329
                        handler of fields used is set
330
    MARK_COLUMNS_READ:  Means a bit in read set is set to inform handler
331
	                that the field is to be read. If field list contains
520.1.22 by Brian Aker
Second pass of thd cleanup
332
                        duplicates, then session->dup_field is set to point
1 by brian
clean slate
333
                        to the last found duplicate.
334
    MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler
335
			that it needs to update this field in write_row
336
                        and update_row.
337
  */
338
  enum enum_mark_columns mark_used_columns;
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
339
  inline void* alloc(size_t size)
340
  {
1485 by Brian Aker
Updates to confine memroot
341
    return mem_root->alloc_root(size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
342
  }
343
  inline void* calloc(size_t size)
344
  {
345
    void *ptr;
1485 by Brian Aker
Updates to confine memroot
346
    if ((ptr= mem_root->alloc_root(size)))
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
347
      memset(ptr, 0, size);
348
    return ptr;
349
  }
350
  inline char *strdup(const char *str)
351
  {
1487 by Brian Aker
More updates for memory::Root
352
    return mem_root->strdup_root(str);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
353
  }
354
  inline char *strmake(const char *str, size_t size)
355
  {
1487 by Brian Aker
More updates for memory::Root
356
    return mem_root->strmake_root(str,size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
357
  }
358
  inline void *memdup(const void *str, size_t size)
359
  {
1487 by Brian Aker
More updates for memory::Root
360
    return mem_root->memdup_root(str, size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
361
  }
362
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
363
  {
364
    void *ptr;
1485 by Brian Aker
Updates to confine memroot
365
    if ((ptr= mem_root->alloc_root(size + gap)))
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
366
      memcpy(ptr,str,size);
367
    return ptr;
368
  }
369
  /** Frees all items attached to this Statement */
370
  void free_items();
371
  /**
372
   * List of items created in the parser for this query. Every item puts
373
   * itself to the list on creation (see Item::Item() for details))
374
   */
375
  Item *free_list;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
376
  memory::Root *mem_root; /**< Pointer to current memroot */
1532.1.10 by Brian Aker
Encapsulation of mem_root for session/this switches the creation of new_path
377
1856.2.18 by Joseph Daly
code cleanup, test fixes
378
1532.1.10 by Brian Aker
Encapsulation of mem_root for session/this switches the creation of new_path
379
  memory::Root *getMemRoot()
380
  {
381
    return mem_root;
382
  }
1856.2.7 by Joseph Daly
create schema changes
383
384
  uint64_t xa_id;
385
386
  uint64_t getXaId()
387
  {
388
    return xa_id;
389
  }
390
391
  void setXaId(uint64_t in_xa_id)
392
  {
393
    xa_id= in_xa_id; 
394
  }
395
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
396
  /**
397
   * Uniquely identifies each statement object in thread scope; change during
398
   * statement lifetime.
399
   *
400
   * @todo should be const
401
   */
402
  uint32_t id;
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.
403
  LEX *lex; /**< parse tree descriptor */
1751.3.1 by Brian Aker
This add a couple of utility table functions to be used with testing.
404
405
  LEX *getLex() 
406
  {
407
    return lex;
408
  }
1280.3.11 by Padraig O'Sullivan
Changed the query member of Session to be std::string
409
  /** query associated with this statement */
1921.4.14 by Brian Aker
Update to tighten up query string.
410
  typedef boost::shared_ptr<const std::string> QueryString;
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
411
private:
1921.4.14 by Brian Aker
Update to tighten up query string.
412
  boost::shared_ptr<std::string> query;
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
413
414
  // Never allow for a modification of this outside of the class. c_str()
415
  // requires under some setup non const, you must copy the QueryString in
416
  // order to use it.
417
public:
1921.4.14 by Brian Aker
Update to tighten up query string.
418
  QueryString getQueryString() const
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
419
  {
420
    return query;
421
  }
422
423
  void resetQueryString()
424
  {
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
425
    query.reset();
426
    _state.reset();
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
427
  }
428
429
  /*
430
    We need to copy the lock on the string in order to make sure we have a stable string.
431
    Once this is done we can use it to build a const char* which can be handed off for
432
    a method to use (Innodb is currently the only engine using this).
433
  */
434
  const char *getQueryStringCopy(size_t &length)
435
  {
436
    QueryString tmp_string(getQueryString());
437
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
438
    if (not tmp_string)
439
    {
440
      length= 0;
2003.1.3 by Andrew Hutchings
Re-fix after discussion with Krow
441
      return NULL;
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
442
    }
443
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
444
    length= tmp_string->length();
445
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
446
    return to_return;
447
  }
1 by brian
clean slate
448
1976.5.1 by Brian Aker
This fixes the issue of a crash because of one thread touching the session
449
  class State {
450
    std::vector <char> _query;
451
452
  public:
453
    typedef boost::shared_ptr<State> const_shared_ptr;
454
455
    State(const char *in_packet, size_t in_packet_length)
456
    {
457
      if (in_packet_length)
458
      {
459
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
460
        _query.resize(minimum + 1);
461
        memcpy(&_query[0], in_packet, minimum);
462
      }
463
      else
464
      {
465
        _query.resize(0);
466
      }
467
    }
468
469
    const char *query() const
470
    {
471
      if (_query.size())
472
        return &_query[0];
473
474
      return "";
475
    }
476
477
    const char *query(size_t &size) const
478
    {
479
      if (_query.size())
480
      {
481
        size= _query.size() -1;
482
        return &_query[0];
483
      }
484
485
      size= 0;
486
      return "";
487
    }
488
  protected:
489
    friend class Session;
490
    typedef boost::shared_ptr<State> shared_ptr;
491
  };
492
private:
493
  State::shared_ptr  _state; 
494
public:
495
496
  State::const_shared_ptr state()
497
  {
498
    return _state;
499
  }
500
1 by brian
clean slate
501
  /**
502
    Name of the current (default) database.
503
504
    If there is the current (default) database, "db" contains its name. If
505
    there is no current (default) database, "db" is NULL and "db_length" is
506
    0. In other words, "db", "db_length" must either be NULL, or contain a
507
    valid database name.
508
509
    @note this attribute is set and alloced by the slave SQL thread (for
520.1.21 by Brian Aker
THD -> Session rename
510
    the Session of that thread); that thread is (and must remain, for now) the
1 by brian
clean slate
511
    only responsible for freeing this member.
512
  */
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
513
private:
514
  util::string::shared_ptr _schema;
515
public:
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
516
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
517
  util::string::const_shared_ptr schema() const
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
518
  {
1976.5.4 by Brian Aker
Update schema, make sure that it always ruturns a valid string (it just
519
    if (_schema)
520
      return _schema;
521
522
    return util::string::const_shared_ptr(new std::string(""));
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
523
  }
1864.3.1 by Brian Aker
Add a catalog() command.
524
  std::string catalog;
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
525
  /* current cache key */
526
  std::string query_cache_key;
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.
527
  /**
520.1.21 by Brian Aker
THD -> Session rename
528
    Constant for Session::where initialization in the beginning of every query.
1 by brian
clean slate
529
520.1.21 by Brian Aker
THD -> Session rename
530
    It's needed because we do not save/restore Session::where normally during
1 by brian
clean slate
531
    primary (non subselect) query execution.
532
  */
533
  static const char * const DEFAULT_WHERE;
534
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
535
  memory::Root warn_root; /**< Allocation area for warnings and errors */
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
536
private:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
537
  plugin::Client *client; /**< Pointer to client object */
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
538
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
539
public:
540
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
541
  void setClient(plugin::Client *client_arg);
542
543
  plugin::Client *getClient()
544
  {
545
    return client;
546
  }
547
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
548
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
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.
549
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
1927.2.1 by Brian Aker
Merge up the tree.
550
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
551
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
1927.2.1 by Brian Aker
Merge up the tree.
552
private:
1689.3.4 by Brian Aker
Remove the hash in session, for a boost based one.
553
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
554
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
555
556
public:
1927.2.1 by Brian Aker
Merge up the tree.
557
558
  const UserVars &getUserVariables() const
559
  {
560
    return user_vars;
561
  }
562
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
563
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
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.
564
  struct system_status_var status_var; /**< Session-local status counters */
565
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
566
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
567
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
568
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.
569
  /**
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.
570
   * A pointer to the stack frame of the scheduler thread
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.
571
   * which is called first in the thread for handling a client
572
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
573
  char *thread_stack;
1 by brian
clean slate
574
1273.11.5 by Dennis Schoen
add getSecurityContext()
575
private:
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
576
  identifier::User::shared_ptr security_ctx;
1377.6.3 by pawel
changed function-like defines into functions in some files
577
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
578
  int32_t scoreboard_index;
579
1377.6.3 by pawel
changed function-like defines into functions in some files
580
  inline void checkSentry() const
581
  {
582
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
583
  }
1273.11.5 by Dennis Schoen
add getSecurityContext()
584
public:
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
585
  identifier::User::const_shared_ptr user() const
1273.11.5 by Dennis Schoen
add getSecurityContext()
586
  {
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
587
    if (security_ctx)
588
      return security_ctx;
589
590
    return identifier::User::const_shared_ptr();
1273.11.5 by Dennis Schoen
add getSecurityContext()
591
  }
1 by brian
clean slate
592
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
593
  void setUser(identifier::User::shared_ptr arg)
1273.11.7 by Dennis Schoen
add second getSecurityContext() function that returns a non-const refernce
594
  {
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
595
    security_ctx= arg;
1273.11.7 by Dennis Schoen
add second getSecurityContext() function that returns a non-const refernce
596
  }
597
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
598
  int32_t getScoreboardIndex()
599
  {
600
    return scoreboard_index;
601
  }
602
603
  void setScoreboardIndex(int32_t in_scoreboard_index)
604
  {
605
    scoreboard_index= in_scoreboard_index;
606
  }
607
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.
608
  /**
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
609
   * Is this session viewable by the current user?
610
   */
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
611
  bool isViewable(identifier::User::const_reference) const;
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
612
613
  /**
1 by brian
clean slate
614
    Used in error messages to tell user in what part of MySQL we found an
615
    error. E. g. when where= "having clause", if fix_fields() fails, user
616
    will know that the error was in having clause.
617
  */
618
  const char *where;
619
620
  /*
621
    One thread can hold up to one named user-level lock. This variable
622
    points to a lock object if the lock is present. See item_func.cc and
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
623
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1 by brian
clean slate
624
  */
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.
625
  uint32_t dbug_sentry; /**< watch for memory corruption */
1775.4.4 by Brian Aker
Cleanup my_thread_var usage.
626
private:
1933.2.1 by Brian Aker
Added a sessions table function, and a "THREAD_ID" column to it.
627
  boost::thread::id boost_thread_id;
1933.2.3 by Brian Aker
Have session store a copy of its current thread.
628
  boost_thread_shared_ptr _thread;
1933.2.4 by Brian Aker
Update user locks to allow for interruption based on boost.
629
  boost::this_thread::disable_interruption *interrupt;
1933.2.1 by Brian Aker
Added a sessions table function, and a "THREAD_ID" column to it.
630
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
631
  internal::st_my_thread_var *mysys_var;
1775.4.4 by Brian Aker
Cleanup my_thread_var usage.
632
public:
633
1933.2.3 by Brian Aker
Have session store a copy of its current thread.
634
  boost_thread_shared_ptr &getThread()
635
  {
636
    return _thread;
1933.2.1 by Brian Aker
Added a sessions table function, and a "THREAD_ID" column to it.
637
  }
638
1933.2.4 by Brian Aker
Update user locks to allow for interruption based on boost.
639
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
640
  {
641
    interrupt= interrupt_arg;
642
  }
643
644
  boost::this_thread::disable_interruption &getThreadInterupt()
645
  {
646
    assert(interrupt);
647
    return *interrupt;
648
  }
649
1775.4.4 by Brian Aker
Cleanup my_thread_var usage.
650
  internal::st_my_thread_var *getThreadVar()
651
  {
652
    return mysys_var;
653
  }
654
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.
655
  /**
656
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
657
   * first byte of the packet in executeStatement()
658
   */
1 by brian
clean slate
659
  enum enum_server_command command;
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.
660
  uint32_t file_id;	/**< File ID for LOAD DATA INFILE */
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
661
  /* @note the following three members should likely move to Client */
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
662
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
663
2040.4.2 by Brian Aker
First pass on removing some of the calls currently to boost::posix_time. (we
664
private:
665
  boost::posix_time::ptime _epoch;
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
666
  boost::posix_time::ptime _connect_time;
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
667
  boost::posix_time::ptime _start_timer;
668
  boost::posix_time::ptime _end_timer;
2040.4.2 by Brian Aker
First pass on removing some of the calls currently to boost::posix_time. (we
669
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
670
  boost::posix_time::ptime _user_time;
2040.4.4 by Brian Aker
Make more time usage private.
671
public:
672
  uint64_t utime_after_lock; // This used by Innodb.
673
674
  void resetUserTime()
675
  {
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
676
    _user_time= boost::posix_time::not_a_date_time;
2040.4.4 by Brian Aker
Make more time usage private.
677
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
678
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
679
  const boost::posix_time::ptime &start_timer() const
680
  {
681
    return _start_timer;
682
  }
683
684
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
685
  {
686
    result_arg=  arg - _start_timer;
687
  }
688
1 by brian
clean slate
689
  thr_lock_type update_lock_default;
690
661 by Brian Aker
First major pass through new replication.
691
  /*
692
    Both of the following container points in session will be converted to an API.
693
  */
694
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)
695
private:
1 by brian
clean slate
696
  /* container for handler's private per-connection data */
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
697
  std::vector<Ha_data> ha_data;
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
698
  /*
699
    Id of current query. Statement can be reused to execute several queries
700
    query_id is global in context of the whole MySQL server.
701
    ID is automatically generated from an atomic counter.
702
    It's used in Cursor code for various purposes: to check which columns
703
    from table are necessary for this select, to check if it's necessary to
704
    update auto-updatable fields (like auto_increment and timestamp).
705
  */
706
  query_id_t query_id;
707
  query_id_t warn_query_id;
2040.4.2 by Brian Aker
First pass on removing some of the calls currently to boost::posix_time. (we
708
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)
709
public:
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
710
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
711
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
1273.1.11 by Jay Pipes
Merge trunk changes and resolve conflicts
712
                                      size_t index= 0);
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)
713
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
714
  /**
715
   * Structure used to manage "statement transactions" and
716
   * "normal transactions". In autocommit mode, the normal transaction is
717
   * equivalent to the statement transaction.
718
   *
719
   * Storage engines will be registered here when they participate in
720
   * a transaction. No engine is registered more than once.
721
   */
1 by brian
clean slate
722
  struct st_transactions {
1273.1.11 by Jay Pipes
Merge trunk changes and resolve conflicts
723
    std::deque<NamedSavepoint> savepoints;
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
724
725
    /**
726
     * The normal transaction (since BEGIN WORK).
727
     *
728
     * Contains a list of all engines that have participated in any of the
729
     * statement transactions started within the context of the normal
730
     * transaction.
731
     *
732
     * @note In autocommit mode, this is empty.
733
     */
734
    TransactionContext all;
735
736
    /**
737
     * The statment transaction.
738
     *
739
     * Contains a list of all engines participating in the given statement.
740
     *
1861.6.3 by David Shrewsbury
Move GPB manipulation code out of Session and into TransactionServices.
741
     * @note In autocommit mode, this will be used to commit/rollback the
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
742
     * normal transaction.
743
     */
744
    TransactionContext stmt;
745
1 by brian
clean slate
746
    XID_STATE xid_state;
747
748
    void cleanup()
749
    {
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
750
      savepoints.clear();
1 by brian
clean slate
751
    }
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
752
    st_transactions() :
753
      savepoints(),
754
      all(),
755
      stmt(),
756
      xid_state()
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
757
    { }
1 by brian
clean slate
758
  } transaction;
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
759
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.
760
  Field *dup_field;
1 by brian
clean slate
761
  sigset_t signals;
762
1921.4.2 by Brian Aker
Adding in concurrent execute support.
763
  // As of right now we do not allow a concurrent execute to launch itself
764
private:
765
  bool concurrent_execute_allowed;
766
public:
767
768
  void setConcurrentExecute(bool arg)
769
  {
770
    concurrent_execute_allowed= arg;
771
  }
772
773
  bool isConcurrentExecuteAllowed() const
774
  {
775
    return concurrent_execute_allowed;
776
  }
777
1 by brian
clean slate
778
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
779
  bool arg_of_last_insert_id_function;
1921.4.2 by Brian Aker
Adding in concurrent execute support.
780
1 by brian
clean slate
781
  /*
782
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
783
    insertion into an auto_increment column".
784
  */
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.
785
  /**
1 by brian
clean slate
786
    This is the first autogenerated insert id which was *successfully*
787
    inserted by the previous statement (exactly, if the previous statement
788
    didn't successfully insert an autogenerated insert id, then it's the one
789
    of the statement before, etc).
790
    It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#).
791
    It is returned by LAST_INSERT_ID().
792
  */
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.
793
  uint64_t first_successful_insert_id_in_prev_stmt;
794
  /**
1 by brian
clean slate
795
    This is the first autogenerated insert id which was *successfully*
796
    inserted by the current statement. It is maintained only to set
797
    first_successful_insert_id_in_prev_stmt when statement ends.
798
  */
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.
799
  uint64_t first_successful_insert_id_in_cur_stmt;
800
  /**
1 by brian
clean slate
801
    We follow this logic:
802
    - when stmt starts, first_successful_insert_id_in_prev_stmt contains the
803
    first insert id successfully inserted by the previous stmt.
804
    - as stmt makes progress, handler::insert_id_for_cur_row changes;
805
    every time get_auto_increment() is called,
806
    auto_inc_intervals_in_cur_stmt_for_binlog is augmented with the
807
    reserved interval (if statement-based binlogging).
808
    - at first successful insertion of an autogenerated value,
809
    first_successful_insert_id_in_cur_stmt is set to
810
    handler::insert_id_for_cur_row.
811
    - when stmt goes to binlog,
812
    auto_inc_intervals_in_cur_stmt_for_binlog is binlogged if
813
    non-empty.
814
    - when stmt ends, first_successful_insert_id_in_prev_stmt is set to
815
    first_successful_insert_id_in_cur_stmt.
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.
816
1 by brian
clean slate
817
    List of auto_increment intervals reserved by the thread so far, for
818
    storage in the statement-based binlog.
819
    Note that its minimum is not first_successful_insert_id_in_cur_stmt:
820
    assuming a table with an autoinc column, and this happens:
821
    INSERT INTO ... VALUES(3);
822
    SET INSERT_ID=3; INSERT IGNORE ... VALUES (NULL);
823
    then the latter INSERT will insert no rows
824
    (first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3"
825
    in the binlog is still needed; the list's minimum will contain 3.
826
  */
827
  Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
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.
828
  /** Used by replication and SET INSERT_ID */
1 by brian
clean slate
829
  Discrete_intervals_list auto_inc_intervals_forced;
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.
830
831
  uint64_t limit_found_rows;
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
832
  uint64_t options; /**< Bitmap of options */
833
  int64_t row_count_func; /**< For the ROW_COUNT() function */
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.
834
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
835
836
  /** 
837
   * Number of rows we actually sent to the client, including "synthetic"
838
   * rows in ROLLUP etc.
839
   */
840
  ha_rows sent_row_count;
841
842
  /**
843
   * Number of rows we read, sent or not, including in create_sort_index()
844
   */
845
  ha_rows examined_row_count;
846
847
  /**
848
   * The set of those tables whose fields are referenced in all subqueries
849
   * of the query.
850
   *
851
   * @todo
852
   * 
853
   * Possibly this it is incorrect to have used tables in Session because
854
   * with more than one subquery, it is not clear what does the field mean.
855
   */
856
  table_map used_tables;
857
858
  /**
859
    @todo
860
    
861
    This, and some other variables like 'count_cuted_fields'
1 by brian
clean slate
862
    maybe should be statement/cursor local, that is, moved to Statement
863
    class. With current implementation warnings produced in each prepared
864
    statement/cursor settle here.
865
  */
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.
866
  List<DRIZZLE_ERROR> warn_list;
867
  uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
868
  uint32_t total_warn_count;
1 by brian
clean slate
869
  Diagnostics_area main_da;
870
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.
871
  ulong col_access;
1 by brian
clean slate
872
873
  /* Statement id is thread-wide. This counter is used to generate ids */
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.
874
  uint32_t statement_id_counter;
875
  uint32_t rand_saved_seed1;
876
  uint32_t rand_saved_seed2;
877
  /**
1 by brian
clean slate
878
    Row counter, mainly for errors and warnings. Not increased in
879
    create_sort_index(); may differ from examined_row_count.
880
  */
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.
881
  uint32_t row_count;
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
882
883
  uint32_t getRowCount() const
884
  {
885
    return row_count;
886
  }
887
1823.6.1 by Brian Aker
First pass through adding back user_locks.
888
  session_id_t thread_id;
1046.1.7 by Brian Aker
Style cleanup.
889
  uint32_t tmp_table;
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
890
  enum global_read_lock_t
891
  {
892
    NONE= 0,
893
    GOT_GLOBAL_READ_LOCK= 1,
894
    MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
895
  };
896
private:
897
  global_read_lock_t _global_read_lock;
898
899
public:
900
901
  global_read_lock_t isGlobalReadLock() const
902
  {
903
    return _global_read_lock;
904
  }
905
906
  void setGlobalReadLock(global_read_lock_t arg)
907
  {
908
    _global_read_lock= arg;
909
  }
910
1910.2.7 by Brian Aker
Rename lock methods to be style + well make sense.
911
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
912
  bool lockGlobalReadLock();
913
  bool lock_table_names(TableList *table_list);
914
  bool lock_table_names_exclusively(TableList *table_list);
915
  bool makeGlobalReadLockBlockCommit();
1910.2.7 by Brian Aker
Rename lock methods to be style + well make sense.
916
  bool abortLockForThread(Table *table);
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
917
  bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
1910.2.4 by Brian Aker
Push some functions behind classes.
918
  int lock_table_name(TableList *table_list);
1910.2.7 by Brian Aker
Rename lock methods to be style + well make sense.
919
  void abortLock(Table *table);
920
  void removeLock(Table *table);
921
  void unlockReadTables(DrizzleLock *sql_lock);
922
  void unlockSomeTables(Table **table, uint32_t count);
923
  void unlockTables(DrizzleLock *sql_lock);
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
924
  void startWaitingGlobalReadLock();
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
925
  void unlockGlobalReadLock();
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
926
927
private:
928
  int unlock_external(Table **table, uint32_t count);
929
  int lock_external(Table **tables, uint32_t count);
1910.2.4 by Brian Aker
Push some functions behind classes.
930
  bool wait_for_locked_table_names(TableList *table_list);
931
  DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
932
                             bool should_lock, Table **write_lock_used);
1910.2.3 by Brian Aker
Second pass on move code to global lock encapsulation.
933
public:
1910.2.2 by Brian Aker
First pass through the global lock refactor merge.
934
1046.1.7 by Brian Aker
Style cleanup.
935
  uint32_t server_status;
936
  uint32_t open_options;
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.
937
  uint32_t select_number; /**< number of select (used for EXPLAIN) */
1 by brian
clean slate
938
  /* variables.transaction_isolation is reset to this after each commit */
939
  enum_tx_isolation session_tx_isolation;
940
  enum_check_fields count_cuted_fields;
941
1910.2.8 by Brian Aker
Enapsulate Kill.
942
  enum killed_state_t
1 by brian
clean slate
943
  {
550 by Monty Taylor
Moved error.h into just the files that need it.
944
    NOT_KILLED,
945
    KILL_BAD_DATA,
946
    KILL_CONNECTION,
947
    KILL_QUERY,
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.
948
    KILLED_NO_VALUE /* means none of the above states apply */
1 by brian
clean slate
949
  };
1910.2.8 by Brian Aker
Enapsulate Kill.
950
private:
951
  killed_state_t volatile _killed;
952
953
public:
954
955
  void setKilled(killed_state_t arg)
956
  {
957
    _killed= arg;
958
  }
959
960
  killed_state_t getKilled()
961
  {
962
    return _killed;
963
  }
964
965
  volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
966
  {
967
    return &_killed;
968
  }
1 by brian
clean slate
969
1960.2.1 by Andrew Hutchings
Add admin connection to client/server protocols
970
  bool is_admin_connection;
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.
971
  bool some_tables_deleted;
972
  bool no_errors;
973
  bool password;
1 by brian
clean slate
974
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
975
    Set to true if execution of the current compound statement
1 by brian
clean slate
976
    can not continue. In particular, disables activation of
977
    CONTINUE or EXIT handlers of stored routines.
978
    Reset in the end of processing of the current user request, in
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
979
    @see reset_session_for_next_command().
1 by brian
clean slate
980
  */
981
  bool is_fatal_error;
982
  /**
983
    Set by a storage engine to request the entire
984
    transaction (that possibly spans multiple engines) to
985
    rollback. Reset in ha_rollback.
986
  */
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.
987
  bool transaction_rollback_request;
1 by brian
clean slate
988
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
989
    true if we are in a sub-statement and the current error can
1 by brian
clean slate
990
    not be safely recovered until we left the sub-statement mode.
991
    In particular, disables activation of CONTINUE and EXIT
992
    handlers inside sub-statements. E.g. if it is a deadlock
993
    error and requires a transaction-wide rollback, this flag is
994
    raised (traditionally, MySQL first has to close all the reads
995
    via @see handler::ha_index_or_rnd_end() and only then perform
996
    the rollback).
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
997
    Reset to false when we leave the sub-statement mode.
1 by brian
clean slate
998
  */
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.
999
  bool is_fatal_sub_stmt_error;
1000
  /** for IS NULL => = last_insert_id() fix in remove_eq_conds() */
1001
  bool substitute_null_with_insert_id;
1002
  bool cleanup_done;
1003
1004
  bool abort_on_warning;
1005
  bool got_warning; /**< Set on call to push_warning() */
1006
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
1007
  /** set during loop of derived table processing */
1008
  bool derived_tables_processing;
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
1009
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
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.
1010
1011
  /** Used by the sys_var class to store temporary values */
1 by brian
clean slate
1012
  union
1013
  {
1055.2.17 by Jay Pipes
More style cleanups in Session
1014
    bool bool_value;
1015
    uint32_t uint32_t_value;
1016
    int32_t int32_t_value;
151 by Brian Aker
Ulonglong to uint64_t
1017
    uint64_t uint64_t_value;
1 by brian
clean slate
1018
  } sys_var_tmp;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1019
1 by brian
clean slate
1020
  /**
1021
    Character input stream consumed by the lexical analyser,
1022
    used during parsing.
1023
    Note that since the parser is not re-entrant, we keep only one input
1024
    stream here. This member is valid only when executing code during parsing,
1025
    and may point to invalid memory after that.
1026
  */
1027
  Lex_input_stream *m_lip;
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.
1028
  
1029
  /** Place to store various things */
1030
  void *session_marker;
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
1031
1055.2.17 by Jay Pipes
More style cleanups in Session
1032
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
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.
1033
  Table *cached_table;
1034
1035
  /**
1036
    Points to info-string that we show in SHOW PROCESSLIST
1037
    You are supposed to call Session_SET_PROC_INFO only if you have coded
1038
    a time-consuming piece that MySQL can get stuck in for a long time.
1039
1040
    Set it using the  session_proc_info(Session *thread, const char *message)
1041
    macro/function.
1042
  */
1043
  inline void set_proc_info(const char *info)
1044
  { 
1045
    proc_info= info;
1046
  }
1047
  inline const char* get_proc_info() const
1048
  {
1049
    return proc_info;
1050
  }
1051
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
1052
  /** Sets this Session's current query ID */
1053
  inline void setQueryId(query_id_t in_query_id)
1054
  {
1055
    query_id= in_query_id;
1056
  }
1057
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.
1058
  /** Returns the current query ID */
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
1059
  query_id_t getQueryId()  const
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.
1060
  {
1061
    return query_id;
1062
  }
1063
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
1064
1065
  /** Sets this Session's warning query ID */
1066
  inline void setWarningQueryId(query_id_t in_query_id)
1067
  {
1068
    warn_query_id= in_query_id;
1069
  }
1070
1071
  /** Returns the Session's warning query ID */
1072
  inline query_id_t getWarningQueryId()  const
1073
  {
1074
    return warn_query_id;
1075
  }
1076
1039.5.56 by Jay Pipes
Adds Session ID accessor, and output to replication messages
1077
  /** Accessor method returning the session's ID. */
1823.6.1 by Brian Aker
First pass through adding back user_locks.
1078
  inline session_id_t getSessionId()  const
1039.5.56 by Jay Pipes
Adds Session ID accessor, and output to replication messages
1079
  {
1080
    return thread_id;
1081
  }
1082
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.
1083
  /** Accessor method returning the server's ID. */
1084
  inline uint32_t getServerId()  const
1085
  {
1086
    /* We return the global server ID. */
1087
    return server_id;
1088
  }
1089
1090
  /** Returns the current transaction ID for the session's current statement */
1091
  inline my_xid getTransactionId()
1092
  {
1093
    return transaction.xid_state.xid.quick_get_my_xid();
1094
  }
1095
  /**
1096
    There is BUG#19630 where statement-based replication of stored
1097
    functions/triggers with two auto_increment columns breaks.
1098
    We however ensure that it works when there is 0 or 1 auto_increment
1099
    column; our rules are
1100
    a) on master, while executing a top statement involving substatements,
1101
    first top- or sub- statement to generate auto_increment values wins the
1102
    exclusive right to see its values be written to binlog (the write
1103
    will be done by the statement or its caller), and the losers won't see
1104
    their values be written to binlog.
1105
    b) on slave, while replicating a top statement involving substatements,
1106
    first top- or sub- statement to need to read auto_increment values from
1107
    the master's binlog wins the exclusive right to read them (so the losers
1108
    won't read their values from binlog but instead generate on their own).
1109
    a) implies that we mustn't backup/restore
1110
    auto_inc_intervals_in_cur_stmt_for_binlog.
1111
    b) implies that we mustn't backup/restore auto_inc_intervals_forced.
1112
1113
    If there are more than 1 auto_increment columns, then intervals for
1114
    different columns may mix into the
1115
    auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong,
1116
    but there is no point in preventing this mixing by preventing intervals
1117
    from the secondly inserted column to come into the list, as such
1118
    prevention would be wrong too.
1119
    What will happen in the case of
1120
    INSERT INTO t1 (auto_inc) VALUES(NULL);
1121
    where t1 has a trigger which inserts into an auto_inc column of t2, is
1122
    that in binlog we'll store the interval of t1 and the interval of t2 (when
1123
    we store intervals, soon), then in slave, t1 will use both intervals, t2
1124
    will use none; if t1 inserts the same number of rows as on master,
1125
    normally the 2nd interval will not be used by t1, which is fine. t2's
1126
    values will be wrong if t2's internal auto_increment counter is different
1127
    from what it was on master (which is likely). In 5.1, in mixed binlogging
1128
    mode, row-based binlogging is used for such cases where two
1129
    auto_increment columns are inserted.
1130
  */
1131
  inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
1132
  {
1133
    if (first_successful_insert_id_in_cur_stmt == 0)
1134
      first_successful_insert_id_in_cur_stmt= id_arg;
1135
  }
1136
  inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
1137
  {
1138
    return first_successful_insert_id_in_prev_stmt;
1139
  }
1140
  /**
1141
    Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
1142
    (mysqlbinlog). We'll soon add a variant which can take many intervals in
1143
    argument.
1144
  */
1145
  inline void force_one_auto_inc_interval(uint64_t next_id)
1146
  {
1147
    auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
1148
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1149
  }
1 by brian
clean slate
1150
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1151
  Session(plugin::Client *client_arg);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
1152
  virtual ~Session();
1 by brian
clean slate
1153
1154
  void cleanup(void);
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1155
  /**
1156
   * Cleans up after query.
1157
   *
1158
   * @details
1159
   *
1160
   * This function is used to reset thread data to its default state.
1161
   *
1162
   * This function is not suitable for setting thread data to some
1163
   * non-default values, as there is only one replication thread, so
1164
   * different master threads may overwrite data of each other on
1165
   * slave.
1166
   */
1 by brian
clean slate
1167
  void cleanup_after_query();
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.
1168
  bool storeGlobals();
1910.2.8 by Brian Aker
Enapsulate Kill.
1169
  void awake(Session::killed_state_t state_to_set);
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1170
  /**
1171
   * Pulls thread-specific variables into Session state.
1172
   *
1173
   * Returns true most times, or false if there was a problem
1174
   * allocating resources for thread-specific storage.
1175
   *
1176
   * @TODO Kill this.  It's not necessary once my_thr_init() is bye bye.
1177
   *
1178
   */
1179
  bool initGlobals();
1180
1181
  /**
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.
1182
    Initialize memory roots necessary for query processing and (!)
1183
    pre-allocate memory for it. We can't do that in Session constructor because
971.3.70 by Eric Day
Fixed style issues found by Jay.
1184
    there are use cases where it's vital to not allocate excessive and not used
1185
    memory.
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.
1186
  */
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1187
  void prepareForQueries();
1 by brian
clean slate
1188
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...
1189
  /**
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.
1190
   * Executes a single statement received from the 
1191
   * client connection.
1192
   *
1193
   * Returns true if the statement was successful, or false 
1194
   * otherwise.
1195
   *
1196
   * @note
1197
   *
1198
   * For profiling to work, it must never be called recursively.
1199
   *
1200
   * In MySQL, this used to be the do_command() C function whic
1201
   * accepted a single parameter of the THD pointer.
1202
   */
1203
  bool executeStatement();
1204
1205
  /**
934.2.9 by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class.
1206
   * Reads a query from packet and stores it.
1207
   *
1208
   * Returns true if query is read and allocated successfully, 
1209
   * false otherwise.  On a return of false, Session::fatal_error
1210
   * is set.
1211
   *
1212
   * @note Used in COM_QUERY and COM_STMT_PREPARE.
1213
   *
1214
   * Sets the following Session variables:
1215
   *  - query
1216
   *  - query_length
1217
   *
1218
   * @param The packet pointer to read from
1219
   * @param The length of the query to read
1220
   */
1221
  bool readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
1222
1223
  /**
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.
1224
   * Ends the current transaction and (maybe) begins the next.
1225
   *
1226
   * Returns true if the transaction completed successfully, 
1227
   * otherwise false.
1228
   *
1229
   * @param Completion type
1230
   */
1231
  bool endTransaction(enum enum_mysql_completiontype completion);
1232
  bool endActiveTransaction();
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
1233
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
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.
1234
1235
  /**
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...
1236
   * Authenticates users, with error reporting.
1237
   *
1238
   * Returns true on success, or false on failure.
1239
   */
1240
  bool authenticate();
1241
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.
1242
  /**
1243
   * Run a session.
1244
   *
1245
   * This will initialize the session and begin the command loop.
1246
   */
1247
  void run();
1248
1249
  /**
1250
   * Schedule a session to be run on the default scheduler.
1251
   */
1932.3.13 by Brian Aker
Cleanup session ownership rules such that we know exactly when session has
1252
  static bool schedule(Session::shared_ptr&);
1932.3.3 by Brian Aker
Pull in code to abstract out the session list a bit.
1253
2015.3.3 by Brian Aker
Update disconnect code.
1254
  static void unlink(session_id_t &session_id);
1932.3.13 by Brian Aker
Cleanup session ownership rules such that we know exactly when session has
1255
  static void unlink(Session::shared_ptr&);
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.
1256
1 by brian
clean slate
1257
  /*
1258
    For enter_cond() / exit_cond() to work the mutex must be got before
1259
    enter_cond(); this mutex is then released by exit_cond().
1260
    Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1261
  */
1812.3.5 by Brian Aker
Move to boost condition_any
1262
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1241.9.55 by Monty Taylor
Moved tree into drizzled/
1263
  void exit_cond(const char* old_msg);
1264
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1265
  time_t query_start()
1266
  {
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
1267
    return getCurrentTimestampEpoch();
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1268
  }
1269
1270
  void set_time()
1271
  {
1272
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
1273
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
1 by brian
clean slate
1274
  }
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1275
2040.4.4 by Brian Aker
Make more time usage private.
1276
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
1 by brian
clean slate
1277
  {
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
1278
    _user_time= boost::posix_time::from_time_t(t);
1878.10.1 by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS.
1279
  }
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1280
1281
  void set_time_after_lock()
1282
  { 
1283
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1284
    utime_after_lock= (mytime - _epoch).total_microseconds();
1285
  }
1286
1287
  void set_end_timer()
1288
  {
1289
    _end_timer= boost::posix_time::microsec_clock::universal_time();
1290
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
1291
  }
1292
2040.4.4 by Brian Aker
Make more time usage private.
1293
  uint64_t getElapsedTime() const
1294
  {
1295
    return (_end_timer - _start_timer).total_microseconds();
1296
  }
1297
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
1298
  /**
1299
   * Returns the current micro-timestamp
1300
   */
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
1301
  uint64_t getCurrentTimestamp(bool actual= true) const
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
1302
  { 
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1303
    uint64_t t_mark;
1304
1305
    if (actual)
1306
    {
1307
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1308
      t_mark= (mytime - _epoch).total_microseconds();
1309
    }
1310
    else
1311
    {
1312
      t_mark= (_end_timer - _epoch).total_microseconds();
1313
    }
1878.10.1 by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS.
1314
1315
    return t_mark; 
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
1316
  }
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1317
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
1318
  // We may need to set user on this
1319
  int64_t getCurrentTimestampEpoch() const
1320
  { 
2040.4.6 by Brian Aker
Remove additional bits around time (more centralize, good...)
1321
    if (not _user_time.is_not_a_date_time())
1322
      return (_user_time - _epoch).total_seconds();
1323
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
1324
    return (_start_timer - _epoch).total_seconds();
1325
  }
1326
1327
  uint64_t found_rows(void) const
1 by brian
clean slate
1328
  {
1329
    return limit_found_rows;
1330
  }
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1331
934.2.28 by Jay Pipes
Renamed some things to our standards and made private methods private...
1332
  /** Returns whether the session is currently inside a transaction */
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
1333
  bool inTransaction() const
1 by brian
clean slate
1334
  {
1335
    return server_status & SERVER_STATUS_IN_TRANS;
1336
  }
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1337
1 by brian
clean slate
1338
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
482 by Brian Aker
Remove uint.
1339
                              const char* str, uint32_t length,
1 by brian
clean slate
1340
                              bool allocate_lex_string);
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1341
1273.13.38 by Brian Aker
Add in new show work.
1342
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1343
                              const std::string &str,
1344
                              bool allocate_lex_string);
1 by brian
clean slate
1345
1346
  int send_explain_fields(select_result *result);
2040.4.3 by Brian Aker
Scale down the calls to universal_time().
1347
1 by brian
clean slate
1348
  /**
1349
    Clear the current error, if any.
1350
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1351
    assume this is never called if the fatal error is set.
1352
    @todo: To silence an error, one should use Internal_error_handler
1353
    mechanism. In future this function will be removed.
1354
  */
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
1355
  inline void clear_error(bool full= false)
1 by brian
clean slate
1356
  {
1357
    if (main_da.is_error())
1358
      main_da.reset_diagnostics_area();
1921.4.1 by Brian Aker
Adding in support for EXECUTE to have WITH NO RETURN.
1359
1360
    if (full)
1361
    {
1362
      drizzle_reset_errors(this, true);
1363
    }
1 by brian
clean slate
1364
  }
383.1.55 by Monty Taylor
Removed libvio deps from drizzled.
1365
1921.4.5 by Brian Aker
Fixing up support so that even when not using a new thread, we can execute
1366
  void clearDiagnostics()
1367
  {
1368
    main_da.reset_diagnostics_area();
1369
  }
1370
1 by brian
clean slate
1371
  /**
1372
    Mark the current error as fatal. Warning: this does not
1373
    set any error, it sets a property of the error, so must be
1374
    followed or prefixed with my_error().
1375
  */
1376
  inline void fatal_error()
1377
  {
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1378
    assert(main_da.is_error());
1055.2.17 by Jay Pipes
More style cleanups in Session
1379
    is_fatal_error= true;
1 by brian
clean slate
1380
  }
1381
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1382
    true if there is an error in the error stack.
1 by brian
clean slate
1383
1384
    Please use this method instead of direct access to
1385
    net.report_error.
1386
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1387
    If true, the current (sub)-statement should be aborted.
1 by brian
clean slate
1388
    The main difference between this member and is_fatal_error
1389
    is that a fatal error can not be handled by a stored
1390
    procedure continue handler, whereas a normal error can.
1391
1392
    To raise this flag, use my_error().
1393
  */
1394
  inline bool is_error() const { return main_da.is_error(); }
748 by Brian Aker
Removal of client side collation.
1395
  inline const CHARSET_INFO *charset() { return default_charset_info; }
1 by brian
clean slate
1396
1397
  void change_item_tree(Item **place, Item *new_value)
1398
  {
1399
    *place= new_value;
1400
  }
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.
1401
  /**
1 by brian
clean slate
1402
    Cleanup statement parse state (parse tree, lex) and execution
1403
    state after execution of a non-prepared SQL statement.
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.
1404
1405
    @todo
1406
1407
    Move this to Statement::~Statement
1 by brian
clean slate
1408
  */
1409
  void end_statement();
1410
  inline int killed_errno() const
1411
  {
1910.2.8 by Brian Aker
Enapsulate Kill.
1412
    killed_state_t killed_val; /* to cache the volatile 'killed' */
1413
    return (killed_val= _killed) != KILL_BAD_DATA ? killed_val : 0;
1 by brian
clean slate
1414
  }
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1415
  void send_kill_message() const;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1416
  /* return true if we will abort query if we make a warning now */
1 by brian
clean slate
1417
  inline bool really_abort_on_warning()
1418
  {
1419
    return (abort_on_warning);
1420
  }
1689.2.26 by Brian Aker
More encapsulation of the thread var.
1421
1422
  void setAbort(bool arg);
1423
  void lockOnSys();
1 by brian
clean slate
1424
  void set_status_var_init();
1425
1426
  /**
1427
    Set the current database; use deep copy of C-string.
1428
1429
    @param new_db     a pointer to the new database name.
1430
    @param new_db_len length of the new database name.
1431
1432
    Initialize the current database from a NULL-terminated string with
1433
    length. If we run out of memory, we free the current database and
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1434
    return true.  This way the user will notice the error as there will be
1 by brian
clean slate
1435
    no current database selected (in addition to the error message set by
1436
    malloc).
1437
1438
    @note This operation just sets {db, db_length}. Switching the current
1439
    database usually involves other actions, like switching other database
1440
    attributes including security context. In the future, this operation
1441
    will be made private and more convenient interface will be provided.
1442
  */
1976.5.2 by Brian Aker
This resolves the issue where one thread may be looking at schema while
1443
  void set_db(const std::string &new_db);
1 by brian
clean slate
1444
1445
  /*
1446
    Copy the current database to the argument. Use the current arena to
1447
    allocate memory for a deep copy: current database may be freed after
1448
    a statement is parsed but before it's executed.
1449
  */
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1450
  bool copy_db_to(char **p_db, size_t *p_db_length);
1 by brian
clean slate
1451
1452
public:
1453
  /**
1454
    Add an internal error handler to the thread execution context.
1455
    @param handler the exception handler to add
1456
  */
1457
  void push_internal_handler(Internal_error_handler *handler);
1458
1459
  /**
1460
    Handle an error condition.
1461
    @param sql_errno the error number
1462
    @param level the error level
1463
    @return true if the error is handled
1464
  */
482 by Brian Aker
Remove uint.
1465
  virtual bool handle_error(uint32_t sql_errno, const char *message,
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
1466
                            DRIZZLE_ERROR::enum_warning_level level);
1 by brian
clean slate
1467
1468
  /**
1469
    Remove the error handler last pushed.
1470
  */
1471
  void pop_internal_handler();
1472
693 by Brian Aker
Cleaning up session class.
1473
  /**
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1474
    Resets Session part responsible for command processing state.
1475
1476
    This needs to be called before execution of every statement
1477
    (prepared or conventional).
1478
    It is not called by substatements of routines.
1479
1480
    @todo
1481
    Make it a method of Session and align its name with the rest of
1482
    reset/end/start/init methods.
1483
    @todo
1484
    Call it after we use Session for queries, not before.
735 by Brian Aker
Refactor session.
1485
  */
1486
  void reset_for_next_command();
1487
1488
  /**
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1489
   * Disconnects the session from a client connection and
1490
   * updates any status variables necessary.
1491
   *
1492
   * @param errcode	Error code to print to console
1493
   *
1494
   * @note  For the connection that is doing shutdown, this is called twice
1495
   */
2054.1.2 by Brian Aker
Rename of the Loooongggggg error type over to simply drizzled::error_t
1496
  void disconnect(enum error_t errcode= EE_OK);
693 by Brian Aker
Cleaning up session class.
1497
934.2.28 by Jay Pipes
Renamed some things to our standards and made private methods private...
1498
  /**
1499
   * Check if user exists and the password supplied is correct.
1500
   *
1501
   * Returns true on success, and false on failure.
1502
   *
1503
   * @note Host, user and passwd may point to communication buffer.
1504
   * Current implementation does not depend on that, but future changes
1505
   * should be done with this in mind; 
1506
   *
1861.6.1 by David Shrewsbury
Add method to undo adding records to a Statement message in case of multi-row statement failure.
1507
   * @param passwd Scrambled password received from client
1508
   * @param db Database name to connect to, may be NULL
934.2.28 by Jay Pipes
Renamed some things to our standards and made private methods private...
1509
   */
1857.4.1 by Monty Taylor
Added string sys_var type.
1510
  bool checkUser(const std::string &passwd, const std::string &db);
1055.3.6 by Jay Pipes
Adds public getConnectMicroseconds() call to Session object. Protects connect_microseconds member variable and sets it correctly. Corrects logging_xxx plugins to use getConnectMicroseconds() API call properly. Fixes Bug #402855
1511
  
1512
  /**
1513
   * Returns the timestamp (in microseconds) of when the Session 
1514
   * connected to the server.
1515
   */
2040.4.5 by Brian Aker
Merge in additional updates for time usage.
1516
  uint64_t getConnectMicroseconds() const
1517
  {
1518
    return (_connect_time - _epoch).total_microseconds();
1519
  }
1520
1521
  uint64_t getConnectSeconds() const
1522
  {
1523
    return (_connect_time - _epoch).total_seconds();
1055.3.6 by Jay Pipes
Adds public getConnectMicroseconds() call to Session object. Protects connect_microseconds member variable and sets it correctly. Corrects logging_xxx plugins to use getConnectMicroseconds() API call properly. Fixes Bug #402855
1524
  }
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
1525
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1526
  /**
1527
   * Returns a pointer to the active Transaction message for this
1528
   * Session being managed by the ReplicationServices component, or
1529
   * NULL if no active message.
1530
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1531
  message::Transaction *getTransactionMessage() const
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1532
  {
1533
    return transaction_message;
1534
  }
1535
1536
  /**
1537
   * Returns a pointer to the active Statement message for this
1538
   * Session, or NULL if no active message.
1539
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1540
  message::Statement *getStatementMessage() const
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1541
  {
1542
    return statement_message;
1543
  }
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
1544
  
1545
  /**
1546
   * Returns a pointer to the current Resulset message for this
1547
   * Session, or NULL if no active message.
1548
   */
1549
  message::Resultset *getResultsetMessage() const
1550
  {
1551
    return resultset;
1552
  }
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1553
  /**
1554
   * Sets the active transaction message used by the ReplicationServices
1555
   * component.
1556
   *
1557
   * @param[in] Pointer to the message
1558
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1559
  void setTransactionMessage(message::Transaction *in_message)
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1560
  {
1561
    transaction_message= in_message;
1562
  }
1563
1564
  /**
1565
   * Sets the active statement message used by the ReplicationServices
1566
   * component.
1567
   *
1568
   * @param[in] Pointer to the message
1569
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1570
  void setStatementMessage(message::Statement *in_message)
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1571
  {
1572
    statement_message= in_message;
1573
  }
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
1574
1575
  /**
1576
   * Sets the active Resultset message used by the Query Cache
1577
   * plugin.
1578
   *
1579
   * @param[in] Pointer to the message
1580
   */
1581
  void setResultsetMessage(message::Resultset *in_message)
1582
  {
1583
    resultset= in_message;
1584
  }
1643.6.16 by Djellel E. Difallah
Fixing memory leaks
1585
  /**
1586
   * reset the active Resultset message used by the Query Cache
1587
   * plugin.
1588
   */
1589
1590
  void resetResultsetMessage()
1591
  { 
1592
    resultset= NULL;
1593
  }
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
1594
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
1595
private:
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1596
  /** Pointers to memory managed by the ReplicationServices component */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1597
  message::Transaction *transaction_message;
1598
  message::Statement *statement_message;
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
1599
  /* Pointer to the current resultset of Select query */
1600
  message::Resultset *resultset;
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1601
  plugin::EventObserverList *session_event_observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1602
  
1603
  /* Schema observers are mapped to databases. */
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1604
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1605
1606
 
1607
public:
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1608
  plugin::EventObserverList *getSessionObservers() 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1609
  { 
1610
    return session_event_observers;
1611
  }
1612
  
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1613
  void setSessionObservers(plugin::EventObserverList *observers) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1614
  { 
1615
    session_event_observers= observers;
1616
  }
1617
  
1618
  /* For schema event observers there is one set of observers per database. */
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1619
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1620
  { 
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1621
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1622
    
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.
1623
    it= schema_event_observers.find(db_name);
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1624
    if (it == schema_event_observers.end())
1625
      return NULL;
1626
      
1627
    return it->second;
1628
  }
1629
  
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1630
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1631
  { 
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1632
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1633
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.
1634
    it= schema_event_observers.find(db_name);
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1635
    if (it != schema_event_observers.end())
1636
      schema_event_observers.erase(it);;
1637
1638
    if (observers)
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.
1639
      schema_event_observers[db_name] = observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1640
  }
1641
  
1642
  
1643
 private:
322.2.2 by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter.
1644
  const char *proc_info;
1645
1 by brian
clean slate
1646
  /** The current internal error handler for this thread, or NULL. */
1647
  Internal_error_handler *m_internal_handler;
1648
  /**
1649
    The lex to hold the parsed tree of conventional (non-prepared) queries.
1650
    Whereas for prepared and stored procedure statements we use an own lex
1651
    instance for each new query, for conventional statements we reuse
1652
    the same lex. (@see mysql_parse for details).
1653
  */
1654
  LEX main_lex;
1655
  /**
1656
    This memory root is used for two purposes:
1657
    - for conventional queries, to allocate structures stored in main_lex
1658
    during parsing, and allocate runtime data (execution plan, etc.)
1659
    during execution.
1660
    - for prepared queries, only to allocate runtime data. The parsed
1661
    tree itself is reused between executions and thus is stored elsewhere.
1662
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1663
  memory::Root main_mem_root;
836 by Brian Aker
Fixed session call from function to method.
1664
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1665
  /**
1666
   * Marks all tables in the list which were used by current substatement
1667
   * as free for reuse.
1668
   *
1669
   * @param Head of the list of tables
1670
   *
1671
   * @note
1672
   *
1673
   * The reason we reset query_id is that it's not enough to just test
1674
   * if table->query_id != session->query_id to know if a table is in use.
1675
   *
1676
   * For example
1677
   * 
1678
   *  SELECT f1_that_uses_t1() FROM t1;
1679
   *  
1680
   * In f1_that_uses_t1() we will see one instance of t1 where query_id is
1681
   * set to query_id of original query.
1682
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1683
  void mark_used_tables_as_free_for_reuse(Table *table);
1684
836 by Brian Aker
Fixed session call from function to method.
1685
public:
1046.1.4 by Brian Aker
Move lazy read of refresh to outside of LOCK_open (we don't lock the refresh
1686
836 by Brian Aker
Fixed session call from function to method.
1687
  /** A short cut for session->main_da.set_ok_status(). */
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
1688
  inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1689
                    uint64_t passed_id= 0, const char *message= NULL)
836 by Brian Aker
Fixed session call from function to method.
1690
  {
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
1691
    main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
836 by Brian Aker
Fixed session call from function to method.
1692
  }
1693
1694
1695
  /** A short cut for session->main_da.set_eof_status(). */
1696
1697
  inline void my_eof()
1698
  {
1699
    main_da.set_eof_status(this);
1700
  }
838 by Brian Aker
More class adoption/method
1701
1702
  /* Some inline functions for more speed */
1703
1704
  inline bool add_item_to_list(Item *item)
1705
  {
1706
    return lex->current_select->add_item_to_list(this, item);
1707
  }
1708
1709
  inline bool add_value_to_list(Item *value)
1710
  {
1711
    return lex->value_list.push_back(value);
1712
  }
1713
1714
  inline bool add_order_to_list(Item *item, bool asc)
1715
  {
1716
    return lex->current_select->add_order_to_list(this, item, asc);
1717
  }
1718
1719
  inline bool add_group_to_list(Item *item, bool asc)
1720
  {
1721
    return lex->current_select->add_group_to_list(this, item, asc);
1722
  }
855 by Brian Aker
Refactor reset of status.
1723
  void refresh_status();
995 by Brian Aker
Refactor get_variable to session
1724
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1836.4.1 by Brian Aker
Adding in more test case for events (though these do not really have the
1725
  user_var_entry *getVariable(const std::string  &name, bool create_if_not_exists);
1726
  void setVariable(const std::string &name, const std::string &value);
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1727
  
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1728
  /**
1729
   * Closes all tables used by the current substatement, or all tables
1730
   * used by this thread if we are on the upper level.
1731
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1732
  void close_thread_tables();
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1733
  void close_old_data_files(bool morph_locks= false,
1734
                            bool send_refresh= false);
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1735
  void close_open_tables();
1954.2.3 by Brian Aker
Update tableidentifier so that it is const in many callers.
1736
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1737
1738
private:
1739
  bool free_cached_table();
1740
public:
1741
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1742
  /**
1743
   * Prepares statement for reopening of tables and recalculation of set of
1744
   * prelocked tables.
1745
   *
1746
   * @param Pointer to a pointer to a list of tables which we were trying to open and lock
1747
   */
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1748
  void close_tables_for_reopen(TableList **tables);
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1749
1750
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1751
  /**
1752
   * Open all tables in list, locks them (all, including derived)
1753
   *
1754
   * @param Pointer to a list of tables for open & locking
1755
   *
1756
   * @retval
1757
   *  false - ok
1758
   * @retval
1759
   *  true  - error
1760
   *
1761
   * @note
1762
   * 
1763
   * The lock will automaticaly be freed by close_thread_tables()
1764
   */
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1765
  bool openTablesLock(TableList *tables);
1109.1.2 by Brian Aker
More from the table patch
1766
1767
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1768
1769
  Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1770
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1771
1054.1.11 by Brian Aker
Remove dead lock.cc commands.
1772
  void unlink_open_table(Table *find);
1954.2.3 by Brian Aker
Update tableidentifier so that it is const in many callers.
1773
  void drop_open_table(Table *table, const TableIdentifier &identifier);
1054.1.11 by Brian Aker
Remove dead lock.cc commands.
1774
  void close_cached_table(Table *table);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1775
1776
  /* Create a lock in the cache */
1877.2.1 by Brian Aker
Refactor table_cache_insert_placeholder.
1777
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1954.2.3 by Brian Aker
Update tableidentifier so that it is const in many callers.
1778
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1779
1689.3.5 by Brian Aker
Do a case insensitive search for path.
1780
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1923.1.4 by Brian Aker
Encapsulate up the cache we use in Session for tracking table proto for temp
1781
1782
  class TableMessages
1783
  {
1784
    TableMessageCache table_message_cache;
1785
1786
  public:
1787
    bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1788
    bool removeTableMessage(const TableIdentifier &identifier);
1789
    bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1790
    bool doesTableMessageExist(const TableIdentifier &identifier);
1791
    bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1792
1793
  };
1794
private:
1795
  TableMessages _table_message_cache;
1796
1797
public:
1798
  TableMessages &getMessageCache()
1799
  {
1800
    return _table_message_cache;
1801
  }
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1802
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1803
  /* Reopen operations */
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1804
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1109.1.4 by Brian Aker
More Table refactor
1805
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1054.1.10 by Brian Aker
Move open_table() to session.
1806
1812.3.5 by Brian Aker
Move to boost condition_any
1807
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1109.1.5 by Brian Aker
More extraction from sql_base
1808
  int setup_conds(TableList *leaves, COND **conds);
1809
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1810
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
1811
  drizzled::util::Storable *getProperty(const std::string &arg)
1812
  {
1813
    return life_properties[arg];
1814
  }
1815
1816
  template<class T>
1817
  bool setProperty(const std::string &arg, T *value)
1818
  {
1819
    life_properties[arg]= value;
1820
1821
    return true;
1822
  }
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1823
1824
  /**
1825
    Return the default storage engine
1826
1827
    @param getDefaultStorageEngine()
1828
1829
    @return
1830
    pointer to plugin::StorageEngine
1831
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1832
  plugin::StorageEngine *getDefaultStorageEngine()
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1833
  {
1834
    if (variables.storage_engine)
1835
      return variables.storage_engine;
1836
    return global_system_variables.storage_engine;
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
1837
  }
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
1838
1490 by Brian Aker
Updates to remove a fe bits of dead code around C support for plugins
1839
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1840
1843.8.5 by Brian Aker
Added concurrent type.
1841
  table::Instance *getInstanceTable();
1878.5.1 by Brian Aker
Update instance for handling construction of virtual_tmp
1842
  table::Instance *getInstanceTable(List<CreateField> &field_list);
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
1843
1844
private:
1845
  bool resetUsage()
1846
  {
1847
    if (getrusage(RUSAGE_THREAD, &usage))
1848
    {
1849
      return false;
1850
    }
1851
1852
    return true;
1853
  }
1854
public:
1855
1856
  void setUsage(bool arg)
1857
  {
1858
    use_usage= arg;
1859
  }
1860
1861
  const struct rusage &getUsage()
1862
  {
1863
    return usage;
1864
  }
1865
1866
private:
1867
  // This lives throughout the life of Session
1868
  bool use_usage;
1869
  PropertyMap life_properties;
1843.8.4 by Brian Aker
Committing refactor of table out (this is part of the concurrency work).
1870
  std::vector<table::Instance *> temporary_shares;
1764.3.6 by Brian Aker
This includes a query_usage table for looking at performance of previous
1871
  struct rusage usage;
1 by brian
clean slate
1872
};
1873
1541.1.1 by Brian Aker
JOIN -> Join rename
1874
class Join;
1 by brian
clean slate
1875
1876
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1877
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1878
} /* namespace drizzled */
1879
1880
/** @TODO why is this in the middle of the file */
850 by Brian Aker
More class creation.
1881
#include <drizzled/select_to_file.h>
1882
#include <drizzled/select_export.h>
1883
#include <drizzled/select_dump.h>
1884
#include <drizzled/select_insert.h>
1885
#include <drizzled/select_create.h>
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1886
#include <drizzled/tmp_table_param.h>
1887
#include <drizzled/select_union.h>
1888
#include <drizzled/select_subselect.h>
1889
#include <drizzled/select_singlerow_subselect.h>
1890
#include <drizzled/select_max_min_finder_subselect.h>
1891
#include <drizzled/select_exists_subselect.h>
1 by brian
clean slate
1892
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1893
namespace drizzled
1894
{
1895
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.
1896
/**
1897
 * A structure used to describe sort information
1898
 * for a field or item used in ORDER BY.
1899
 */
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
1900
class SortField 
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.
1901
{
1891.2.1 by Monty Taylor
Fixed things to make things compile with clang
1902
public:
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.
1903
  Field *field;	/**< Field to sort */
1904
  Item	*item; /**< Item if not sorting fields */
1905
  size_t length; /**< Length of sort field */
1906
  uint32_t suffix_length; /**< Length suffix (0-4) */
1907
  Item_result result_type; /**< Type of item */
1908
  bool reverse; /**< if descending sort */
1909
  bool need_strxnfrm;	/**< If we have to use strxnfrm() */
1711.6.1 by Brian Aker
Style on structure cleanup
1910
1911
  SortField() :
1912
    field(0),
1913
    item(0),
1914
    length(0),
1915
    suffix_length(0),
1916
    result_type(STRING_RESULT),
1917
    reverse(0),
1918
    need_strxnfrm(0)
1919
  { }
1920
1921
};
1 by brian
clean slate
1922
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1923
} /* namespace drizzled */
1924
1925
/** @TODO why is this in the middle of the file */
1926
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1927
#include <drizzled/table_ident.h>
1928
#include <drizzled/user_var_entry.h>
1929
#include <drizzled/unique.h>
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1930
#include <drizzled/var.h>
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1931
#include <drizzled/select_dumpvar.h>
1 by brian
clean slate
1932
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1933
namespace drizzled
1934
{
1935
1 by brian
clean slate
1936
/* Bits in sql_command_flags */
1937
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.
1938
enum sql_command_flag_bits 
1939
{
590.2.17 by Monty Taylor
Changed CF_BIT_* to an enum.
1940
  CF_BIT_CHANGES_DATA,
1941
  CF_BIT_HAS_ROW_COUNT,
1942
  CF_BIT_STATUS_COMMAND,
1943
  CF_BIT_SHOW_TABLE_COMMAND,
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
1944
  CF_BIT_WRITE_LOGS_COMMAND,
1945
  CF_BIT_SIZE
590.2.17 by Monty Taylor
Changed CF_BIT_* to an enum.
1946
};
602.2.2 by Yoshinori Sano
Fix bugs in params of sql_command_flags[...].test(). Previously, the value such as, 0, 1, 2, 4, 8 and 16 is given to std::bitset.test() in that place, which is misunderstanding of the spec of the test(). The test(size_t n) returns true if bit n is set.
1947
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
1948
static const std::bitset<CF_BIT_SIZE> CF_CHANGES_DATA(1 << CF_BIT_CHANGES_DATA);
1949
static const std::bitset<CF_BIT_SIZE> CF_HAS_ROW_COUNT(1 << CF_BIT_HAS_ROW_COUNT);
1950
static const std::bitset<CF_BIT_SIZE> CF_STATUS_COMMAND(1 << CF_BIT_STATUS_COMMAND);
1951
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1952
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1 by brian
clean slate
1953
1948.2.6 by Brian Aker
Added function global_read_lock(), this way a session can know if it has
1954
namespace display  {
1955
const std::string &type(drizzled::Session::global_read_lock_t type);
1956
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1957
} /* namespace display */
1958
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1959
} /* namespace drizzled */
1960
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
1961
#endif /* DRIZZLED_SESSION_H */