~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/session_dictionary/sessions.cc

  • Committer: patrick crews
  • Date: 2011-03-15 12:12:09 UTC
  • mfrom: (1099.4.216 drizzle)
  • Revision ID: gleebix@gmail.com-20110315121209-8g2tkf31w0rx9ter
Tags: 2011.03.12
Updated translations

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
 
 
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("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);
 
56
}
 
57
 
 
58
Sessions::Generator::Generator(Field **arg) :
 
59
  plugin::TableFunction::Generator(arg),
 
60
  session_generator(*getSession().user())
 
61
{
 
62
}
 
63
 
 
64
Sessions::Generator::~Generator()
 
65
{
 
66
}
 
67
 
 
68
bool Sessions::Generator::populate()
 
69
{
 
70
  drizzled::Session::pointer tmp;
 
71
 
 
72
  while ((tmp= session_generator))
 
73
  {
 
74
    drizzled::session::State::const_shared_ptr state(tmp->state());
 
75
    identifier::User::const_shared_ptr tmp_sctx= tmp->user();
 
76
 
 
77
    /* ID */
 
78
    push((int64_t) tmp->thread_id);
 
79
 
 
80
    /* USER */
 
81
    if (not tmp_sctx->username().empty())
 
82
      push(tmp_sctx->username());
 
83
    else 
 
84
      push(_("no user"));
 
85
 
 
86
    /* HOST */
 
87
    push(tmp_sctx->address());
 
88
 
 
89
    /* CATALOG */
 
90
    push(tmp->catalog().name());
 
91
 
 
92
    /* SCHEMA */
 
93
    drizzled::util::string::const_shared_ptr schema(tmp->schema());
 
94
    if (schema and not schema->empty())
 
95
    {
 
96
      push(*schema);
 
97
    }
 
98
    else
 
99
    {
 
100
      push();
 
101
    }
 
102
 
 
103
    /* COMMAND */
 
104
    const char *val= tmp->getKilled() == Session::KILL_CONNECTION ? "Killed" : NULL;
 
105
    if (val)
 
106
    {
 
107
      push(val);
 
108
    }
 
109
    else
 
110
    {
 
111
      push(getCommandName(tmp->command));
 
112
    }
 
113
 
 
114
    /* STATE */
 
115
    const char *step= tmp->get_proc_info();
 
116
    step ? push(step): push();
 
117
 
 
118
    /* QUERY */
 
119
    if (state)
 
120
    {
 
121
      size_t length;
 
122
      const char *tmp_ptr= state->query(length);
 
123
      push(tmp_ptr, length);
 
124
    }
 
125
    else
 
126
    {
 
127
      push();
 
128
    }
 
129
 
 
130
    /* HAS_GLOBAL_LOCK */
 
131
    bool has_global_lock= tmp->isGlobalReadLock();
 
132
    push(has_global_lock);
 
133
 
 
134
    /* IS_INTERACTIVE */
 
135
    push(tmp->getClient()->isInteractive());
 
136
 
 
137
    /* IS_ADMIN */
 
138
    push(tmp->getClient()->isAdmin());
 
139
 
 
140
    /* IS_CONSOLE */
 
141
    push(tmp->getClient()->isConsole());
 
142
 
 
143
    return true;
 
144
  }
 
145
 
 
146
  return false;
 
147
}
 
148
 
 
149
} // namespace session_dictionary