~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2011-01-13 06:00:40 UTC
  • mfrom: (2069.4.6 clean)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: brian@gir-3-20110113060040-fz7r6c7t39mwt9tz
Merge in change to POTFILES

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
20
21
#ifndef DRIZZLED_SESSION_H
21
22
#define DRIZZLED_SESSION_H
22
23
 
 
24
#include "drizzled/plugin.h"
 
25
#include "drizzled/sql_locale.h"
 
26
#include "drizzled/resource_context.h"
 
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"
 
34
#include "drizzled/query_id.h"
 
35
#include "drizzled/named_savepoint.h"
 
36
#include "drizzled/transaction_context.h"
 
37
#include "drizzled/util/storable.h"
 
38
#include "drizzled/my_hash.h"
 
39
#include "drizzled/pthread_globals.h"
 
40
#include <netdb.h>
 
41
#include <sys/time.h>
 
42
#include <sys/resource.h>
 
43
 
23
44
#include <algorithm>
24
45
#include <bitset>
25
 
#include <boost/make_shared.hpp>
26
 
#include <boost/thread/condition_variable.hpp>
 
46
#include <deque>
 
47
#include <map>
 
48
#include <string>
 
49
 
 
50
#include "drizzled/identifier.h"
 
51
#include "drizzled/open_tables_state.h"
 
52
#include "drizzled/internal_error_handler.h"
 
53
#include "drizzled/diagnostics_area.h"
 
54
#include "drizzled/plugin/authorization.h"
 
55
 
 
56
#include "drizzled/catalog/instance.h"
 
57
#include "drizzled/catalog/local.h"
 
58
 
 
59
#include <boost/unordered_map.hpp>
 
60
 
 
61
#include <boost/thread/thread.hpp>
27
62
#include <boost/thread/mutex.hpp>
28
63
#include <boost/thread/shared_mutex.hpp>
29
 
#include <boost/thread/thread.hpp>
30
 
#include <map>
31
 
#include <netdb.h>
32
 
#include <string>
33
 
#include <sys/resource.h>
34
 
#include <sys/time.h>
 
64
#include <boost/thread/condition_variable.hpp>
 
65
#include <boost/make_shared.hpp>
35
66
 
36
 
#include <drizzled/catalog/instance.h>
37
 
#include <drizzled/catalog/local.h>
38
 
#include <drizzled/copy_info.h>
39
 
#include <drizzled/cursor.h>
40
 
#include <drizzled/diagnostics_area.h>
41
 
#include <drizzled/file_exchange.h>
42
 
#include <drizzled/ha_data.h>
43
 
#include <drizzled/identifier.h>
44
 
#include <drizzled/lex_column.h>
45
 
#include <drizzled/my_hash.h>
46
 
#include <drizzled/named_savepoint.h>
47
 
#include <drizzled/open_tables_state.h>
48
 
#include <drizzled/plugin.h>
49
 
#include <drizzled/plugin/authorization.h>
50
 
#include <drizzled/pthread_globals.h>
51
 
#include <drizzled/query_id.h>
52
 
#include <drizzled/resource_context.h>
53
 
#include <drizzled/session/property_map.h>
54
 
#include <drizzled/session/state.h>
55
 
#include <drizzled/session/table_messages.h>
56
 
#include <drizzled/session/transactions.h>
57
 
#include <drizzled/sql_error.h>
58
 
#include <drizzled/sql_lex.h>
59
 
#include <drizzled/sql_locale.h>
60
 
#include <drizzled/statistics_variables.h>
61
 
#include <drizzled/system_variables.h>
62
 
#include <drizzled/system_variables.h>
63
 
#include <drizzled/table_ident.h>
64
 
#include <drizzled/transaction_context.h>
65
 
#include <drizzled/util/storable.h>
66
 
#include <drizzled/var.h>
67
 
#include <drizzled/visibility.h>
68
67
 
69
68
#define MIN_HANDSHAKE_SIZE      6
70
69
 
85
84
class Resultset;
86
85
}
87
86
 
88
 
namespace internal { struct st_my_thread_var; }
89
 
namespace table { class Placeholder; }
90
 
 
 
87
namespace internal
 
88
{
 
89
struct st_my_thread_var;
 
90
}
 
91
 
 
92
namespace table
 
93
{
 
94
class Placeholder;
 
95
}
 
