00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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());
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 }
00084 }