Drizzled Public API Documentation

data_dictionary_schema.cc

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2010 Djellel Eddine Difallah
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *   * Redistributions of source code must retain the above copyright notice,
00009  *     this list of conditions and the following disclaimer.
00010  *   * Redistributions in binary form must reproduce the above copyright notice,
00011  *     this list of conditions and the following disclaimer in the documentation
00012  *     and/or other materials provided with the distribution.
00013  *   * Neither the name of Djellel Eddine Difallah nor the names of its contributors
00014  *     may be used to endorse or promote products derived from this software
00015  *     without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027  * THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 
00044 #include <config.h>
00045 
00046 #include "query_cache_service.h"
00047 #include "data_dictionary_schema.h"
00048 
00049 #include <fcntl.h>
00050 #include <sys/stat.h>
00051 
00052 using namespace std;
00053 using namespace drizzled;
00054 
00055 /*
00056  *
00057  * Query_Cache_Meta_ENTRIES view
00058  *
00059  */
00060 
00061 QueryCacheTool::QueryCacheTool() :
00062   plugin::TableFunction("DATA_DICTIONARY", "QUERY_CACHE_ENTRIES")
00063 {
00064   add_field("key");
00065   add_field("schema");
00066   add_field("sql");
00067 }
00068 
00069 QueryCacheTool::Generator::Generator(Field **arg) :
00070   plugin::TableFunction::Generator(arg)
00071 {
00072   it= QueryCacheService::cache.begin();
00073   end= QueryCacheService::cache.end(); 
00074 }
00075 
00076 bool QueryCacheTool::Generator::populate()
00077 {
00078   if (it == end)
00079   { 
00080     return false;
00081   } 
00082 
00083   QueryCacheService::CacheEntry &entry= *it;
00084 
00085   push(entry.first);
00086   push(entry.second.schema());
00087   push(entry.second.sql());
00088 
00089   it++;
00090 
00091   return true;
00092 }
00093 
00094 /*
00095  *
00096  * Query_Cache_Cached_Tables view
00097  *
00098  */
00099 
00100 CachedTables::CachedTables() :
00101   plugin::TableFunction("DATA_DICTIONARY", "QUERY_CACHED_TABLES")
00102 {
00103   add_field("Table");
00104   add_field("Cache_Keys");
00105 }
00106 
00107 CachedTables::Generator::Generator(Field **arg) :
00108   plugin::TableFunction::Generator(arg)
00109 {
00110   it= QueryCacheService::cachedTables.begin();
00111   end= QueryCacheService::cachedTables.end(); 
00112 }
00113 
00114 bool CachedTables::Generator::populate()
00115 {
00116   if (it == end)
00117   { 
00118     return false;
00119   } 
00120 
00121   QueryCacheService::CachedTablesEntry &entry= *it;
00122 
00123   push(entry.first);
00124   string list_keys;
00125   vector<string>::iterator tmp;
00126   for(tmp= entry.second.begin(); tmp != entry.second.end(); tmp++)
00127   {
00128     list_keys+= "::"+ *tmp;
00129   }
00130   push(list_keys);
00131   it++;
00132   return true;
00133 }