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 #include <drizzled/session/state.h>
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("SESSION_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_CONSOLE", plugin::TableFunction::BOOLEAN, 0, false);
00055 }
00056
00057 Sessions::Generator::Generator(Field **arg) :
00058 plugin::TableFunction::Generator(arg),
00059 session_generator(*getSession().user())
00060 {
00061 }
00062
00063 bool Sessions::Generator::populate()
00064 {
00065 while (Session* tmp= session_generator)
00066 {
00067 boost::shared_ptr<session::State> state(tmp->state());
00068 identifier::user::ptr tmp_sctx= tmp->user();
00069
00070
00071 push((int64_t) tmp->thread_id);
00072
00073
00074 if (not tmp_sctx->username().empty())
00075 push(tmp_sctx->username());
00076 else
00077 push(_("no user"));
00078
00079
00080 push(tmp_sctx->address());
00081
00082
00083 push(tmp->catalog().name());
00084
00085
00086 util::string::ptr schema(tmp->schema());
00087 if (schema and not schema->empty())
00088 {
00089 push(*schema);
00090 }
00091 else
00092 {
00093 push();
00094 }
00095
00096
00097 if (tmp->getKilled() == Session::KILL_CONNECTION)
00098 {
00099 push("Killed");
00100 }
00101 else
00102 {
00103 push(getCommandName(tmp->command));
00104 }
00105
00106
00107 const char *step= tmp->get_proc_info();
00108 step ? push(step): push();
00109
00110
00111 if (state)
00112 {
00113 size_t length;
00114 const char *tmp_ptr= state->query(length);
00115 push(tmp_ptr, length);
00116 }
00117 else
00118 {
00119 push();
00120 }
00121
00122
00123 bool has_global_lock= tmp->isGlobalReadLock();
00124 push(has_global_lock);
00125
00126
00127 push(tmp->getClient()->isInteractive());
00128
00129
00130 push(tmp->getClient()->isConsole());
00131
00132 return true;
00133 }
00134
00135 return false;
00136 }
00137
00138 }