192
memset(dbbuff, 0, sizeof(dbbuff));
193
conversion_error= tablename_to_filename(db, dbbuff, sizeof(dbbuff));
194
if (conversion_error)
196
errmsg_printf(ERRMSG_LVL_ERROR,
197
_("Schema name cannot be encoded and fit within filesystem "
198
"name length restrictions."));
203
int rootdir_len= strlen(FN_ROOTDIR);
204
path.append(drizzle_data_home);
205
ssize_t without_rootdir= path.length() - rootdir_len;
207
/* Don't add FN_ROOTDIR if dirzzle_data_home already includes it */
208
if (without_rootdir >= 0)
210
const char *tmp= path.c_str() + without_rootdir;
212
if (memcmp(tmp, FN_ROOTDIR, rootdir_len) != 0)
213
path.append(FN_ROOTDIR);
217
path.append(FN_ROOTDIR);
220
return path.length();
225
Translate a table name to a cursor name (WL #1324).
228
tablename_to_filename()
230
to OUT The cursor name
231
to_length The size of the cursor name buffer.
234
true if errors happen. false on success.
236
static bool tablename_to_filename(const char *from, char *to, size_t to_length)
240
for (; *from && length < to_length; length++, from++)
242
if ((*from >= '0' && *from <= '9') ||
243
(*from >= 'A' && *from <= 'Z') ||
244
(*from >= 'a' && *from <= 'z') ||
245
/* OSX defines an extra set of high-bit and multi-byte characters
246
that cannot be used on the filesystem. Instead of trying to sort
247
those out, we'll just escape encode all high-bit-set chars on OSX.
248
It won't really hurt anything - it'll just make some filenames ugly. */
249
#if !defined(TARGET_OS_OSX)
250
((unsigned char)*from >= 128) ||
256
to[length]= tolower(*from);
260
if (length + 3 >= to_length)
263
/* We need to escape this char in a way that can be reversed */
265
to[length++]= hexchars[(*from >> 4) & 15];
266
to[length]= hexchars[(*from) & 15];
269
if (internal::check_if_legal_tablename(to) &&
270
length + 4 < to_length)
272
memcpy(to + length, "@@@", 4);
278
TableIdentifier::TableIdentifier(const drizzled::Table &table) :
279
SchemaIdentifier(table.s->getTableProto()->schema()),
280
type(table.s->getTableProto()->type()),
281
table_name(table.s->getTableProto()->name())
244
return in_path.length();
247
Table::Table(const drizzled::Table &table) :
248
identifier::Schema(table.getShare()->getSchemaName()),
249
type(table.getShare()->getTableType()),
250
table_name(table.getShare()->getTableName())
283
252
if (type == message::Table::TEMPORARY)
284
path= table.s->path.str;
253
path= table.getShare()->getPath();
289
void TableIdentifier::init()
291
lower_table_name.append(table_name);
292
std::transform(lower_table_name.begin(), lower_table_name.end(),
293
lower_table_name.begin(), ::tolower);
297
const std::string &TableIdentifier::getPath()
299
assert(not lower_table_name.empty());
304
case message::Table::STANDARD:
305
build_table_filename(path, getLower().c_str(), lower_table_name.c_str(), false);
307
case message::Table::INTERNAL:
308
build_table_filename(path, getLower().c_str(), lower_table_name.c_str(), true);
310
case message::Table::TEMPORARY:
261
case message::Table::FUNCTION:
262
case message::Table::STANDARD:
263
assert(path.size() == 0);
264
build_table_filename(path, getSchemaName(), table_name, false);
266
case message::Table::INTERNAL:
267
assert(path.size() == 0);
268
build_table_filename(path, getSchemaName(), table_name, true);
270
case message::Table::TEMPORARY:
311
273
build_tmptable_filename(path);
313
case message::Table::FUNCTION:
314
path.append(getSchemaName());
316
path.append(table_name);
319
assert(path.length()); // TODO throw exception, this is a possibility
278
util::insensitive_hash hasher;
279
hash_value= hasher(path);
281
std::string tb_name(getTableName());
282
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
284
key.set(getKeySize(), getSchemaName(), tb_name);
288
const std::string &Table::getPath() const
325
bool TableIdentifier::compare(std::string schema_arg, std::string table_arg)
327
std::transform(schema_arg.begin(), schema_arg.end(),
328
schema_arg.begin(), ::tolower);
330
std::transform(table_arg.begin(), table_arg.end(),
331
table_arg.begin(), ::tolower);
333
if (schema_arg == getLower() && table_arg == lower_table_name)
341
const std::string &TableIdentifier::getSQLPath()
343
if (sql_path.empty())
346
case message::Table::FUNCTION:
347
case message::Table::STANDARD:
348
sql_path.append(getLower());
349
sql_path.append(".");
350
sql_path.append(table_name);
352
case message::Table::INTERNAL:
353
sql_path.append("temporary.");
354
sql_path.append(table_name);
356
case message::Table::TEMPORARY:
357
sql_path.append(getLower());
358
sql_path.append(".#");
359
sql_path.append(table_name);
368
void TableIdentifier::copyToTableMessage(message::Table &message)
293
void Table::getSQLPath(std::string &sql_path) const // @todo this is just used for errors, we should find a way to optimize it
296
case message::Table::FUNCTION:
297
case message::Table::STANDARD:
298
sql_path.append(getSchemaName());
299
sql_path.append(".");
300
sql_path.append(table_name);
302
case message::Table::INTERNAL:
303
sql_path.append("temporary.");
304
sql_path.append(table_name);
306
case message::Table::TEMPORARY:
307
sql_path.append(getSchemaName());
308
sql_path.append(".#");
309
sql_path.append(table_name);
314
bool Table::isValid() const
316
if (not identifier::Schema::isValid())
322
if (table_name.empty())
328
if (table_name.size() > NAME_LEN)
334
if (table_name.at(table_name.length() -1) == ' ')
340
if (table_name.at(0) == '.')
347
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
349
int well_formed_error;
350
uint32_t res= cs->cset->well_formed_len(cs, table_name.c_str(), table_name.c_str() + table_name.length(),
351
NAME_CHAR_LEN, &well_formed_error);
352
if (well_formed_error or table_name.length() != res)
365
my_error(ER_WRONG_TABLE_NAME, MYF(0), name.c_str());
374
void Table::copyToTableMessage(message::Table &message) const
370
376
message.set_name(table_name);
371
377
message.set_schema(getSchemaName());
380
void Table::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
382
key_buffer.resize(resize_arg);
384
std::copy(a.begin(), a.end(), key_buffer.begin());
385
std::copy(b.begin(), b.end(), key_buffer.begin() + a.length() + 1);
387
util::sensitive_hash hasher;
388
hash_value= hasher(key_buffer);
391
std::size_t hash_value(Table const& b)
393
return b.getHashValue();
396
std::size_t hash_value(Table::Key const& b)
398
return b.getHashValue();
401
} /* namespace identifier */
374
402
} /* namespace drizzled */