diff --git a/include/mysql_thread.h b/include/mysql_thread.h index a8b66cd5c..00184eb38 100644 --- a/include/mysql_thread.h +++ b/include/mysql_thread.h @@ -258,6 +258,9 @@ class MySQL_Threads_Handler virtual void shutdown_threads() {}; virtual void wrlock() {}; virtual void wrunlock() {}; + virtual char *get_variable(char *name) {return NULL;}; + virtual bool set_variable(char *name, char *value) {return false;}; + virtual char **get_variables_list() {return NULL;} }; typedef MySQL_Threads_Handler * create_MySQL_Threads_Handler_t(); diff --git a/lib/Standard_MySQL_Thread.cpp b/lib/Standard_MySQL_Thread.cpp index 99d6ef2ff..37e971bb2 100644 --- a/lib/Standard_MySQL_Thread.cpp +++ b/lib/Standard_MySQL_Thread.cpp @@ -169,6 +169,17 @@ volatile static unsigned int __global_MySQL_Thread_Variables_version; +static char * mysql_thread_variables_names[]= { + (char *)"default_schema", + (char *)"poll_timeout", + (char *)"server_capabilities", + (char *)"server_version", + (char *)"threads", + NULL +}; + + + class Standard_MySQL_Threads_Handler: public MySQL_Threads_Handler { private: @@ -219,6 +230,94 @@ class Standard_MySQL_Threads_Handler: public MySQL_Threads_Handler proxy_error("Not existing variable: %s\n", name); assert(0); return 0; } + + virtual char *get_variable(char *name) { // this is the public function, accessible from admin +#define INTBUFSIZE 4096 + char intbuf[INTBUFSIZE]; + if (!strcmp(name,"server_version")) return strdup(variables.server_version); + if (!strcmp(name,"default_schema")) return strdup(variables.default_schema); + if (!strcmp(name,"server_capabilities")) { + // FIXME : make it human readable + sprintf(intbuf,"%d",variables.server_capabilities); + return strdup(intbuf); + } + if (!strcmp(name,"poll_timeout")) { + sprintf(intbuf,"%d",variables.poll_timeout); + return strdup(intbuf); + } + if (!strcmp(name,"threads")) { + sprintf(intbuf,"%d",num_threads); + return strdup(intbuf); + } + return NULL; + } + + + + + virtual bool set_variable(char *name, char *value) { // this is the public function, accessible from admin + // IN: + // name: variable name + // value: variable value + // + // OUT: + // false: unable to change the variable value, either because doesn't exist, or because out of range, or read only + // true: variable value changed + // + size_t vallen=strlen(value); + + if (!strcmp(name,"default_schema")) { + if (vallen) { + free(variables.default_schema); + variables.default_schema=strdup(value); + return true; + } else { + return false; + } + } + if (!strcmp(name,"server_version")) { + if (vallen) { + free(variables.server_version); + variables.server_version=strdup(value); + return true; + } else { + return false; + } + } + if (!strcmp(name,"poll_timeout")) { + int intv=atoi(value); + if (intv > 10 && intv < 20000) { + variables.poll_timeout=intv; + return true; + } else { + return false; + } + } + if (!strcmp(name,"threads")) { + int intv=atoi(value); + if (num_threads==0 && intv > 0 && intv < 128) { + num_threads=intv; + return true; + } else { + return false; + } + } + + return false; + } + + + virtual char **get_variable_lists() { + size_t l=sizeof(mysql_thread_variables_names); + unsigned int i; + char **ret=(char **)malloc(sizeof(char *)*l); + for (i=0;i