Drizzled Public API Documentation

collations.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 
00028 CollationsTool::CollationsTool() :
00029   CharacterSetsTool("COLLATIONS")
00030 {
00031   add_field("CHARACTER_SET_NAME");
00032   add_field("COLLATION_NAME");
00033   add_field("DESCRIPTION");
00034   add_field("ID", plugin::TableFunction::NUMBER, 0, false);
00035   add_field("IS_DEFAULT", plugin::TableFunction::BOOLEAN, 0, false);
00036   add_field("IS_COMPILED", plugin::TableFunction::BOOLEAN, 0, false);
00037   add_field("SORTLEN", plugin::TableFunction::NUMBER, 0, false);
00038 }
00039 
00040 CollationsTool::Generator::Generator(Field **arg) :
00041   CharacterSetsTool::Generator(arg),
00042   is_collation_primed(false)
00043 {
00044 }
00045 
00046 
00047 bool CollationsTool::Generator::end()
00048 {
00049   return collation_iter == all_charsets+255;
00050 }
00051 
00052 
00053 bool CollationsTool::Generator::check()
00054 {
00055   const CHARSET_INFO *tmp_cs= character_set();
00056   const CHARSET_INFO *tmp_cl= collation();
00057 
00058   if (not tmp_cl || 
00059       not (tmp_cl->state & MY_CS_AVAILABLE) ||
00060       not my_charset_same(tmp_cs, tmp_cl))
00061     return true;
00062 
00063   return false;
00064 }
00065 
00066 bool CollationsTool::Generator::nextCollationCore()
00067 {
00068   if (isPrimed())
00069   {
00070     collation_iter++;
00071   }
00072   else
00073   {
00074     if (not isCharacterSetPrimed())
00075      return false;
00076 
00077     collation_iter= all_charsets;
00078     prime();
00079   }
00080 
00081   if (end())
00082     return false;
00083 
00084   if (check())
00085       return false;
00086 
00087   return true;
00088 }
00089 
00090 
00091 bool CollationsTool::Generator::next()
00092 {
00093   while (not nextCollationCore())
00094   {
00095 
00096     if (isPrimed() && not end())
00097       continue;
00098 
00099     if (not nextCharacterSet())
00100       return false;
00101 
00102     prime(false);
00103   }
00104 
00105   return true;
00106 }
00107 
00108 bool CollationsTool::Generator::populate()
00109 {
00110   if (not next())
00111     return false;
00112 
00113   fill();
00114 
00115   return true;
00116 }
00117 
00118 void CollationsTool::Generator::fill()
00119 {
00120   const CHARSET_INFO *tmp_cs= character_set();
00121   const CHARSET_INFO *tmp_cl= collation_iter[0];
00122 
00123   assert(tmp_cs);
00124   assert(tmp_cl);
00125 
00126   assert(tmp_cs->name);
00127   /* CHARACTER_SET_NAME */
00128   push(tmp_cs->name);
00129 
00130   /* "COLLATION_NAME" */
00131   assert(tmp_cl->name);
00132   push(tmp_cl->name);
00133 
00134   /* "DESCRIPTION" */
00135   push(tmp_cl->csname);
00136 
00137   /* COLLATION_ID */
00138   push(static_cast<int64_t>(tmp_cl->number));
00139 
00140   /* IS_DEFAULT */
00141   push((bool)(tmp_cl->state & MY_CS_PRIMARY));
00142 
00143   /* IS_COMPILED */
00144   push((bool)(tmp_cl->state & MY_CS_COMPILED));
00145 
00146   /* SORTLEN */
00147   push(static_cast<int64_t>(tmp_cl->strxfrm_multiply));
00148 }