23 #include <drizzled/errmsg_print.h>
24 #include <drizzled/gettext.h>
25 #include <drizzled/identifier.h>
26 #include <drizzled/session.h>
27 #include <drizzled/internal/my_sys.h>
28 #include <drizzled/catalog/local.h>
29 #include <drizzled/util/tablename_to_filename.h>
30 #include <drizzled/util/backtrace.h>
31 #include <drizzled/charset.h>
37 #include <boost/algorithm/string/compare.hpp>
42 namespace identifier {
44 Schema::Schema(
str_ref db_arg) :
45 db(db_arg.data(), db_arg.size())
48 string::size_type lastPos= db.find_first_of(
'/', 0);
50 if (lastPos != std::string::npos)
52 catalog= db.substr(0, lastPos);
53 db.erase(0, lastPos + 1);
57 if (db_arg.empty() ==
false)
59 db_path += util::tablename_to_filename(db);
60 assert(db_path.length());
63 _corrected_db= boost::to_lower_copy(db);
66 const std::string &Schema::getPath()
const
71 bool Schema::compare(
const std::string &arg)
const
73 return boost::iequals(arg, db);
76 bool Schema::compare(
const Schema& arg)
const
78 return boost::iequals(arg.getSchemaName(), db);
81 bool Schema::isValid()
const
83 const charset_info_st& cs= my_charset_utf8mb4_general_ci;
84 int well_formed_error;
86 && db.size() <= NAME_LEN
88 && db.at(db.size() - 1) !=
' '
89 && db.size() == cs.cset->well_formed_len(cs, db, NAME_CHAR_LEN, &well_formed_error))
91 if (not well_formed_error)
94 my_error(ER_WRONG_DB_NAME, *
this);
98 const std::string &Schema::getCatalogName()
const
100 return drizzled::catalog::local_identifier().name();
103 std::ostream& operator<<(std::ostream& output,
const Schema&identifier)
105 return output <<
"identifier::Schema:(" << drizzled::catalog::local_identifier() <<
", " << identifier.getSchemaName() <<
", " << identifier.getPath() <<
")";