~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-08-07 20:07:09 UTC
  • mto: (1115.3.4 captain)
  • mto: This revision was merged to the branch mainline in revision 1117.
  • Revision ID: osullivan.padraig@gmail.com-20090807200709-igc524sy3od6u3hk
Removed the Statement class. Copied any members it had that were needed by
the Session class in to that class. Removed the inheritance from Statement
in the Session class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
 
265
265
void mark_transaction_to_rollback(Session *session, bool all);
266
266
 
267
 
/**
268
 
 * Single command executed against this connection.
269
 
 *
270
 
 * @details
271
 
 *
272
 
 * One connection can contain a lot of simultaneously running statements,
273
 
 * some of which could be prepared, that is, contain placeholders.
274
 
 *
275
 
 * To perform some action with statement we reset Session part to the state  of
276
 
 * that statement, do the action, and then save back modified state from Session
277
 
 * to the statement. It will be changed in near future, and Statement will
278
 
 * be used explicitly.
279
 
 *
280
 
 * @todo
281
 
 *
282
 
 * The above comment is bullshit in Drizzle. See TODO markers on Session to
283
 
 * completely detach the inheritance of Session from Statement.
 
267
struct st_savepoint 
 
268
{
 
269
  struct st_savepoint *prev;
 
270
  char *name;
 
271
  uint32_t length;
 
272
  Ha_trx_info *ha_list;
 
273
};
 
274
 
 
275
extern pthread_mutex_t LOCK_xid_cache;
 
276
extern HASH xid_cache;
 
277
 
 
278
#include <drizzled/security_context.h>
 
279
#include <drizzled/open_tables_state.h>
 
280
 
 
281
#include <drizzled/internal_error_handler.h> 
 
282
#include <drizzled/diagnostics_area.h> 
 
283
 
 
284
/**
 
285
  Storage engine specific thread local data.
 
286
*/
 
287
struct Ha_data
 
288
{
 
289
  /**
 
290
    Storage engine specific thread local data.
 
291
    Lifetime: one user connection.
 
292
  */
 
293
  void *ha_ptr;
 
294
  /**
 
295
    0: Life time: one statement within a transaction. If @@autocommit is
 
296
    on, also represents the entire transaction.
 
297
    @sa trans_register_ha()
 
298
 
 
299
    1: Life time: one transaction within a connection.
 
300
    If the storage engine does not participate in a transaction,
 
301
    this should not be used.
 
302
    @sa trans_register_ha()
 
303
  */
 
304
  Ha_trx_info ha_info[2];
 
305
 
 
306
  Ha_data() :ha_ptr(NULL) {}
 
307
};
 
308
 
 
309
/**
 
310
 * Represents a client connection to the database server.
 
311
 *
 
312
 * Contains the client/server protocol object, the current statement
 
313
 * being executed, local-to-session variables and status counters, and
 
314
 * a host of other information.
 
315
 *
 
316
 * @todo
 
317
 *
 
318
 * Session should NOT inherit from Statement, but rather it should have a
 
319
 * vector of Statement object pointers which comprise the statements executed
 
320
 * on the Session.  Until this architectural change is done, we can forget
 
321
 * about parallel operations inside a session.
 
322
 *
 
323
 * @todo
 
324
 *
 
325
 * Make member variables private and have inlined accessors and setters.  Hide
 
326
 * all member variables that are not critical to non-internal operations of the
 
327
 * session object.
284
328
 */
285
 
class Statement
 
329
class Session : public Open_tables_state
286
330
{
287
 
  Statement(const Statement &rhs);              /* not implemented: */
288
 
  Statement &operator=(const Statement &rhs);   /* non-copyable */
289
331
public:
290
332
  /**
291
 
   * List of items created in the parser for this query. Every item puts
292
 
   * itself to the list on creation (see Item::Item() for details))
293
 
   */
294
 
  Item *free_list;
295
 
  MEM_ROOT *mem_root; /**< Pointer to current memroot */
296
 
  /**
297
 
   * Uniquely identifies each statement object in thread scope; change during
298
 
   * statement lifetime.
299
 
   *
300
 
   * @todo should be const
301
 
   */
302
 
   uint32_t id;
303
 
 
 
333
   * @note
 
334
   * The elements from here until the END_STATEMENT_VARIABLES below have
 
335
   * been coped from the original Statement class that used to be declared
 
336
   * in this header file. Session used to inherit from that class. Thus, we
 
337
   * copied the elements from Statement that were needed in Session and then
 
338
   * removed the Statement class.
 
339
   */
 
340
  
304
341
  /*
305
342
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
306
343
                        handler of fields used is set
313
350
                        and update_row.
314
351
  */
315
352
  enum enum_mark_columns mark_used_columns;
316
 
 
 
353
  inline void* alloc(size_t size)
 
354
  {
 
355
    return alloc_root(mem_root,size);
 
356
  }
 
357
  inline void* calloc(size_t size)
 
358
  {
 
359
    void *ptr;
 
360
    if ((ptr= alloc_root(mem_root,size)))
 
361
      memset(ptr, 0, size);
 
362
    return ptr;
 
363
  }
 
364
  inline char *strdup(const char *str)
 
365
  {
 
366
    return strdup_root(mem_root,str);
 
367
  }
 
368
  inline char *strmake(const char *str, size_t size)
 
369
  {
 
370
    return strmake_root(mem_root,str,size);
 
371
  }
 
372
  inline void *memdup(const void *str, size_t size)
 
373
  {
 
374
    return memdup_root(mem_root,str,size);
 
375
  }
 
376
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
 
377
  {
 
378
    void *ptr;
 
379
    if ((ptr= alloc_root(mem_root,size+gap)))
 
380
      memcpy(ptr,str,size);
 
381
    return ptr;
 
382
  }
 
383
  /** Frees all items attached to this Statement */
 
384
  void free_items();
 
385
  /**
 
386
   * List of items created in the parser for this query. Every item puts
 
387
   * itself to the list on creation (see Item::Item() for details))
 
388
   */
 
389
  Item *free_list;
 
390
  MEM_ROOT *mem_root; /**< Pointer to current memroot */
 
391
  /**
 
392
   * Uniquely identifies each statement object in thread scope; change during
 
393
   * statement lifetime.
 
394
   *
 
395
   * @todo should be const
 
396
   */
 
397
  uint32_t id;
317
398
  LEX *lex; /**< parse tree descriptor */
318
399
  /**
319
400
    Points to the query associated with this statement. It's const, but
354
435
  */
355
436
  char *db;
356
437
  uint32_t db_length; /**< Length of current schema name */
357
 
 
358
 
public:
359
 
 
360
 
  /* This constructor is called for backup statements */
361
 
  Statement() {}
362
 
 
363
 
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, uint32_t id_arg)
364
 
  :
