23
23
#include <assert.h>
24
24
#include <boost/lexical_cast.hpp>
25
25
#include "drizzled/identifier.h"
26
#include "drizzled/session.h"
26
27
#include "drizzled/internal/my_sys.h"
28
#include <drizzled/error.h>
29
#include <drizzled/errmsg_print.h>
30
#include <drizzled/gettext.h>
32
#include <drizzled/table.h>
29
#include "drizzled/table.h"
34
31
#include "drizzled/util/string.h"
35
32
#include "drizzled/util/tablename_to_filename.h"
210
202
path length on success, 0 on failure
213
size_t Table::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
205
size_t TableIdentifier::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
215
207
bool conversion_error= false;
217
209
conversion_error= util::tablename_to_filename(in_db, in_path);
218
210
if (conversion_error)
220
errmsg_printf(error::ERROR,
212
errmsg_printf(ERRMSG_LVL_ERROR,
221
213
_("Schema name cannot be encoded and fit within filesystem "
222
214
"name length restrictions."));
279
case message::Table::FUNCTION:
280
case message::Table::STANDARD:
281
case message::Table::INTERNAL:
283
case message::Table::TEMPORARY:
287
pos= path.find("tmp/#sql");
288
if (pos != std::string::npos)
290
key_path= path.substr(pos);
296
270
util::insensitive_hash hasher;
297
271
hash_value= hasher(path);
299
std::string tb_name(getTableName());
300
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
302
key.set(getKeySize(), getSchemaName(), tb_name);
273
key.set(getKeySize(), getSchemaName(), getTableName());
306
const std::string &Table::getPath() const
277
const std::string &TableIdentifier::getPath() const
311
const std::string &Table::getKeyPath() const
313
if (key_path.empty())
319
void Table::getSQLPath(std::string &sql_path) const // @todo this is just used for errors, we should find a way to optimize it
322
case message::Table::FUNCTION:
323
case message::Table::STANDARD:
324
sql_path.append(getSchemaName());
325
sql_path.append(".");
326
sql_path.append(table_name);
328
case message::Table::INTERNAL:
329
sql_path.append("temporary.");
330
sql_path.append(table_name);
332
case message::Table::TEMPORARY:
333
sql_path.append(getSchemaName());
334
sql_path.append(".#");
335
sql_path.append(table_name);
340
bool Table::isValid() const
342
if (not identifier::Schema::isValid())
348
if (table_name.empty())
354
if (table_name.size() > NAME_LEN)
360
if (table_name.at(table_name.length() -1) == ' ')
366
if (table_name.at(0) == '.')
373
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
375
int well_formed_error;
376
uint32_t res= cs->cset->well_formed_len(cs, table_name.c_str(), table_name.c_str() + table_name.length(),
377
NAME_CHAR_LEN, &well_formed_error);
378
if (well_formed_error or table_name.length() != res)
391
my_error(ER_WRONG_TABLE_NAME, MYF(0), name.c_str());
400
void Table::copyToTableMessage(message::Table &message) const
282
const std::string &TableIdentifier::getSQLPath() // @todo this is just used for errors, we should find a way to optimize it
284
if (sql_path.empty())
287
case message::Table::FUNCTION:
288
case message::Table::STANDARD:
289
sql_path.append(getSchemaName());
290
sql_path.append(".");
291
sql_path.append(table_name);
293
case message::Table::INTERNAL:
294
sql_path.append("temporary.");
295
sql_path.append(table_name);
297
case message::Table::TEMPORARY:
298
sql_path.append(getSchemaName());
299
sql_path.append(".#");
300
sql_path.append(table_name);
309
void TableIdentifier::copyToTableMessage(message::Table &message) const
402
311
message.set_name(table_name);
403
312
message.set_schema(getSchemaName());
406
void Table::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
315
void TableIdentifier::Key::set(size_t resize_arg, const std::string &a, const std::string &b)
408
317
key_buffer.resize(resize_arg);
414
323
hash_value= hasher(key_buffer);
417
std::size_t hash_value(Table const& b)
419
return b.getHashValue();
422
std::size_t hash_value(Table::Key const& b)
424
return b.getHashValue();
428
std::ostream& operator<<(std::ostream& output, Table::const_reference identifier)
431
output << identifier.getSchemaName();
433
output << identifier.getTableName();
435
output << message::type(identifier.getType());
437
output << identifier.getPath();
439
output << identifier.getHashValue();
442
return output; // for multiple << operators.
445
} /* namespace identifier */
326
std::size_t hash_value(TableIdentifier const& b)
328
return b.getHashValue();
331
std::size_t hash_value(TableIdentifier::Key const& b)
333
return b.getHashValue();
446
336
} /* namespace drizzled */