~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/session_dictionary/sessions.cc

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2011 Sun Microsystems, Inc.
 
5
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include <plugin/session_dictionary/dictionary.h>
 
25
 
 
26
#include <netdb.h>
 
27
 
 
28
#include <drizzled/internal/my_sys.h>
 
29
#include <drizzled/internal/thread_var.h>
 
30
#include <drizzled/plugin/authorization.h>
 
31
#include <drizzled/plugin/client.h>
 
32
#include <drizzled/pthread_globals.h>
 
33
#include <drizzled/session/state.h>
 
34
#include <set>
 
35
 
 
36
using namespace std;
 
37
using namespace drizzled;
 
38
 
 
39
namespace session_dictionary {
 
40
 
 
41
Sessions::Sessions() :
 
42
  plugin::TableFunction("DATA_DICTIONARY", "SESSIONS")
 
43
{
 
44
  add_field("SESSION_ID", plugin::TableFunction::NUMBER, 0, false);
 
45
  add_field("SESSION_USERNAME", 16);
 
46
  add_field("SESSION_HOST", NI_MAXHOST);
 
47
  add_field("SESSION_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
 
48
  add_field("SESSION_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, true);
 
49
  add_field("COMMAND", 16);
 
50
  add_field("STATE", plugin::TableFunction::STRING, 256, true);
 
51
  add_field("QUERY", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
 
52
  add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN, 0, false);
 
53
  add_field("IS_INTERACTIVE", plugin::TableFunction::BOOLEAN, 0, false);
 
54
  add_field("IS_CONSOLE", plugin::TableFunction::BOOLEAN, 0, false);
 
55
}
 
56
 
 
57
Sessions::Generator::Generator(Field **arg) :
 
58
  plugin::TableFunction::Generator(arg),
 
59
  session_generator(*getSession().user())
 
60
{
 
61
}
 
62
 
 
63
bool Sessions::Generator::populate()
 
64
{
 
65
  while (Session* tmp= session_generator)
 
66
  {
 
67
    boost::shared_ptr<session::State> state(tmp->state());
 
68
    identifier::user::ptr tmp_sctx= tmp->user();
 
69
 
 
70
    /* ID */
 
71
    push((int64_t) tmp->thread_id);
 
72
 
 
73
    /* USER */
 
74
    if (not tmp_sctx->username().empty())
 
75
      push(tmp_sctx->username());
 
76
    else 
 
77
      push(_("no user"));
 
78
 
 
79
    /* HOST */
 
80
    push(tmp_sctx->address());
 
81
 
 
82
    /* CATALOG */
 
83
    push(tmp->catalog().name());
 
84
 
 
85
    /* SCHEMA */
 
86
    util::string::ptr schema(tmp->schema());
 
87
    if (schema and not schema->empty())
 
88
    {
 
89
      push(*schema);
 
90
    }
 
91
    else
 
92
    {
 
93
      push();
 
94
    }
 
95
 
 
96
    /* COMMAND */
 
97
    if (tmp->getKilled() == Session::KILL_CONNECTION)
 
98
    {
 
99
      push("Killed");
 
100
    }
 
101
    else
 
102
    {
 
103
      push(getCommandName(tmp->command));
 
104
    }
 
105
 
 
106
    /* STATE */
 
107
    const char *step= tmp->get_proc_info();
 
108
    step ? push(step): push();
 
109
 
 
110
    /* QUERY */
 
111
    if (state)
 
112
    {
 
113
      size_t length;
 
114
      const char *tmp_ptr= state->query(length);
 
115
      push(tmp_ptr, length);
 
116
    }
 
117
    else
 
118
    {
 
119
      push();
 
120
    }
 
121
 
 
122
    /* HAS_GLOBAL_LOCK */
 
123
    bool has_global_lock= tmp->isGlobalReadLock();
 
124
    push(has_global_lock);
 
125
 
 
126
    /* IS_INTERACTIVE */
 
127
    push(tmp->getClient()->isInteractive());
 
128
 
 
129
    /* IS_CONSOLE */
 
130
    push(tmp->getClient()->isConsole());
 
131
 
 
132
    return true;
 
133
  }
 
134
 
 
135
  return false;
 
136
}
 
137
 
 
138
} // namespace session_dictionary