1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2011 Sun Microsystems, Inc.
5
* Copyright (C) 2009 Sun Microsystems, Inc.
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.
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.
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
24
#include <plugin/session_dictionary/dictionary.h>
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>
37
using namespace drizzled;
39
namespace session_dictionary {
41
Sessions::Sessions() :
42
plugin::TableFunction("DATA_DICTIONARY", "SESSIONS")
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);
57
Sessions::Generator::Generator(Field **arg) :
58
plugin::TableFunction::Generator(arg),
59
session_generator(*getSession().user())
63
bool Sessions::Generator::populate()
65
while (Session* tmp= session_generator)
67
boost::shared_ptr<session::State> state(tmp->state());
68
identifier::user::ptr tmp_sctx= tmp->user();
71
push((int64_t) tmp->thread_id);
74
if (not tmp_sctx->username().empty())
75
push(tmp_sctx->username());
80
push(tmp_sctx->address());
83
push(tmp->catalog().name());
86
util::string::ptr schema(tmp->schema());
87
if (schema and not schema->empty())
97
if (tmp->getKilled() == Session::KILL_CONNECTION)
103
push(getCommandName(tmp->command));
107
const char *step= tmp->get_proc_info();
108
step ? push(step): push();
114
const char *tmp_ptr= state->query(length);
115
push(tmp_ptr, length);
122
/* HAS_GLOBAL_LOCK */
123
bool has_global_lock= tmp->isGlobalReadLock();
124
push(has_global_lock);
127
push(tmp->getClient()->isInteractive());
130
push(tmp->getClient()->isConsole());
138
} // namespace session_dictionary