1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
25
#include "drizzled/identifier.h"
26
#include "drizzled/session.h"
27
#include "drizzled/current_session.h"
28
#include "drizzled/internal/my_sys.h"
30
#include "drizzled/util/tablename_to_filename.h"
31
#include "drizzled/util/backtrace.h"
37
#include <boost/algorithm/string/compare.hpp>
47
static void build_schema_filename(string &path, const string &name_arg)
50
bool conversion_error= false;
52
conversion_error= util::tablename_to_filename(name_arg, path);
55
errmsg_printf(ERRMSG_LVL_ERROR,
56
_("Catalog name cannot be encoded and fit within filesystem "
57
"name length restrictions."));
61
Catalog::Catalog(const std::string &name_arg) :
64
assert(not name_arg.empty());
66
build_schema_filename(path, _name);
67
assert(path.length()); // TODO throw exception, this is a possibility
69
util::insensitive_hash hasher;
70
hash_value= hasher(path);
73
const std::string &Catalog::getPath() const
78
bool Catalog::compare(const std::string &arg) const
80
return boost::iequals(arg, _name);
83
bool Catalog::isValid() const
88
if (_name.size() > NAME_LEN)
91
if (_name.at(_name.length() -1) == ' ')
94
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
96
int well_formed_error;
97
uint32_t res= cs->cset->well_formed_len(cs, _name.c_str(), _name.c_str() + _name.length(),
98
NAME_CHAR_LEN, &well_formed_error);
100
if (well_formed_error)
102
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
106
if (_name.length() != res)
112
std::size_t hash_value(Catalog const& b)
114
return b.getHashValue();
118
} /* namespace identifier */
119
} /* namespace drizzled */