96
 
 
97
class Lex_input_stream;
 
98
class user_var_entry;
91
99
class CopyField;
92
 
class DrizzleXid;
93
 
class Internal_error_handler;
94
 
class Lex_input_stream;
 
100
class Table_ident;
 
101
 
95
102
class TableShareInstance;
96
 
class Table_ident;
97
 
class Time_zone;
98
 
class select_result;
99
 
class user_var_entry;
100
103
 
101
104
extern char internal_table_name[2];
102
105
extern char empty_c_string[1];
106
109
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
107
110
extern uint32_t tc_heuristic_recover;
108
111
 
 
112
/**
 
113
  @brief
 
114
  Local storage for proto that are tmp table. This should be enlarged
 
115
  to hande the entire table-share for a local table. Once Hash is done,
 
116
  we should consider exchanging the map for it.
 
117
*/
 
118
typedef std::map <std::string, message::Table> ProtoCache;
 
119
 
 
120
/**
 
121
  The COPY_INFO structure is used by INSERT/REPLACE code.
 
122
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
 
123
  UPDATE code:
 
124
    If a row is inserted then the copied variable is incremented.
 
125
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
 
126
      new data differs from the old one then the copied and the updated
 
127
      variables are incremented.
 
128
    The touched variable is incremented if a row was touched by the update part
 
129
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
 
130
      was actually changed or not.
 
131
*/
 
132
class CopyInfo 
 
133
{
 
134
public:
 
135
  ha_rows records; /**< Number of processed records */
 
136
  ha_rows deleted; /**< Number of deleted records */
 
137
  ha_rows updated; /**< Number of updated records */
 
138
  ha_rows copied;  /**< Number of copied records */
 
139
  ha_rows error_count;
 
140
  ha_rows touched; /* Number of touched records */
 
141
  enum enum_duplicates handle_duplicates;
 
142
  int escape_char, last_errno;
 
143
  bool ignore;
 
144
  /* for INSERT ... UPDATE */
 
145
  List<Item> *update_fields;
 
146
  List<Item> *update_values;
 
147
  /* for VIEW ... WITH CHECK OPTION */
 
148
 
 
149
  CopyInfo() :
 
150
    records(0),
 
151
    deleted(0),
 
152
    updated(0),
 
153
    copied(0),
 
154
    error_count(0),
 
155
    touched(0),
 
156
    escape_char(0),
 
157
    last_errno(0),
 
158
    ignore(0),
 
159
    update_fields(0),
 
160
    update_values(0)
 
161
  { }
 
162
 
 
163
};
 
164
 
 
165
} /* namespace drizzled */
 
166
 
 
167
/** @TODO why is this in the middle of the file */
 
168
#include <drizzled/lex_column.h>
 
169
 
 
170
namespace drizzled
 