365
 
    free_list(NULL), 
366
 
    mem_root(mem_root_arg),
367
 
    id(id_arg),
368
 
    mark_used_columns(MARK_COLUMNS_READ),
369
 
    lex(lex_arg),
370
 
    query(NULL),
371
 
    query_length(0),
372
 
    db(NULL),
373
 
    db_length(0)
374
 
  {}
375
 
  virtual ~Statement() {}
376
 
  inline void* alloc(size_t size)
377
 
  {
378
 
    return alloc_root(mem_root,size);
379
 
  }
380
 
  inline void* calloc(size_t size)
381
 
  {
382
 
    void *ptr;
383
 
    if ((ptr= alloc_root(mem_root,size)))
384
 
      memset(ptr, 0, size);
385
 
    return ptr;
386
 
  }
387
 
  inline char *strdup(const char *str)
388
 
  {
389
 
    return strdup_root(mem_root,str);
390
 
  }
391
 
  inline char *strmake(const char *str, size_t size)
392
 
  {
393
 
    return strmake_root(mem_root,str,size);
394
 
  }
395
 
  inline void *memdup(const void *str, size_t size)
396
 
  {
397
 
    return memdup_root(mem_root,str,size);
398
 
  }
399
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
400
 
  {
401
 
    void *ptr;
402
 
    if ((ptr= alloc_root(mem_root,size+gap)))
403
 
      memcpy(ptr,str,size);
404
 
    return ptr;
405
 
  }
406
 
  /** Frees all items attached to this Statement */
407
 
  void free_items();
408
 
};
409
 
 
410
 
struct st_savepoint 
411
 
{
412
 
  struct st_savepoint *prev;
413
 
  char *name;
414
 
  uint32_t length;
415
 
  Ha_trx_info *ha_list;
416
 
};
417
 
 
418
 
extern pthread_mutex_t LOCK_xid_cache;
419
 
extern HASH xid_cache;
420
 
 
421
 
#include <drizzled/security_context.h>
422
 
#include <drizzled/open_tables_state.h>
423
 
 
424
 
#include <drizzled/internal_error_handler.h> 
425
 
#include <drizzled/diagnostics_area.h> 
426
 
 
427
 
/**
428
 
  Storage engine specific thread local data.
429
 
*/
430
 
struct Ha_data
431
 
{
432
 
  /**
433
 
    Storage engine specific thread local data.
434
 
    Lifetime: one user connection.
435
 
  */
436
 
  void *ha_ptr;
437
 
  /**
438
 
    0: Life time: one statement within a transaction. If @@autocommit is
439
 
    on, also represents the entire transaction.
440
 
    @sa trans_register_ha()
441
 
 
442
 
    1: Life time: one transaction within a connection.
443
 
    If the storage engine does not participate in a transaction,
444
 
    this should not be used.
445
 
    @sa trans_register_ha()
446
 
  */
447
 
  Ha_trx_info ha_info[2];
448
 
 
449
 
  Ha_data() :ha_ptr(NULL) {}
450
 
};
451
 
 
452
 
/**
453
 
 * Represents a client connection to the database server.
454
 
 *
455
 
 * Contains the client/server protocol object, the current statement
456
 
 * being executed, local-to-session variables and status counters, and
457
 
 * a host of other information.
458
 
 *
459
 
 * @todo
460
 
 *
461
 
 * Session should NOT inherit from Statement, but rather it should have a
462
 
 * vector of Statement object pointers which comprise the statements executed
463
 
 * on the Session.  Until this architectural change is done, we can forget
464
 
 * about parallel operations inside a session.
465
 
 *
466
 
 * @todo
467
 
 *
468
 
 * Make member variables private and have inlined accessors and setters.  Hide
469
 
 * all member variables that are not critical to non-internal operations of the
470
 
 * session object.
471
 
 */
472
 
class Session :public Statement, public Open_tables_state
473
 
{
474
 
public:
 
438
  /**< END_STATEMENT_VARIABLES */
 
439
 
475
440
  /**
476
441
    Constant for Session::where initialization in the beginning of every query.
477
442
 
907
872
  }
908
873
 
909
874
  Session(Protocol *protocol_arg);
910
 
  ~Session();
 
875
  virtual ~Session();
911
876
 
912
877
  /**
913
878
    Initialize memory roots necessary for query processing and (!)