Go to the documentation of this file.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
00036 #include <config.h>
00037 #include <drizzled/plugin/function.h>
00038 #include <drizzled/item/func.h>
00039 #include <drizzled/function/str/strfunc.h>
00040 #include <drizzled/error.h>
00041 #include <drizzled/internal/my_sys.h>
00042 #include <drizzled/charset.h>
00043
00044 #include <fcntl.h>
00045
00046 #include "query_cache_udf_tools.h"
00047 #include "query_cache_service.h"
00048 #include "memcached_qc.h"
00049
00050 #include <drizzled/message/resultset.pb.h>
00051 #include <google/protobuf/io/zero_copy_stream.h>
00052 #include <google/protobuf/io/zero_copy_stream_impl.h>
00053 #include <google/protobuf/io/coded_stream.h>
00054 #include <google/protobuf/text_format.h>
00055
00056 using namespace std;
00057 using namespace drizzled;
00058 using namespace google;
00059
00060
00061 plugin::Create_function<PrintQueryCacheMetaFunction> *print_query_cache_meta_func_factory= NULL;
00062
00063 void PrintQueryCacheMetaFunction::fix_length_and_dec()
00064 {
00065 max_length= 2 * 1024 * 1024;
00066 args[0]->collation.set(
00067 get_charset_by_csname(args[0]->collation.collation->csname,
00068 MY_CS_BINSORT), DERIVATION_COERCIBLE);
00069 }
00070
00071 String *PrintQueryCacheMetaFunction::val_str(String *str)
00072 {
00073 assert(fixed == true);
00074
00075 String *key_arg= args[0]->val_str(str);
00076
00077 if (key_arg == NULL)
00078 {
00079 my_error(ER_INVALID_NULL_ARGUMENT, MYF(0), func_name());
00080 null_value= true;
00081 return NULL;
00082 }
00083
00084 null_value= false;
00085
00086 map<string, message::Resultset>::iterator it= QueryCacheService::cache.find(String_to_std_string(*key_arg));
00087
00088 if (it == QueryCacheService::cache.end())
00089 {
00090 my_error(ER_INVALID_NULL_ARGUMENT, MYF(0), func_name());
00091 null_value= true;
00092 return NULL;
00093 }
00094
00095 message::Resultset resultset_message= it->second;
00096
00097 string resultset_text;
00098 protobuf::TextFormat::PrintToString(resultset_message, &resultset_text);
00099
00100 if (str->alloc(resultset_text.length()))
00101 {
00102 null_value= true;
00103 return NULL;
00104 }
00105
00106 str->length(resultset_text.length());
00107
00108 strncpy(str->ptr(), resultset_text.c_str(), resultset_text.length());
00109
00110 return str;
00111 }
00112
00113 int64_t QueryCacheFlushFunction::val_int()
00114 {
00115 bool res;
00116 time_t expiration= 0;
00117 null_value= false;
00118
00119 if ((arg_count != 0 && arg_count != 1) ||!MemcachedQueryCache::getClient())
00120 {
00121 return 0;
00122 }
00123
00124 if (arg_count == 1)
00125 {
00126 String *tmp_exp= args[0]->val_str(&value);
00127
00128 expiration= (time_t)atoi(tmp_exp->c_ptr());
00129 }
00130
00131 res= MemcachedQueryCache::getClient()->flush(expiration);
00132 QueryCacheService::cache.clear();
00133 QueryCacheService::cachedTables.clear();
00134
00135 if (not res)
00136 {
00137 return 0;
00138 }
00139
00140 return 1;
00141 }