Drizzled Public API Documentation

config_table_function.cc
00001 /*
00002   Copyright (C) 2010 Stewart Smith
00003 
00004   This program is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU General Public License
00006   as published by the Free Software Foundation; either version 2
00007   of the License, or (at your option) any later version.
00008 
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details.
00013 
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 */
00018 
00019 #include <config.h>
00020 #include <drizzled/plugin/table_function.h>
00021 
00022 #include <haildb.h>
00023 
00024 #include "config_table_function.h"
00025 
00026 using namespace std;
00027 using namespace drizzled;
00028 
00029 class LibInnoDBConfigTool : public drizzled::plugin::TableFunction
00030 {
00031 public:
00032 
00033   LibInnoDBConfigTool();
00034 
00035   LibInnoDBConfigTool(const char *table_arg) :
00036     drizzled::plugin::TableFunction("data_dictionary", table_arg)
00037   { }
00038 
00039   ~LibInnoDBConfigTool() {}
00040 
00041   class Generator : public drizzled::plugin::TableFunction::Generator
00042   {
00043   private:
00044     const char **names;
00045     uint32_t names_count;
00046     uint32_t names_next;
00047   public:
00048     Generator(drizzled::Field **arg);
00049     ~Generator();
00050 
00051     bool populate();
00052   };
00053 
00054   LibInnoDBConfigTool::Generator *generator(drizzled::Field **arg)
00055   {
00056     return new Generator(arg);
00057   }
00058 };
00059 
00060 LibInnoDBConfigTool::LibInnoDBConfigTool() :
00061   plugin::TableFunction("DATA_DICTIONARY", "HAILDB_CONFIGURATION")
00062 {
00063   add_field("NAME");
00064   add_field("TYPE");
00065   add_field("VALUE", plugin::TableFunction::STRING, 64, true);
00066 }
00067 
00068 LibInnoDBConfigTool::Generator::Generator(Field **arg) :
00069   plugin::TableFunction::Generator(arg),
00070   names_next(0)
00071 {
00072   ib_err_t err= ib_cfg_get_all(&names, &names_count);
00073   assert(err == DB_SUCCESS);
00074 }
00075 
00076 LibInnoDBConfigTool::Generator::~Generator()
00077 {
00078   free(names);
00079 }
00080 
00081 bool LibInnoDBConfigTool::Generator::populate()
00082 {
00083   if (names_next < names_count)
00084   {
00085     const char* config_name= names[names_next];
00086 
00087     push(config_name);
00088 
00089     ib_cfg_type_t type;
00090     ib_err_t err= ib_cfg_var_get_type(config_name, &type);
00091     assert(err == DB_SUCCESS);
00092 
00093     void *value_ptr;
00094     err= ib_cfg_get(config_name, &value_ptr);
00095     assert(err == DB_SUCCESS);
00096 
00097     switch(type)
00098     {
00099     case IB_CFG_IBOOL:
00100     {
00101       push("BOOL");
00102       ib_bool_t value= (ib_bool_t)value_ptr;
00103       if (value == IB_FALSE)
00104         push("false");
00105       else
00106         push("true");
00107       break;
00108     }
00109     case IB_CFG_ULINT:
00110     {
00111       push("ULINT");
00112       push((uint64_t)value_ptr);
00113       break;
00114     }
00115     case IB_CFG_ULONG:
00116     {
00117       push("ULONG");
00118       push((uint64_t)value_ptr);
00119       break;
00120     }
00121     case IB_CFG_TEXT:
00122     {
00123       push("TEXT");
00124       if (value_ptr == NULL)
00125         push();
00126       else
00127         push((char*)value_ptr);
00128       break;
00129     }
00130     case IB_CFG_CB:
00131       push("CALLBACK");
00132       if (value_ptr == NULL)
00133         push();
00134       else
00135         push("Is set");
00136       break;
00137     default:
00138       push("UNKNOWN");
00139       push("UNKNOWN");
00140       break;
00141     }
00142 
00143     names_next++;
00144     return true;
00145   }
00146   return false; // No more rows
00147 }
00148 
00149 static LibInnoDBConfigTool *config_tool;
00150 
00151 int config_table_function_initialize(drizzled::module::Context &context)
00152 {
00153   config_tool= new(std::nothrow)LibInnoDBConfigTool();
00154   context.add(config_tool);
00155 
00156   return 0;
00157 }