~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2010-12-08 18:58:56 UTC
  • mfrom: (1976.5.4 real-trunk)
  • Revision ID: brian@tangent.org-20101208185856-577lkcj42ss9xg7s
MErge in fix for session

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "drizzled/util/storable.h"
38
38
#include "drizzled/my_hash.h"
39
39
#include "drizzled/pthread_globals.h"
40
 
 
41
40
#include <netdb.h>
42
41
#include <sys/time.h>
43
42
#include <sys/resource.h>
44
43
 
 
44
#include <algorithm>
 
45
#include <bitset>
 
46
#include <deque>
45
47
#include <map>
46
48
#include <string>
47
 
#include <bitset>
48
 
#include <deque>
49
49
 
50
50
#include "drizzled/security_context.h"
51
51
#include "drizzled/open_tables_state.h"
59
59
#include <boost/thread/mutex.hpp>
60
60
#include <boost/thread/shared_mutex.hpp>
61
61
#include <boost/thread/condition_variable.hpp>
 
62
#include <boost/make_shared.hpp>
 
63
 
62
64
 
63
65
#define MIN_HANDSHAKE_SIZE      6
64
66
 
416
418
 
417
419
  void resetQueryString()
418
420
  {
419
 
    return query.reset(new std::string);
 
421
    query.reset();
 
422
    _state.reset();
420
423
  }
421
424
 
422
425
  /*
428
431
  {
429
432
    QueryString tmp_string(getQueryString());
430
433
 
 
434
    assert(tmp_string);
 
435
    if (not tmp_string)
 
436
    {
 
437
      length= 0;
 
438
      return 0;
 
439
    }
 
440
 
431
441
    length= tmp_string->length();
432
442
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
433
443
    return to_return;
434
444
  }
435
445
 
 
446
  class State {
 
447
    std::vector <char> _query;
 
448
 
 
449
  public:
 
450
    typedef boost::shared_ptr<State> const_shared_ptr;
 
451
 
 
452
    State(const char *in_packet, size_t in_packet_length)
 
453
    {
 
454
      if (in_packet_length)
 
455
      {
 
456
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
 
457
        _query.resize(minimum + 1);
 
458
        memcpy(&_query[0], in_packet, minimum);
 
459
      }
 
460
      else
 
461
      {
 
462
        _query.resize(0);
 
463
      }
 
464
    }
 
465
 
 
466
    const char *query() const
 
467
    {
 
468
      if (_query.size())
 
469
        return &_query[0];
 
470
 
 
471
      return "";
 
472
    }
 
473
 
 
474
    const char *query(size_t &size) const
 
475
    {
 
476
      if (_query.size())
 
477
      {
 
478
        size= _query.size() -1;
 
479
        return &_query[0];
 
480
      }
 
481
 
 
482
      size= 0;
 
483
      return "";
 
484
    }
 
485
  protected:
 
486
    friend class Session;
 
487
    typedef boost::shared_ptr<State> shared_ptr;
 
488
  };
 
489
private:
 
490
  State::shared_ptr  _state; 
 
491
public:
 
492
 
 
493
  State::const_shared_ptr state()
 
494
  {
 
495
    return _state;
 
496
  }
 
497
 
436
498
  /**
437
499
    Name of the current (default) database.
438
500
 
445
507
    the Session of that thread); that thread is (and must remain, for now) the
446
508
    only responsible for freeing this member.
447
509
  */
448
 
  std::string db;
 
510
private:
 
511
  util::string::shared_ptr _schema;
 
512
public:
449
513
 
450
 
  const std::string &getSchema() const
 
514
  util::string::const_shared_ptr schema() const
451
515
  {
452
 
    return db;
 
516
    if (_schema)
 
517
      return _schema;
 
518
 
 
519
    return util::string::const_shared_ptr(new std::string(""));
453
520
  }
454
521
  std::string catalog;
455
522
  /* current cache key */
1309
1376
    database usually involves other actions, like switching other database
1310
1377
    attributes including security context. In the future, this operation
1311
1378
    will be made private and more convenient interface will be provided.
1312
 
 
1313
 
    @return Operation status
1314
 
      @retval false Success
1315
 
      @retval true  Out-of-memory error
1316
1379
  */
1317
 
  bool set_db(const std::string &new_db);
 
1380
  void set_db(const std::string &new_db);
1318
1381
 
1319
1382
  /*
1320
1383
    Copy the current database to the argument. Use the current arena to