00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <cassert>
00023 #include <drizzled/errmsg_print.h>
00024 #include <drizzled/gettext.h>
00025 #include <drizzled/identifier.h>
00026 #include <drizzled/session.h>
00027 #include <drizzled/internal/my_sys.h>
00028 #include <drizzled/catalog/local.h>
00029 #include <drizzled/util/tablename_to_filename.h>
00030 #include <drizzled/util/backtrace.h>
00031 #include <drizzled/charset.h>
00032
00033 #include <algorithm>
00034 #include <sstream>
00035 #include <cstdio>
00036
00037 #include <boost/algorithm/string/compare.hpp>
00038
00039 using namespace std;
00040
00041 namespace drizzled {
00042 namespace identifier {
00043
00044 Schema::Schema(str_ref db_arg) :
00045 db(db_arg.data(), db_arg.size())
00046 {
00047 #if 0
00048 string::size_type lastPos= db.find_first_of('/', 0);
00049
00050 if (lastPos != std::string::npos)
00051 {
00052 catalog= db.substr(0, lastPos);
00053 db.erase(0, lastPos + 1);
00054 }
00055 #endif
00056
00057 if (not db_arg.empty())
00058 {
00059 db_path += util::tablename_to_filename(db);
00060 assert(db_path.length());
00061 }
00062 }
00063
00064 const std::string &Schema::getPath() const
00065 {
00066 return db_path;
00067 }
00068
00069 bool Schema::compare(const std::string &arg) const
00070 {
00071 return boost::iequals(arg, db);
00072 }
00073
00074 bool Schema::compare(const Schema& arg) const
00075 {
00076 return boost::iequals(arg.getSchemaName(), db);
00077 }
00078
00079 bool Schema::isValid() const
00080 {
00081 const charset_info_st& cs= my_charset_utf8mb4_general_ci;
00082 int well_formed_error;
00083 if (not db.empty()
00084 && db.size() <= NAME_LEN
00085 && db.at(0) != '.'
00086 && db.at(db.size() - 1) != ' '
00087 && db.size() == cs.cset->well_formed_len(cs, db, NAME_CHAR_LEN, &well_formed_error))
00088 {
00089 if (not well_formed_error)
00090 return true;
00091 }
00092 my_error(ER_WRONG_DB_NAME, *this);
00093 return false;
00094 }
00095
00096 const std::string &Schema::getCatalogName() const
00097 {
00098 return drizzled::catalog::local_identifier().name();
00099 }
00100
00101 std::ostream& operator<<(std::ostream& output, const Schema&identifier)
00102 {
00103 return output << "identifier::Schema:(" << drizzled::catalog::local_identifier() << ", " << identifier.getSchemaName() << ", " << identifier.getPath() << ")";
00104 }
00105
00106 }
00107 }