00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include <plugin/session_dictionary/dictionary.h>
00025
00026 #include <netdb.h>
00027
00028 #include <drizzled/internal/my_sys.h>
00029 #include <drizzled/internal/thread_var.h>
00030 #include <drizzled/plugin/authorization.h>
00031 #include <drizzled/plugin/client.h>
00032 #include <drizzled/pthread_globals.h>
00033
00034 #include <set>
00035
00036 using namespace std;
00037 using namespace drizzled;
00038
00039 namespace session_dictionary {
00040
00041 Sessions::Sessions() :
00042 plugin::TableFunction("DATA_DICTIONARY", "SESSIONS")
00043 {
00044 add_field("SESSION_ID", plugin::TableFunction::NUMBER, 0, false);
00045 add_field("SESION_USERNAME", 16);
00046 add_field("SESSION_HOST", NI_MAXHOST);
00047 add_field("SESSION_CATALOG", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00048 add_field("SESSION_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, true);
00049 add_field("COMMAND", 16);
00050 add_field("STATE", plugin::TableFunction::STRING, 256, true);
00051 add_field("QUERY", plugin::TableFunction::STRING, PROCESS_LIST_WIDTH, true);
00052 add_field("HAS_GLOBAL_LOCK", plugin::TableFunction::BOOLEAN, 0, false);
00053 add_field("IS_INTERACTIVE", plugin::TableFunction::BOOLEAN, 0, false);
00054 add_field("IS_ADMIN", plugin::TableFunction::BOOLEAN, 0, false);
00055 add_field("IS_CONSOLE", plugin::TableFunction::BOOLEAN, 0, false);
00056 }
00057
00058 Sessions::Generator::Generator(Field **arg) :
00059 plugin::TableFunction::Generator(arg),
00060 session_generator(*getSession().user())
00061 {
00062 }
00063
00064 Sessions::Generator::~Generator()
00065 {
00066 }
00067
00068 bool Sessions::Generator::populate()
00069 {
00070 drizzled::Session::pointer tmp;
00071
00072 while ((tmp= session_generator))
00073 {
00074 drizzled::session::State::const_shared_ptr state(tmp->state());
00075 identifier::User::const_shared_ptr tmp_sctx= tmp->user();
00076
00077
00078 push((int64_t) tmp->thread_id);
00079
00080
00081 if (not tmp_sctx->username().empty())
00082 push(tmp_sctx->username());
00083 else
00084 push(_("no user"));
00085
00086
00087 push(tmp_sctx->address());
00088
00089
00090 push(tmp->catalog().name());
00091
00092
00093 drizzled::util::string::const_shared_ptr schema(tmp->schema());
00094 if (schema and not schema->empty())
00095 {
00096 push(*schema);
00097 }
00098 else
00099 {
00100 push();
00101 }
00102
00103
00104 const char *val= tmp->getKilled() == Session::KILL_CONNECTION ? "Killed" : NULL;
00105 if (val)
00106 {
00107 push(val);
00108 }
00109 else
00110 {
00111 push(getCommandName(tmp->command));
00112 }
00113
00114
00115 const char *step= tmp->get_proc_info();
00116 step ? push(step): push();
00117
00118
00119 if (state)
00120 {
00121 size_t length;
00122 const char *tmp_ptr= state->query(length);
00123 push(tmp_ptr, length);
00124 }
00125 else
00126 {
00127 push();
00128 }
00129
00130
00131 bool has_global_lock= tmp->isGlobalReadLock();
00132 push(has_global_lock);
00133
00134
00135 push(tmp->getClient()->isInteractive());
00136
00137
00138 push(tmp->getClient()->isAdmin());
00139
00140
00141 push(tmp->getClient()->isConsole());
00142
00143 return true;
00144 }
00145
00146 return false;
00147 }
00148
00149 }