Drizzled Public API Documentation

message.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 <drizzled/show.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/schema.h>
00026 #include <drizzled/plugin/event_observer.h>
00027 #include <drizzled/message.h>
00028 
00029 #include <string>
00030 
00031 namespace drizzled {
00032 namespace message {
00033 
00034 static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
00035 
00036 // These are used to generate strings for types
00037 static const std::string VARCHAR("VARCHAR");
00038 static const std::string VARBINARY("VARBINARY");
00039 static const std::string DOUBLE("DOUBLE");
00040 static const std::string TEXT("TEXT");
00041 static const std::string BLOB("BLOB");
00042 static const std::string ENUM("ENUM");
00043 static const std::string INTEGER("INTEGER");
00044 static const std::string BIGINT("BIGINT");
00045 static const std::string DECIMAL("DECIMAL");
00046 static const std::string DATE("DATE");
00047 static const std::string EPOCH("EPOCH");
00048 static const std::string TIMESTAMP("TIMESTAMP");
00049 static const std::string MICROTIME("MICROTIME");
00050 static const std::string DATETIME("DATETIME");
00051 static const std::string TIME("TIME");
00052 static const std::string UUID("UUID");
00053 static const std::string BOOLEAN("BOOLEAN");
00054 static const std::string IPV6("IPV6");
00055 
00056 static const std::string UNDEFINED("UNDEFINED");
00057 static const std::string RESTRICT("RESTRICT");
00058 static const std::string CASCADE("CASCADE");
00059 static const std::string SET_NULL("SET NULL");
00060 static const std::string NO_ACTION("NO ACTION");
00061 static const std::string SET_DEFAULT("SET DEFAULT");
00062 
00063 static const std::string YES("YES");
00064 static const std::string NO("NO");
00065 
00066 static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
00067 static const std::string BTREE("BTREE");
00068 static const std::string RTREE("RTREE");
00069 static const std::string HASH("HASH");
00070 static const std::string FULLTEXT("FULLTEXT");
00071 
00072 static const std::string MATCH_FULL("FULL");
00073 static const std::string MATCH_PARTIAL("PARTIAL");
00074 static const std::string MATCH_SIMPLE("SIMPLE");
00075 
00076 const static std::string STANDARD_STRING("STANDARD");
00077 const static std::string TEMPORARY_STRING("TEMPORARY");
00078 const static std::string INTERNAL_STRING("INTERNAL");
00079 const static std::string FUNCTION_STRING("FUNCTION");
00080 
00081 void update(drizzled::message::Schema &arg)
00082 {
00083   arg.set_version(arg.version() + 1);
00084   arg.set_update_timestamp(time(NULL));
00085 }
00086 
00087 void update(drizzled::message::Table &arg)
00088 {
00089   arg.set_version(arg.version() + 1);
00090   arg.set_update_timestamp(time(NULL));
00091 }
00092 
00093 bool is_numeric(const message::Table::Field &field)
00094 {
00095   message::Table::Field::FieldType type= field.type();
00096 
00097   switch (type)
00098   {
00099   case message::Table::Field::DOUBLE:
00100   case message::Table::Field::INTEGER:
00101   case message::Table::Field::BIGINT:
00102   case message::Table::Field::DECIMAL:
00103     return true;
00104   case message::Table::Field::BLOB:
00105   case message::Table::Field::VARCHAR:
00106   case message::Table::Field::ENUM:
00107   case message::Table::Field::DATE:
00108   case message::Table::Field::EPOCH:
00109   case message::Table::Field::DATETIME:
00110   case message::Table::Field::TIME:
00111   case message::Table::Field::UUID:
00112   case message::Table::Field::BOOLEAN:
00113   case message::Table::Field::IPV6:
00114     break;
00115   }
00116 
00117   return false;
00118 }
00119 
00120 const std::string &type(const message::Table::Field &field)
00121 {
00122   message::Table::Field::FieldType type= field.type();
00123 
00124   switch (type)
00125   {
00126   case message::Table::Field::VARCHAR:
00127     return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
00128   case message::Table::Field::DOUBLE:
00129     return DOUBLE;
00130   case message::Table::Field::BLOB:
00131     return field.string_options().collation().compare("binary") ? TEXT : BLOB;
00132   case message::Table::Field::ENUM:
00133     return ENUM;
00134   case message::Table::Field::INTEGER:
00135     return INTEGER;
00136   case message::Table::Field::BIGINT:
00137     return BIGINT;
00138   case message::Table::Field::DECIMAL:
00139     return DECIMAL;
00140   case message::Table::Field::DATE:
00141     return DATE;
00142   case message::Table::Field::EPOCH:
00143     return TIMESTAMP;
00144   case message::Table::Field::DATETIME:
00145     return DATETIME;
00146   case message::Table::Field::TIME:
00147     return TIME;
00148   case message::Table::Field::UUID:
00149     return UUID;
00150   case message::Table::Field::BOOLEAN:
00151     return BOOLEAN;
00152   case message::Table::Field::IPV6:
00153     return IPV6;
00154   }
00155 
00156   abort();
00157 }
00158 
00159 const std::string &type(drizzled::message::Table::Field::FieldType type)
00160 {
00161   switch (type)
00162   {
00163   case message::Table::Field::VARCHAR:
00164     return VARCHAR;
00165   case message::Table::Field::DOUBLE:
00166     return DOUBLE;
00167   case message::Table::Field::BLOB:
00168     return BLOB;
00169   case message::Table::Field::ENUM:
00170     return ENUM;
00171   case message::Table::Field::INTEGER:
00172     return INTEGER;
00173   case message::Table::Field::BIGINT:
00174     return BIGINT;
00175   case message::Table::Field::DECIMAL:
00176     return DECIMAL;
00177   case message::Table::Field::DATE:
00178     return DATE;
00179   case message::Table::Field::EPOCH:
00180     return EPOCH;
00181   case message::Table::Field::DATETIME:
00182     return DATETIME;
00183   case message::Table::Field::TIME:
00184     return TIME;
00185   case message::Table::Field::UUID:
00186     return UUID;
00187   case message::Table::Field::BOOLEAN:
00188     return BOOLEAN;
00189   case message::Table::Field::IPV6:
00190     return IPV6;
00191   }
00192 
00193   abort();
00194 }
00195 
00196 const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
00197 {
00198   switch (type)
00199   {
00200   case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
00201     return RESTRICT;
00202   case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
00203     return CASCADE;
00204   case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
00205     return SET_NULL;
00206   case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
00207   case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
00208     return NO_ACTION;
00209   case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
00210     return SET_DEFAULT;
00211   }
00212 
00213   return NO_ACTION;
00214 }
00215 
00216 const std::string &type(drizzled::message::Table::Index::IndexType type)
00217 {
00218   switch (type)
00219   {
00220   case message::Table::Index::UNKNOWN_INDEX:
00221     return UNKNOWN_INDEX;
00222   case message::Table::Index::BTREE:
00223     return BTREE;
00224   case message::Table::Index::RTREE:
00225     return RTREE;
00226   case message::Table::Index::HASH:
00227     return HASH;
00228   case message::Table::Index::FULLTEXT:
00229     return FULLTEXT;
00230   }
00231 
00232   assert(0);
00233   return PROGRAM_ERROR;
00234 }
00235 
00236 const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
00237 {
00238   switch (type)
00239   {
00240   case message::Table::ForeignKeyConstraint::MATCH_FULL:
00241     return MATCH_FULL;
00242   case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
00243     return MATCH_PARTIAL;
00244   case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
00245   case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
00246     return MATCH_SIMPLE;
00247   }
00248 
00249   return MATCH_SIMPLE;
00250 }
00251 
00252 const std::string &type(drizzled::message::Table::TableType type)
00253 {
00254   switch (type)
00255   {
00256   case message::Table::STANDARD:
00257     return STANDARD_STRING;
00258   case message::Table::TEMPORARY:
00259     return TEMPORARY_STRING;
00260   case message::Table::INTERNAL:
00261     return INTERNAL_STRING;
00262   case message::Table::FUNCTION:
00263     return FUNCTION_STRING;
00264   }
00265 
00266   assert(0);
00267   return PROGRAM_ERROR;
00268 }
00269 
00270 #if 0
00271 std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
00272 { 
00273     std::string buffer;
00274 
00275     google::protobuf::TextFormat::PrintToString(message, &buffer);
00276     output << buffer;
00277 
00278     return output;
00279 }
00280 
00281 std::ostream& operator<<(std::ostream& output, const message::Table &message)
00282 { 
00283   std::string buffer;
00284 
00285   google::protobuf::TextFormat::PrintToString(message, &buffer);
00286   output << buffer;
00287 
00288   return output;
00289 }
00290 #endif
00291 
00292 
00293 } /* namespace message */
00294 } /* namespace drizzled */