Drizzled Public API Documentation

schema.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 
00024 #include <uuid/uuid.h>
00025 
00026 #include <drizzled/show.h>
00027 #include <drizzled/message/schema.h>
00028 #include <drizzled/session.h>
00029 #include <drizzled/charset_info.h>
00030 
00031 #include <drizzled/catalog/local.h>
00032 
00033 namespace drizzled {
00034 namespace message {
00035 namespace schema {
00036 
00037 shared_ptr make_shared(identifier::Schema::const_reference identifier)
00038 {
00039   shared_ptr shared(new message::Schema);
00040 
00041   init(*shared, identifier.getSchemaName());
00042 
00043   return shared;
00044 }
00045 
00046 shared_ptr make_shared(const std::string &name_arg)
00047 {
00048   shared_ptr shared(new message::Schema);
00049 
00050   init(*shared, name_arg);
00051 
00052   return shared;
00053 }
00054 
00055 void init(drizzled::message::Schema &arg, const std::string &name_arg)
00056 {
00057   arg.set_name(name_arg);
00058   arg.set_catalog(drizzled::catalog::local()->name());
00059   arg.mutable_engine()->set_name(std::string("filesystem")); // For the moment we have only one.
00060   arg.set_creation_timestamp(time(NULL));
00061   arg.set_update_timestamp(time(NULL));
00062   if (not arg.has_collation())
00063   {
00064     arg.set_collation(default_charset_info->name);
00065   }
00066 
00067   /* 36 characters for uuid string +1 for NULL */
00068   uuid_t uu;
00069   char uuid_string[37];
00070   uuid_generate_random(uu);
00071   uuid_unparse(uu, uuid_string);
00072   arg.set_uuid(uuid_string, 36);
00073 
00074   arg.set_version(1);
00075 }
00076 
00077 } // namespace schema
00078 } // namespace message
00079 } // namespace drizzled