~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2009-08-17 00:51:17 UTC
  • mfrom: (1115.3.4 captain)
  • Revision ID: brian@gaz-20090817005117-j9der2dkee8pwbw5
Merge Jay

Show diffs side-by-side

added added

removed removed

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