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
00023 #include <assert.h>
00024
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
00032 #include <algorithm>
00033 #include <sstream>
00034 #include <cstdio>
00035
00036 #include <boost/algorithm/string/compare.hpp>
00037
00038 using namespace std;
00039
00040 namespace drizzled
00041 {
00042
00043 namespace identifier
00044 {
00045
00046 static void build_schema_filename(string &path, const string &name_arg)
00047 {
00048 path.append("../");
00049 bool conversion_error= false;
00050
00051 conversion_error= util::tablename_to_filename(name_arg, path);
00052 if (conversion_error)
00053 {
00054 errmsg_printf(error::ERROR,
00055 _("Catalog name cannot be encoded and fit within filesystem "
00056 "name length restrictions."));
00057 }
00058 }
00059
00060 Catalog::Catalog(const std::string &name_arg) :
00061 _name(name_arg)
00062 {
00063 init();
00064 }
00065
00066 Catalog::Catalog(const drizzled::LEX_STRING &name_arg) :
00067 _name(name_arg.str, name_arg.length)
00068 {
00069 init();
00070 }
00071
00072 void Catalog::init()
00073 {
00074 assert(not _name.empty());
00075
00076 build_schema_filename(path, _name);
00077 assert(path.length());
00078
00079 util::insensitive_hash hasher;
00080 hash_value= hasher(path);
00081 }
00082
00083 const std::string &Catalog::getPath() const
00084 {
00085 return path;
00086 }
00087
00088 bool Catalog::compare(const std::string &arg) const
00089 {
00090 return boost::iequals(arg, _name);
00091 }
00092
00093 bool Catalog::isValid() const
00094 {
00095 if (_name.empty())
00096 return false;
00097
00098 if (_name.size() > NAME_LEN)
00099 return false;
00100
00101 if (_name.at(_name.length() -1) == ' ')
00102 return false;
00103
00104 const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
00105
00106 int well_formed_error;
00107 uint32_t res= cs->cset->well_formed_len(cs, _name.c_str(), _name.c_str() + _name.length(),
00108 NAME_CHAR_LEN, &well_formed_error);
00109
00110 if (well_formed_error)
00111 {
00112 my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
00113 return false;
00114 }
00115
00116 if (_name.length() != res)
00117 return false;
00118
00119 return true;
00120 }
00121
00122 std::size_t hash_value(Catalog const& b)
00123 {
00124 return b.getHashValue();
00125 }
00126
00127 void Catalog::getSQLPath(std::string &sql_path) const
00128 {
00129 sql_path= _name;
00130 }
00131
00132
00133
00134 }
00135 }