Drizzled Public API Documentation

index_parts.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/schema_dictionary/dictionary.h>
00023 #include <drizzled/statement/select.h>
00024 
00025 using namespace std;
00026 using namespace drizzled;
00027 
00028 IndexPartsTool::IndexPartsTool() :
00029   IndexesTool("INDEX_PARTS")
00030 {
00031   add_field("TABLE_SCHEMA");
00032   add_field("TABLE_NAME");
00033   add_field("INDEX_NAME");
00034   add_field("COLUMN_NAME");
00035   add_field("COLUMN_NUMBER", plugin::TableFunction::NUMBER, 0, false);
00036   add_field("SEQUENCE_IN_INDEX", plugin::TableFunction::NUMBER, 0, false);
00037   add_field("COMPARE_LENGTH", plugin::TableFunction::NUMBER, 0, true);
00038   add_field("IS_ORDER_REVERSE", plugin::TableFunction::BOOLEAN, 0, false);
00039   add_field("IS_USED_IN_PRIMARY", plugin::TableFunction::BOOLEAN, 0, false);
00040   add_field("IS_UNIQUE", plugin::TableFunction::BOOLEAN, 0, false);
00041   add_field("IS_NULLABLE", plugin::TableFunction::BOOLEAN, 0, false);
00042 }
00043 
00044 IndexPartsTool::Generator::Generator(Field **arg) :
00045   IndexesTool::Generator(arg),
00046   index_part_iterator(0),
00047   is_index_part_primed(false)
00048 {
00049 }
00050 
00051 
00052 bool IndexPartsTool::Generator::nextIndexPartsCore()
00053 {
00054   if (is_index_part_primed)
00055   {
00056     index_part_iterator++;
00057   }
00058   else
00059   {
00060     if (not isIndexesPrimed())
00061       return false;
00062 
00063     index_part_iterator= 0;
00064     is_index_part_primed= true;
00065   }
00066 
00067   if (index_part_iterator >= getIndex().index_part_size())
00068     return false;
00069 
00070   index_part= getIndex().index_part(index_part_iterator);
00071 
00072   return true;
00073 }
00074 
00075 bool IndexPartsTool::Generator::nextIndexParts()
00076 {
00077   while (not nextIndexPartsCore())
00078   {
00079     if (not nextIndex())
00080       return false;
00081     is_index_part_primed= false;
00082   }
00083 
00084   return true;
00085 }
00086 
00087 bool IndexPartsTool::Generator::populate()
00088 {
00089   if (not nextIndexParts())
00090     return false;
00091 
00092   fill();
00093 
00094   return true;
00095 }
00096 
00097 void IndexPartsTool::Generator::fill()
00098 {
00099   const message::Table::Field &field= getTableProto().field(index_part.fieldnr());
00100 
00101   /* TABLE_SCHEMA */
00102   push(getTableProto().schema());
00103 
00104   /* TABLE_NAME */
00105   push(getTableProto().name());
00106 
00107   /* INDEX_NAME */
00108   push(getIndex().name());
00109 
00110   /* COLUMN_NAME */
00111   push(field.name());
00112 
00113   /* COLUMN_NUMBER */
00114   push(static_cast<int64_t>(index_part.fieldnr()));
00115 
00116   /* SEQUENCE_IN_INDEX  */
00117   push(static_cast<int64_t>(index_part_iterator));
00118 
00119   /* COMPARE_LENGTH */
00120   if ((field.type() == message::Table::Field::VARCHAR or
00121     field.type() == message::Table::Field::BLOB) and
00122     (index_part.has_compare_length()) and
00123     (index_part.compare_length() != field.string_options().length()))
00124   {
00125     push(static_cast<int64_t>(index_part.compare_length()));
00126   }
00127   else
00128     push();
00129 
00130   /* IS_ORDER_REVERSE */
00131   push(index_part.in_reverse_order());
00132 
00133   /* IS_USED_IN_PRIMARY */
00134   push(getIndex().is_primary());
00135 
00136   /* IS_UNIQUE */
00137   push(getIndex().is_unique());
00138 
00139   /* IS_NULLABLE */
00140   push(getIndex().options().null_part_key());
00141 }