Drizzled Public API Documentation

character_sets.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 Sun Microsystems, Inc.
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 #include <plugin/collation_dictionary/dictionary.h>
00023 
00024 using namespace std;
00025 using namespace drizzled;
00026 
00027 CharacterSetsTool::CharacterSetsTool() :
00028   plugin::TableFunction("DATA_DICTIONARY", "CHARACTER_SETS")
00029 {
00030   add_field("CHARACTER_SET_NAME");
00031   add_field("DEFAULT_COLLATE_NAME");
00032   add_field("DESCRIPTION");
00033   add_field("MAXLEN", plugin::TableFunction::NUMBER, 0, false);
00034 }
00035 
00036 CharacterSetsTool::Generator::Generator(Field **arg) :
00037   plugin::TableFunction::Generator(arg),
00038   is_char_primed(false)
00039 {
00040 }
00041 
00042 bool CharacterSetsTool::Generator::checkCharacterSet()
00043 {
00044   if (character_set() && (character_set()->state & MY_CS_PRIMARY) &&
00045       (character_set()->state & MY_CS_AVAILABLE) && not (character_set()->state & MY_CS_HIDDEN))
00046   {
00047     return false;
00048   }
00049 
00050   return true;
00051 }
00052 
00053 bool CharacterSetsTool::Generator::nextCharacterSetCore()
00054 {
00055   if (is_char_primed)
00056   {
00057     character_set_iter++;
00058   }
00059   else
00060   {
00061     character_set_iter= all_charsets;
00062     is_char_primed= true;
00063   }
00064 
00065   if (character_set_iter == all_charsets+255)
00066     return false;
00067 
00068   if (checkCharacterSet())
00069       return false;
00070 
00071   return true;
00072 }
00073 
00074 bool CharacterSetsTool::Generator::nextCharacterSet()
00075 {
00076   while (not nextCharacterSetCore())
00077   {
00078     if (character_set_iter == all_charsets+255)
00079       return false;
00080   }
00081 
00082   return true;
00083 }
00084 
00085 bool CharacterSetsTool::Generator::populate()
00086 {
00087   if (nextCharacterSet())
00088   {
00089     fill();
00090     return true;
00091   }
00092 
00093   return false;
00094 }
00095 
00096 void CharacterSetsTool::Generator::fill()
00097 {
00098   const CHARSET_INFO * const tmp_cs= character_set_iter[0];
00099 
00100   /* CHARACTER_SET_NAME */
00101   push(tmp_cs->csname);
00102 
00103   /* DEFAULT_COLLATE_NAME */
00104   push(tmp_cs->name);
00105 
00106   /* DESCRIPTION */
00107   push(tmp_cs->comment);
00108 
00109   /* MAXLEN */
00110   push(static_cast<int64_t>(tmp_cs->mbmaxlen));
00111 }