Drizzled Public API Documentation

catalog.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Brian Aker
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 #include <cassert>
23 #include <drizzled/errmsg_print.h>
24 #include <drizzled/gettext.h>
25 #include <drizzled/identifier.h>
26 #include <drizzled/session.h>
27 #include <drizzled/internal/my_sys.h>
28 
29 #include <drizzled/util/tablename_to_filename.h>
30 #include <drizzled/util/backtrace.h>
31 #include <drizzled/charset.h>
32 
33 #include <algorithm>
34 #include <sstream>
35 #include <cstdio>
36 
37 #include <boost/algorithm/string/compare.hpp>
38 
39 using namespace std;
40 
41 namespace drizzled {
42 namespace identifier {
43 
44 Catalog::Catalog(str_ref name_arg) :
45  _name(name_arg.data(), name_arg.size())
46 {
47  init();
48 }
49 
50 void Catalog::init()
51 {
52  assert(not _name.empty());
53  path.clear();
54  path += util::tablename_to_filename(_name);
55  assert(path.length()); // TODO throw exception, this is a possibility
56  hash_value= util::insensitive_hash()(path);
57 }
58 
59 bool Catalog::compare(const std::string &arg) const
60 {
61  return boost::iequals(arg, _name);
62 }
63 
64 bool Catalog::isValid() const
65 {
66  if (_name.empty()
67  || _name.size() > NAME_LEN
68  || _name.at(_name.length() -1 ) == ' ')
69  return false;
70  const charset_info_st& cs= my_charset_utf8mb4_general_ci;
71  int well_formed_error;
72  uint32_t res= cs.cset->well_formed_len(cs, _name, NAME_CHAR_LEN, &well_formed_error);
73  if (well_formed_error)
74  {
75  my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
76  return false;
77  }
78  if (_name.length() != res)
79  return false;
80  return true;
81 }
82 
83 } /* namespace identifier */
84 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.