171
{
 
172
 
 
173
class select_result;
 
174
class Time_zone;
 
175
 
109
176
#define Session_SENTRY_MAGIC 0xfeedd1ff
110
177
#define Session_SENTRY_GONE  0xdeadbeef
111
178
 
112
 
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
 
179
struct drizzle_system_variables
 
180
{
 
181
  drizzle_system_variables()
 
182
  {}
 
183
  /*
 
184
    How dynamically allocated system variables are handled:
 
185
 
 
186
    The global_system_variables and max_system_variables are "authoritative"
 
187
    They both should have the same 'version' and 'size'.
 
188
    When attempting to access a dynamic variable, if the session version
 
189
    is out of date, then the session version is updated and realloced if
 
190
    neccessary and bytes copied from global to make up for missing data.
 
191
  */
 
192
  ulong dynamic_variables_version;
 
193
  char * dynamic_variables_ptr;
 
194
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
 
195
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
 
196
 
 
197
  uint64_t myisam_max_extra_sort_file_size;
 
198
  uint64_t max_heap_table_size;
 
199
  uint64_t tmp_table_size;
 
200
  ha_rows select_limit;
 
201
  ha_rows max_join_size;
 
202
  uint64_t auto_increment_increment;
 
203
  uint64_t auto_increment_offset;
 
204
  uint64_t bulk_insert_buff_size;
 
205
  uint64_t join_buff_size;
 
206
  uint32_t max_allowed_packet;
 
207
  uint64_t max_error_count;
 
208
  uint64_t max_length_for_sort_data;
 
209
  size_t max_sort_length;
 
210
  uint64_t min_examined_row_limit;
 
211
  bool optimizer_prune_level;
 
212
  bool log_warnings;
 
213
 
 
214
  uint32_t optimizer_search_depth;
 
215
  uint32_t div_precincrement;
 
216
  uint64_t preload_buff_size;
 
217
  uint32_t read_buff_size;
 
218
  uint32_t read_rnd_buff_size;
 
219
  bool replicate_query;
 
220
  size_t sortbuff_size;
 
221
  uint32_t thread_handling;
 
222
  uint32_t tx_isolation;
 
223
  size_t transaction_message_threshold;
 
224
  uint32_t completion_type;
 
225
  /* Determines which non-standard SQL behaviour should be enabled */
 
226
  uint32_t sql_mode;
 
227
  uint64_t max_seeks_for_key;
 
228
  size_t range_alloc_block_size;
 
229
  uint32_t query_alloc_block_size;
 
230
  uint32_t query_prealloc_size;
 
231
  uint64_t group_concat_max_len;
 
232
  uint64_t pseudo_thread_id;
 
233
 
 
234
  plugin::StorageEngine *storage_engine;
 
235
 
 
236
  /* Only charset part of these variables is sensible */
 
237
  const CHARSET_INFO  *character_set_filesystem;
 
238
 
 
239
  /* Both charset and collation parts of these variables are important */
 
240
  const CHARSET_INFO    *collation_server;
 
241
 
 
242
  inline const CHARSET_INFO  *getCollation(void) 
 
243
  {
 
244
    return collation_server;
 
245
  }
 
246
 
 
247
  /* Locale Support */
 
248
  MY_LOCALE *lc_time_names;
 
249
 
 
250
  Time_zone *time_zone;
 
251
};
 
252
 
 
253
extern struct drizzle_system_variables global_system_variables;
 
254
 
 
255
} /* namespace drizzled */
 
256
 
 
257
#include "drizzled/sql_lex.h"
 
258
 
 
259
namespace drizzled
 
