00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "user_commands.h"
00031
00032 using namespace drizzled;
00033 using namespace std;
00034
00035 const char* UserCommands::USER_COUNTS[] =
00036 {
00037 "COUNT_SELECT",
00038 "COUNT_DELETE",
00039 "COUNT_UPDATE",
00040 "COUNT_INSERT",
00041 "COUNT_ROLLBACK",
00042 "COUNT_COMMIT",
00043 "COUNT_CREATE",
00044 "COUNT_ALTER",
00045 "COUNT_DROP",
00046 "COUNT_ADMIN"
00047 };
00048
00049 const char* UserCommands::COM_STATUS_VARS[] =
00050 {
00051 "select",
00052 "create_table",
00053 "create_index",
00054 "alter_table",
00055 "update",
00056 "insert",
00057 "insert_select",
00058 "delete",
00059 "truncate",
00060 "drop_table",
00061 "drop_index",
00062 "show_create",
00063 "show_create_db",
00064 "load",
00065 "set_option",
00066 "unlock_tables",
00067 "change_db",
00068 "create_db",
00069 "drop_db",
00070 "alter_db",
00071 "replace",
00072 "replace_select",
00073 "check",
00074 "flush",
00075 "kill",
00076 "analyze",
00077 "rollback",
00078 "rollback_to_savepoint",
00079 "commit",
00080 "savepoint",
00081 "release_savepoint",
00082 "begin",
00083 "rename_table",
00084 "show_warns",
00085 "empty_query",
00086 "show_errors",
00087 "checksum"
00088 };
00089
00090 UserCommands::UserCommands()
00091 {
00092 init();
00093 }
00094
00095 void UserCommands::init()
00096 {
00097 vector<uint64_t>::iterator it= vector_of_command_counts.begin();
00098 for (int j=0; j < SQLCOM_END; ++j)
00099 {
00100 it= vector_of_command_counts.insert(it, 0);
00101 }
00102 vector_of_command_counts.resize(SQLCOM_END);
00103 }
00104
00105 void UserCommands::incrementCount(uint32_t index, uint32_t i)
00106 {
00107 uint64_t *count= &(vector_of_command_counts.at(index));
00108 *count= *count + i;
00109 }
00110
00111 uint64_t UserCommands::getCount(uint32_t index)
00112 {
00113 uint64_t *count= &(vector_of_command_counts.at(index));
00114 return *count;
00115 }
00116
00117 uint64_t UserCommands::getUserCount(uint32_t index)
00118 {
00119 switch (index)
00120 {
00121 case COUNT_SELECT:
00122 return getCount(SQLCOM_SELECT);
00123 case COUNT_DELETE:
00124 return getCount(SQLCOM_DELETE);
00125 case COUNT_UPDATE:
00126 return getCount(SQLCOM_UPDATE);
00127 case COUNT_INSERT:
00128 return getCount(SQLCOM_INSERT);
00129 case COUNT_ROLLBACK:
00130 return getCount(SQLCOM_ROLLBACK);
00131 case COUNT_COMMIT:
00132 return getCount(SQLCOM_COMMIT);
00133 case COUNT_CREATE:
00134 return getCount(SQLCOM_CREATE_TABLE);
00135 case COUNT_ALTER:
00136 return getCount(SQLCOM_ALTER_TABLE);
00137 case COUNT_DROP:
00138 return getCount(SQLCOM_DROP_TABLE);
00139 default:
00140 return 0;
00141 }
00142 }
00143
00144 void UserCommands::reset()
00145 {
00146 for (uint32_t j= 0; j < SQLCOM_END; ++j)
00147 {
00148 uint64_t *count= &(vector_of_command_counts.at(j));
00149 *count= 0;
00150 }
00151 }
00152
00153 UserCommands::UserCommands(const UserCommands &user_commands)
00154 {
00155 init();
00156
00157 for (uint32_t j= 0; j < SQLCOM_END; ++j)
00158 {
00159 uint64_t *my_count= &(vector_of_command_counts.at(j));
00160 uint64_t other_count= user_commands.vector_of_command_counts.at(j);
00161 *my_count= other_count;
00162 }
00163 }
00164
00165 void UserCommands::merge(UserCommands *user_commands)
00166 {
00167 for (uint32_t j= 0; j < SQLCOM_END; ++j)
00168 {
00169 uint64_t *my_count= &(vector_of_command_counts.at(j));
00170 uint64_t other_count= user_commands->vector_of_command_counts.at(j);
00171 *my_count= *my_count + other_count;
00172 }
00173 }
00174
00175 void UserCommands::logCommand(enum_sql_command sql_command)
00176 {
00177 if (sql_command < SQLCOM_END)
00178 {
00179 incrementCount(sql_command);
00180 }
00181 }