44
41
extern string drizzle_tmpdir;
45
42
extern pid_t current_pid;
44
static const char hexchars[]= "0123456789abcdef";
46
static bool tablename_to_filename(const string &from, string &to);
47
48
static size_t build_schema_filename(string &path, const string &db)
50
51
bool conversion_error= false;
52
conversion_error= util::tablename_to_filename(db, path);
53
conversion_error= tablename_to_filename(db, dbbuff);
53
54
if (conversion_error)
55
56
errmsg_printf(ERRMSG_LVL_ERROR,
57
58
"name length restrictions."));
61
65
return path.length();
70
Translate a table name to a cursor name (WL #1324).
73
tablename_to_filename()
75
to OUT The cursor name
78
true if errors happen. false on success.
80
static bool tablename_to_filename(const string &from, string &to)
83
string::const_iterator iter= from.begin();
84
for (; iter != from.end(); ++iter)
86
if ((*iter >= '0' && *iter <= '9') ||
87
(*iter >= 'a' && *iter <= 'z') ||
88
/* OSX defines an extra set of high-bit and multi-byte characters
89
that cannot be used on the filesystem. Instead of trying to sort
90
those out, we'll just escape encode all high-bit-set chars on OSX.
91
It won't really hurt anything - it'll just make some filenames ugly. */
92
#if !defined(TARGET_OS_OSX)
93
((unsigned char)*iter >= 128) ||
103
if ((*iter >= 'A' && *iter <= 'Z'))
105
to.push_back(tolower(*iter));
109
/* We need to escape this char in a way that can be reversed */
111
to.push_back(hexchars[(*iter >> 4) & 15]);
112
to.push_back(hexchars[(*iter) & 15]);
115
if (internal::check_if_legal_tablename(to.c_str()))
64
122
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
70
string::size_type lastPos= db.find_first_of('/', 0);
72
if (lastPos != std::string::npos)
74
catalog= db.substr(0, lastPos);
75
db.erase(0, lastPos + 1);
79
126
if (not db_arg.empty())
81
128
drizzled::build_schema_filename(db_path, db);
98
145
return boost::iequals(arg, db);
101
bool SchemaIdentifier::compare(SchemaIdentifier::const_reference arg) const
103
return boost::iequals(arg.getSchemaName(), db);
106
148
bool SchemaIdentifier::isValid() const
118
if (db.size() > NAME_LEN)
124
if (db.at(db.length() -1) == ' ')
137
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
139
int well_formed_error;
140
uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
141
NAME_CHAR_LEN, &well_formed_error);
142
if (well_formed_error or db.length() != res)
155
my_error(ER_WRONG_DB_NAME, MYF(0), name.c_str());
153
if (db.size() > NAME_LEN)
156
if (db.at(db.length() -1) == ' ')
159
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
161
int well_formed_error;
162
uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
163
NAME_CHAR_LEN, &well_formed_error);
165
if (well_formed_error)
167
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", db.c_str());
171
if (db.length() != res)