Drizzled Public API Documentation

catalog.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 #include <cassert>
00023 #include <drizzled/errmsg_print.h>
00024 #include <drizzled/gettext.h>
00025 #include <drizzled/identifier.h>
00026 #include <drizzled/session.h>
00027 #include <drizzled/internal/my_sys.h>
00028 
00029 #include <drizzled/util/tablename_to_filename.h>
00030 #include <drizzled/util/backtrace.h>
00031 #include <drizzled/charset.h>
00032 
00033 #include <algorithm>
00034 #include <sstream>
00035 #include <cstdio>
00036 
00037 #include <boost/algorithm/string/compare.hpp>
00038 
00039 using namespace std;
00040 
00041 namespace drizzled {
00042 namespace identifier {
00043 
00044 Catalog::Catalog(str_ref name_arg) :
00045   _name(name_arg.data(), name_arg.size())
00046 { 
00047   init();
00048 }
00049 
00050 void Catalog::init()
00051 { 
00052   assert(not _name.empty());
00053   path += "../";
00054   path += util::tablename_to_filename(_name);
00055   assert(path.length()); // TODO throw exception, this is a possibility
00056   hash_value= util::insensitive_hash()(path);
00057 }
00058 
00059 bool Catalog::compare(const std::string &arg) const
00060 {
00061   return boost::iequals(arg, _name);
00062 }
00063 
00064 bool Catalog::isValid() const
00065 {
00066   if (_name.empty()
00067     || _name.size() > NAME_LEN
00068     || _name.at(_name.length() -1 ) == ' ')
00069     return false;
00070   const charset_info_st& cs= my_charset_utf8mb4_general_ci;
00071   int well_formed_error;
00072   uint32_t res= cs.cset->well_formed_len(cs, _name, NAME_CHAR_LEN, &well_formed_error);
00073   if (well_formed_error)
00074   {
00075     my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
00076     return false;
00077   }
00078   if (_name.length() != res)
00079     return false;
00080   return true;
00081 }
00082 
00083 } /* namespace identifier */
00084 } /* namespace drizzled */