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