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>
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("SESION_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_ADMIN", plugin::TableFunction::BOOLEAN, 0, false);
55
add_field("IS_CONSOLE", plugin::TableFunction::BOOLEAN, 0, false);
58
Sessions::Generator::Generator(Field **arg) :
59
plugin::TableFunction::Generator(arg),
60
session_generator(*getSession().user())
64
Sessions::Generator::~Generator()
68
bool Sessions::Generator::populate()
70
drizzled::Session::pointer tmp;
72
while ((tmp= session_generator))
74
drizzled::session::State::const_shared_ptr state(tmp->state());
75
identifier::User::const_shared_ptr tmp_sctx= tmp->user();
78
push((int64_t) tmp->thread_id);
81
if (not tmp_sctx->username().empty())
82
push(tmp_sctx->username());
87
push(tmp_sctx->address());
90
push(tmp->catalog().name());
93
drizzled::util::string::const_shared_ptr schema(tmp->schema());
94
if (schema and not schema->empty())
104
const char *val= tmp->getKilled() == Session::KILL_CONNECTION ? "Killed" : NULL;
111
push(getCommandName(tmp->command));
115
const char *step= tmp->get_proc_info();
116
step ? push(step): push();
122
const char *tmp_ptr= state->query(length);
123
push(tmp_ptr, length);
130
/* HAS_GLOBAL_LOCK */
131
bool has_global_lock= tmp->isGlobalReadLock();
132
push(has_global_lock);
135
push(tmp->getClient()->isInteractive());
138
push(tmp->getClient()->isAdmin());
141
push(tmp->getClient()->isConsole());
149
} // namespace session_dictionary