Drizzled Public API Documentation

variables.cc

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <plugin/session_dictionary/dictionary.h>
00024 #include <drizzled/user_var_entry.h>
00025 
00026 #define LARGEST_USER_VARIABLE_NAME 128
00027 
00028 namespace session_dictionary {
00029 
00030 Variables::Variables() :
00031   drizzled::plugin::TableFunction("DATA_DICTIONARY", "USER_DEFINED_VARIABLES")
00032 {
00033   add_field("VARIABLE_NAME", drizzled::plugin::TableFunction::STRING, LARGEST_USER_VARIABLE_NAME, false);
00034   add_field("VARIABLE_VALUE", drizzled::plugin::TableFunction::STRING, LARGEST_USER_VARIABLE_NAME, true);
00035 }
00036 
00037 Variables::Generator::Generator(drizzled::Field **arg) :
00038   drizzled::plugin::TableFunction::Generator(arg),
00039   user_vars(getSession().getUserVariables()),
00040   iter(user_vars.begin())
00041 {
00042 }
00043 
00044 Variables::Generator::~Generator()
00045 {
00046 }
00047 
00048 bool Variables::Generator::populate()
00049 {
00050   while (iter != user_vars.end())
00051   {
00052     char buff[LARGEST_USER_VARIABLE_NAME];
00053     drizzled::String tmp(buff, sizeof(buff), drizzled::system_charset_info);
00054 
00055     bool null_value;
00056     uint32_t decimals= 4; // arbitrary
00057     iter->second->val_str(&null_value, &tmp, decimals);
00058 
00059 
00060     // VARIABLE_NAME
00061     push(iter->first);
00062     
00063     // VARIABLE_VALUE 
00064     if (null_value)
00065       push();
00066     else
00067       push(tmp.c_str());
00068 
00069     iter++;
00070 
00071     return true;
00072   }
00073 
00074   return false;
00075 }
00076 
00077 } /* namespace session_dictionary */