260
{
 
261
 
 
262
void mark_transaction_to_rollback(Session *session, bool all);
 
263
 
 
264
/**
 
265
  Storage engine specific thread local data.
 
266
*/
 
267
struct Ha_data
 
268
{
 
269
  /**
 
270
    Storage engine specific thread local data.
 
271
    Lifetime: one user connection.
 
272
  */
 
273
  void *ha_ptr;
 
274
  /**
 
275
   * Resource contexts for both the "statement" and "normal"
 
276
   * transactions.
 
277
   *
 
278
   * Resource context at index 0:
 
279
   *
 
280
   * Life time: one statement within a transaction. If @@autocommit is
 
281
   * on, also represents the entire transaction.
 
282
   *
 
283
   * Resource context at index 1:
 
284
   *
 
285
   * Life time: one transaction within a connection. 
 
286
   *
 
287
   * @note
 
288
   *
 
289
   * If the storage engine does not participate in a transaction, 
 
290
   * there will not be a resource context.
 
291
   */
 
292
  drizzled::ResourceContext resource_context[2];
 
293
 
 
294
  Ha_data() :ha_ptr(NULL) {}
 
295
};
113
296
 
114
297
/**
115
298
 * Represents a client connection to the database server.
131
314
 * session object.
132
315
 */
133
316
 
134
 
class DRIZZLED_API Session : public Open_tables_state
 
317
class Session : public Open_tables_state
135
318
{
136
319
public:
137
320
  // Plugin storage in Session.
 
321
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
 
322
  typedef Session* Ptr;
138
323
  typedef boost::shared_ptr<Session> shared_ptr;
139
324
  typedef Session& reference;
140
325
  typedef const Session& const_reference;
159
344
                        and update_row.
160
345
  */
161
346
  enum enum_mark_columns mark_used_columns;
 
347
  inline void* alloc(size_t size)
 
348
  {
 
349
    return mem_root->alloc_root(size);
 
350
  }
162
351
  inline void* calloc(size_t size)
163
352
  {
164
353
    void *ptr;
166
355
      memset(ptr, 0, size);
167
356
    return ptr;
168
357
  }
 
358
  inline char *strdup(const char *str)
 
359
  {
 
360
    return mem_root->strdup_root(str);
 
361
  }
169
362
  inline char *strmake(const char *str, size_t size)
170
363
  {
171
364
    return mem_root->strmake_root(str,size);
172
365
  }
173
 
 
 
366
  inline void *memdup(const void *str, size_t size)
 
367
  {
 
368
    return mem_root->memdup_root(str, size);
 
369
  }
174
370
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
175
371
  {
176
372
    void *ptr;
180
376
  }
181
377
  /** Frees all items attached to this Statement */
182
378
  void free_items();
183
 
 
184
379
  /**
185
380
   * List of items created in the parser for this query. Every item puts
186
381
   * itself to the list on creation (see Item::Item() for details))
213
408
   * @todo should be const
214
409
   */
215
410
  uint32_t id;
216
 
private:
217
411
  LEX *lex; /**< parse tree descriptor */
218
412
 
219
 
public:
220
413
  LEX *getLex() 
221
414
  {
222
415
    return lex;
223
416
  }
224
 
 
225
 
  enum_sql_command getSqlCommand() const
226
 
  {
227
 
    return lex->sql_command;
228
 
  }
229
 
 
230
417
  /** query associated with this statement */
231
418
  typedef boost::shared_ptr<const std::string> QueryString;
232
 
 
233
419
private:
234
420
  boost::shared_ptr<std::string> query;
235
421
 
268
454
    return to_return;
269
455
  }
270
456
 
 
457
  class State {
 
458
    std::vector <char> _query;
 
459
 
 
460
  public:
 
461
    typedef boost::shared_ptr<State> const_shared_ptr;
 
462
 
 
463
    State(const char *in_packet, size_t in_packet_length)
 
464
    {
 
465
      if (in_packet_length)
 
466
      {
 
467
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
 
468
        _query.resize(minimum + 1);
 
469
        memcpy(&_query[0], in_packet, minimum);
 
470
      }
 
471
      else
 
472
      {
 
473
        _query.resize(0);
 
474
      }
 
475
    }
 
476
 
 
477
    const char *query() const
 
478
    {
 
479
      if (_query.size())
 
480
        return &_query[0];
 
481
 
 
482
      return "";
 
483
    }
 
484
 
 
485
    const char *query(size_t &size) const
 
486
    {
 
487
      if (_query.size())
 
488
      {
 
489
        size= _query.size() -1;
 
490
        return &_query[0];
 
491
      }
 
492
 
 
493
      size= 0;
 
494
      return "";
 
495
    }
 
496
  protected:
 
497
    friend class Session;
 
498
    typedef boost::shared_ptr<State> shared_ptr;
 
499
  };
271
500
private:
272
 
  session::State::shared_ptr  _state; 
273
 
 
 
501
  State::shared_ptr  _state; 
274
502
public:
275
503
 
276
 
  session::State::const_shared_ptr state()
 
504
  State::const_shared_ptr state()
277
505
  {
278
506
    return _state;
279
507
  }
292
520
  */
293
521
private:
294
522
  util::string::shared_ptr _schema;
295
 
 
296
523
public:
297
524
 
298
525
  util::string::const_shared_ptr schema() const
326
553
    return client;
327
554
  }
328
555
 
329
 
  plugin::Client *getClient() const
330
 
  {
331
 
    return client;
332
 
  }
333
 
 
334
556
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
335
557
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
336
558
 
337
559
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
338
 
 
339
560
private:
340
561
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
341
562
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
342
563
 
343
564
public:
 
565
 
344
566
  const UserVars &getUserVariables() const
345
567
  {
346
568
    return user_vars;
347
569
  }
348
570
 
349
571
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
350
 
 
351
 
  enum_tx_isolation getTxIsolation()
352
 
  {
353
 
    return (enum_tx_isolation)variables.tx_isolation;
354
 
  }
355
 
 
356
572
  struct system_status_var status_var; /**< Session-local status counters */
357
573
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
358
574
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
373
589
  {
374
590
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
375
591
  }
376
 
 
377
592
public:
378
593
  identifier::User::const_shared_ptr user() const
