Drizzled Public API Documentation

table.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 
00022 #include <config.h>
00023 #include <drizzled/message/table.h>
00024 #include <drizzled/charset_info.h>
00025 #include <drizzled/global_charset_info.h>
00026 #include <drizzled/catalog/local.h>
00027 
00028 namespace drizzled {
00029 namespace message {
00030 namespace table {
00031 
00032 shared_ptr make_shared(identifier::Table::const_reference identifier, const std::string &engine_arg)
00033 {
00034   shared_ptr shared(new message::Table);
00035 
00036   init(*shared, identifier.getTableName(), identifier.getSchemaName(), engine_arg);
00037 
00038   return shared;
00039 }
00040 
00041 shared_ptr make_shared(const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
00042 {
00043   shared_ptr shared(new message::Table);
00044 
00045   init(*shared, name_arg, schema_arg, engine_arg);
00046 
00047   return shared;
00048 }
00049 
00050 void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
00051 {
00052   arg.set_name(name_arg);
00053   arg.set_schema(schema_arg);
00054   arg.set_creation_timestamp(time(NULL));
00055   arg.set_update_timestamp(time(NULL));
00056   arg.mutable_engine()->set_name(engine_arg);
00057 
00058   /* 36 characters for uuid string +1 for NULL */
00059   uuid_t uu;
00060   char uuid_string[37];
00061   uuid_generate_random(uu);
00062   uuid_unparse(uu, uuid_string);
00063   arg.set_uuid(uuid_string, 36);
00064 
00065   arg.set_version(1);
00066 
00067   if (not arg.has_type())
00068   {
00069     arg.set_type(drizzled::message::Table::STANDARD);
00070   }
00071 
00072   arg.mutable_options()->set_collation_id(default_charset_info->number);
00073   arg.mutable_options()->set_collation(default_charset_info->name);
00074 
00075   arg.set_catalog(drizzled::catalog::local()->name());
00076 }
00077 
00078 void update(drizzled::message::Table &arg)
00079 {
00080   arg.set_version(arg.version() + 1);
00081   arg.set_update_timestamp(time(NULL));
00082 }
00083 
00084 } // namespace table
00085 } // namespace message
00086 } // namespace drizzled