45
class SchemaIdentifier;
47
44
extern std::string drizzle_tmpdir;
48
45
extern pid_t current_pid;
50
47
static const char hexchars[]= "0123456789abcdef";
49
static bool tablename_to_filename(const string &from, string &to);
53
52
Translate a cursor name to a table name (WL #1324).
204
203
path length on success, 0 on failure
207
size_t TableIdentifier::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
206
size_t TableIdentifier::build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp)
209
208
bool conversion_error= false;
211
conversion_error= util::tablename_to_filename(in_db, in_path);
210
conversion_error= tablename_to_filename(db, path);
212
211
if (conversion_error)
214
213
errmsg_printf(ERRMSG_LVL_ERROR,
220
in_path.append(FN_ROOTDIR);
219
path.append(FN_ROOTDIR);
222
221
if (is_tmp) // It a conversion tmp
224
in_path.append(in_table_name);
223
path.append(table_name);
228
conversion_error= util::tablename_to_filename(in_table_name, in_path);
227
conversion_error= tablename_to_filename(table_name, path);
229
228
if (conversion_error)
231
230
errmsg_printf(ERRMSG_LVL_ERROR,
238
return in_path.length();
237
return path.length();
242
Translate a table name to a cursor name (WL #1324).
245
tablename_to_filename()
247
to OUT The cursor name
248
to_length The size of the cursor name buffer.
251
true if errors happen. false on success.
253
static bool tablename_to_filename(const string &from, string &to)
256
string::const_iterator iter= from.begin();
257
for (; iter != from.end(); ++iter)
261
if ((isdigit(*iter)) ||
273
to.push_back(tolower(*iter));
278
/* We need to escape this char in a way that can be reversed */
280
to.push_back(hexchars[(*iter >> 4) & 15]);
281
to.push_back(hexchars[(*iter) & 15]);
284
if (internal::check_if_legal_tablename(to.c_str()))
241
291
TableIdentifier::TableIdentifier(const drizzled::Table &table) :
272
322
util::insensitive_hash hasher;
273
323
hash_value= hasher(path);
275
std::string tb_name(getTableName());
276
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
325
key.resize(getKeySize());
278
key.set(getKeySize(), getSchemaName(), tb_name);
327
std::copy(getSchemaName().begin(), getSchemaName().end(), key.begin());
328
std::copy(getTableName().begin(), getTableName().end(), key.begin() + getSchemaName().length() + 1);
287
void TableIdentifier::getSQLPath(std::string &sql_path) const // @todo this is just used for errors, we should find a way to optimize it
290
case message::Table::FUNCTION:
291
case message::Table::STANDARD:
292
sql_path.append(getSchemaName());
293
sql_path.append(".");
294
sql_path.append(table_name);
296
case message::Table::INTERNAL:
297
sql_path.append("temporary.");
298
sql_path.append(table_name);
300
case message::Table::TEMPORARY:
301
sql_path.append(getSchemaName());
302
sql_path.append(".#");
303
sql_path.append(table_name);
308
bool TableIdentifier::isValid() const
310
if (not SchemaIdentifier::isValid())
316
if (table_name.empty())
322
if (table_name.size() > NAME_LEN)
328
if (table_name.at(table_name.length() -1) == ' ')
334
if (table_name.at(0) == '.')
341
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
343
int well_formed_error;
344
uint32_t res= cs->cset->well_formed_len(cs, table_name.c_str(), table_name.c_str() + table_name.length(),
345
NAME_CHAR_LEN, &well_formed_error);
346
if (well_formed_error or table_name.length() != res)
359
my_error(ER_WRONG_TABLE_NAME, MYF(0), name.c_str());
337
const std::string &TableIdentifier::getSQLPath() // @todo this is just used for errors, we should find a way to optimize it
339
if (sql_path.empty())
342
case message::Table::FUNCTION:
343
case message::Table::STANDARD:
344
sql_path.append(getSchemaName());
345
sql_path.append(".");
346
sql_path.append(table_name);
348
case message::Table::INTERNAL:
349
sql_path.append("temporary.");
350
sql_path.append(table_name);
352
case message::Table::TEMPORARY:
353
sql_path.append(getSchemaName());
354
sql_path.append(".#");
355
sql_path.append(table_name);
371
367
message.set_schema(getSchemaName());
374
void TableIdentifier::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
376
key_buffer.resize(resize_arg);
378
std::copy(a.begin(), a.end(), key_buffer.begin());
379
std::copy(b.begin(), b.end(), key_buffer.begin() + a.length() + 1);
381
util::sensitive_hash hasher;
382
hash_value= hasher(key_buffer);
385
370
std::size_t hash_value(TableIdentifier const& b)
387
372
return b.getHashValue();
390
std::size_t hash_value(TableIdentifier::Key const& b)
392
return b.getHashValue();
395
375
} /* namespace drizzled */