379
594
  {
403
618
   */
404
619
  bool isViewable(identifier::User::const_reference) const;
405
620
 
406
 
private:
407
621
  /**
408
622
    Used in error messages to tell user in what part of MySQL we found an
409
623
    error. E. g. when where= "having clause", if fix_fields() fails, user
410
624
    will know that the error was in having clause.
411
625
  */
412
 
  const char *_where;
413
 
 
414
 
public:
415
 
  const char *where()
416
 
  {
417
 
    return _where;
418
 
  }
419
 
 
420
 
  void setWhere(const char *arg)
421
 
  {
422
 
    _where= arg;
423
 
  }
 
626
  const char *where;
424
627
 
425
628
  /*
426
629
    One thread can hold up to one named user-level lock. This variable
428
631
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
429
632
  */
430
633
  uint32_t dbug_sentry; /**< watch for memory corruption */
431
 
 
432
634
private:
433
635
  boost::thread::id boost_thread_id;
434
636
  boost_thread_shared_ptr _thread;
435
637
  boost::this_thread::disable_interruption *interrupt;
436
638
 
437
639
  internal::st_my_thread_var *mysys_var;
 
640
public:
438
641
 
439
 
public:
440
642
  boost_thread_shared_ptr &getThread()
441
643
  {
442
644
    return _thread;
517
719
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
518
720
                                      size_t index= 0);
519
721
 
520
 
  session::Transactions transaction;
 
722
  /**
 
723
   * Structure used to manage "statement transactions" and
 
724
   * "normal transactions". In autocommit mode, the normal transaction is
 
725
   * equivalent to the statement transaction.
 
726
   *
 
727
   * Storage engines will be registered here when they participate in
 
728
   * a transaction. No engine is registered more than once.
 
729
   */
 
730
  struct st_transactions {
 
731
    std::deque<NamedSavepoint> savepoints;
 
732
 
 
733
    /**
 
734
     * The normal transaction (since BEGIN WORK).
 
735
     *
 
736
     * Contains a list of all engines that have participated in any of the
 
737
     * statement transactions started within the context of the normal
 
738
     * transaction.
 
739
     *
 
740
     * @note In autocommit mode, this is empty.
 
741
     */
 
742
    TransactionContext all;
 
743
 
 
744
    /**
 
745
     * The statment transaction.
 
746
     *
 
747
     * Contains a list of all engines participating in the given statement.
 
748
     *
 
749
     * @note In autocommit mode, this will be used to commit/rollback the
 
750
     * normal transaction.
 
751
     */
 
752
    TransactionContext stmt;
 
753
 
 
754
    XID_STATE xid_state;
 
755
 
 
756
    void cleanup()
 
757
    {
 
758
      savepoints.clear();
 
759
    }
 
760
    st_transactions() :
 
761
      savepoints(),
 
762
      all(),
 
763
      stmt(),
 
764
      xid_state()
 
765
    { }
 
766
  } transaction;
521
767
 
522
768
  Field *dup_field;
523
769
  sigset_t signals;
525
771
  // As of right now we do not allow a concurrent execute to launch itself
526
772
private:
527
773
  bool concurrent_execute_allowed;
528
 
 
529
774
public:
530
775
 
531
776
  void setConcurrentExecute(bool arg)
594
839
  uint64_t limit_found_rows;
595
840
  uint64_t options; /**< Bitmap of options */
596
841
  int64_t row_count_func; /**< For the ROW_COUNT() function */
597
 
 
598
 
  int64_t rowCount() const
599
 
  {
600
 
    return row_count_func;
601
 
  }
602
 
 
603
842
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
604
843
 
605
844
  /** 
770
1009
  bool substitute_null_with_insert_id;
771
1010
  bool cleanup_done;
772
1011
 
773
 
private:
774
1012
  bool abort_on_warning;
775
 
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
776
 
 
777
 
public:
778
1013
  bool got_warning; /**< Set on call to push_warning() */
779
1014
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
780
1015
  /** set during loop of derived table processing */
781
1016
  bool derived_tables_processing;
782
 
 
783
 
  bool doing_tablespace_operation(void)
784
 
  {
785
 
    return tablespace_op;
786
 
  }
787
 
 
788
 
  void setDoingTablespaceOperation(bool doing)
789
 
  {
790
 
    tablespace_op= doing;
791
 
  }
792
 
 
 
1017
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
793
1018
 
794
1019
  /** Used by the sys_var class to store temporary values */
795
1020
  union
1014
1239
  bool endTransaction(enum enum_mysql_completiontype completion);
1015
1240
  bool endActiveTransaction();
1016
1241
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
1017
 
  void markTransactionForRollback(bool all);
1018
1242
 
1019
1243
  /**
1020
1244
   * Authenticates users, with error reporting.
1046
1270
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1047
1271
  void exit_cond(const char* old_msg);
1048
1272
 
1049
 
  type::Time::epoch_t query_start()
 
1273
  time_t query_start()
1050
1274
  {
1051
1275
    return getCurrentTimestampEpoch();
1052
1276
  }
1082
1306
  /**
1083
1307
   * Returns the current micro-timestamp
1084
1308
   */
1085
 
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
 
1309
  uint64_t getCurrentTimestamp(bool actual= true) const
1086
1310
  { 
1087
 
    type::Time::epoch_t t_mark;
 
1311
    uint64_t t_mark;
1088
1312
 
1089
1313
    if (actual)
1090
1314
    {
1100
1324
  }
1101
1325
 
1102
1326
  // We may need to set user on this
1103
 
  type::Time::epoch_t getCurrentTimestampEpoch() const
 
1327
  time_t getCurrentTimestampEpoch() const
1104
1328
  { 
1105
1329
    if (not _user_time.is_not_a_date_time())
1106
1330
      return (_user_time - _epoch).total_seconds();
1108
1332
    return (_start_timer - _epoch).total_seconds();
1109
1333
  }
1110
1334
 
1111
 
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
 
1335
  time_t getCurrentTimestampEpoch(uint32_t &fraction_arg) const
1112
1336
  { 
1113
1337
    if (not _user_time.is_not_a_date_time())
1114
1338
    {
1210
1434
  }
1211
1435
  void send_kill_message() const;
1212
1436
  /* return true if we will abort query if we make a warning now */
1213
 
  inline bool abortOnWarning()
1214
 
  {
1215
 
    return abort_on_warning;
1216
 
  }
1217
 
 
1218
 
  inline void setAbortOnWarning(bool arg)
1219
 
  {
1220
 
    abort_on_warning= arg;
 
1437
  inline bool really_abort_on_warning()
 
1438
  {
 
1439
    return (abort_on_warning);
1221
1440
  }
1222
1441
 
1223
1442
  void setAbort(bool arg);
1263
1482
    @param level the error level
1264
1483
    @return true if the error is handled
1265
1484
  */
1266
 
  virtual bool handle_error(drizzled::error_t sql_errno, const char *message,
 
1485
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1267
1486
                            DRIZZLE_ERROR::enum_warning_level level);
1268
1487
 
1269
1488
  /**
1534
1753
  void close_old_data_files(bool morph_locks= false,
1535
1754
                            bool send_refresh= false);
1536
1755
  void close_open_tables();
1537
 
  void close_data_files_and_morph_locks(const identifier::Table &identifier);
 
1756
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1538
1757
 
1539
1758
private:
1540
 
  bool free_cached_table(boost::mutex::scoped_lock &scopedLock);
1541
 
 
 
1759
  bool free_cached_table();
1542
1760
public:
1543
1761
 
1544
1762
  /**
1572
1790
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1573
1791
 
1574
1792
  void unlink_open_table(Table *find);
1575
 
  void drop_open_table(Table *table, const identifier::Table &identifier);
 
1793
  void drop_open_table(Table *table, const TableIdentifier &identifier);
1576
1794
  void close_cached_table(Table *table);
1577
1795
 
1578
1796
  /* Create a lock in the cache */
1579
 
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1580
 
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1581
 
 
 
1797
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
 
1798
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
 
1799
 
 
1800
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
 
1801
 
 
1802
  class TableMessages
 
1803
  {
 
1804
    TableMessageCache table_message_cache;
 
1805
 
 
1806
  public:
 
1807
    bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1808
    bool removeTableMessage(const TableIdentifier &identifier);
 
1809
    bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1810
    bool doesTableMessageExist(const TableIdentifier &identifier);
 
1811
    bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
 
1812
 
 
1813
  };
1582
1814
private:
1583
 
  session::TableMessages _table_message_cache;
 
1815
  TableMessages _table_message_cache;
1584
1816
 
1585
1817
public:
1586
 
  session::TableMessages &getMessageCache()
 
1818
  TableMessages &getMessageCache()
1587
1819
  {
1588
1820
    return _table_message_cache;
1589
1821
  }
1590
1822
 
1591
1823
  /* Reopen operations */
1592
 
  bool reopen_tables();
 
1824
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1593
1825
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1594
1826
 
1595
1827
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1598
1830
 
1599
1831
  drizzled::util::Storable *getProperty(const std::string &arg)
1600
1832
  {
1601
 
    return life_properties.getProperty(arg);
 
1833
    return life_properties[arg];
1602
1834
  }
1603
1835
 
1604
1836
  template<class T>
1605
1837
  bool setProperty(const std::string &arg, T *value)
1606
1838
  {
1607
 
    life_properties.setProperty(arg, value);
 
1839
    life_properties[arg]= value;
1608
1840
 
1609
1841
    return true;
1610
1842
  }
1624
1856
    return global_system_variables.storage_engine;
1625
1857
  }
1626
1858
 
1627
 
  void get_xid(DrizzleXid *xid); // Innodb only
 
1859
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1628
1860
 
1629
1861
  table::Singular *getInstanceTable();
1630
1862
  table::Singular *getInstanceTable(List<CreateField> &field_list);
1639
1871
 
1640
1872
    return true;
1641
1873
  }
1642
 
 
1643
1874
public:
1644
1875
 
1645
1876
  void setUsage(bool arg)
1667
1898
 
1668
1899
  // This lives throughout the life of Session
1669
1900
  bool use_usage;
1670
 
  session::PropertyMap life_properties;
 
1901
  PropertyMap life_properties;
1671
1902
  std::vector<table::Singular *> temporary_shares;
1672
1903
  struct rusage usage;
1673
1904
};
1674
1905
 
 
1906
class Join;
 
1907
 
1675
1908
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1676
1909
 
 
1910
} /* namespace drizzled */
 
1911
 
 
1912
/** @TODO why is this in the middle of the file */
 
1913
#include <drizzled/select_to_file.h>
 
1914
#include <drizzled/select_export.h>
 
1915
#include <drizzled/select_dump.h>
 
1916
#include <drizzled/select_insert.h>
 
1917
#include <drizzled/select_create.h>
 
1918
#include <drizzled/tmp_table_param.h>
 
1919
#include <drizzled/select_union.h>
 
1920
#include <drizzled/select_subselect.h>
 
1921
#include <drizzled/select_singlerow_subselect.h>
 
1922
#include <drizzled/select_max_min_finder_subselect.h>
 
1923
#include <drizzled/select_exists_subselect.h>
 
1924
 
 
1925
namespace drizzled
 
1926
{
 
1927
 
 
1928
/**
 
1929
 * A structure used to describe sort information
 
1930
 * for a field or item used in ORDER BY.
 
1931
 */
 
1932
class SortField 
 
1933
{
 
1934
public:
 
1935
  Field *field; /**< Field to sort */
 
1936
  Item  *item; /**< Item if not sorting fields */
 
1937
  size_t length; /**< Length of sort field */
 
1938
  uint32_t suffix_length; /**< Length suffix (0-4) */
 
1939
  Item_result result_type; /**< Type of item */
 
1940
  bool reverse; /**< if descending sort */
 
1941
  bool need_strxnfrm;   /**< If we have to use strxnfrm() */
 
1942
 
 
1943
  SortField() :
 
1944
    field(0),
 
1945
    item(0),
 
1946
    length(0),
 
1947
    suffix_length(0),
 
1948
    result_type(STRING_RESULT),
 
1949
    reverse(0),
 
1950
    need_strxnfrm(0)
 
1951
  { }
 
1952
 
 
1953
};
 
1954
 
 
1955
} /* namespace drizzled */
 
1956
 
 
1957
/** @TODO why is this in the middle of the file */
 
1958
 
 
1959
#include <drizzled/table_ident.h>
 
1960
#include <drizzled/user_var_entry.h>
 
1961
#include <drizzled/unique.h>
 
1962
#include <drizzled/var.h>
 
1963
#include <drizzled/select_dumpvar.h>
 
1964
 
 
1965
namespace drizzled
 
1966
{
 
1967
 
1677
1968
/* Bits in sql_command_flags */
1678
1969
 
1679
1970
enum sql_command_flag_bits 
1695
1986
namespace display  {
1696
1987
const std::string &type(drizzled::Session::global_read_lock_t type);
1697
1988
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1698
 
 
1699
1989
} /* namespace display */
1700
1990
 
1701
1991
} /* namespace drizzled */