1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
4
* Copyright (C) 2009 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
23
#include <assert.h>
25
#include <drizzled/identifier.h>
26
#include <drizzled/session.h>
27
#include <drizzled/internal/my_sys.h>
25
#include "drizzled/identifier.h"
26
#include "drizzled/session.h"
27
#include "drizzled/current_session.h"
28
#include "drizzled/internal/my_sys.h"
29
#include <drizzled/util/tablename_to_filename.h>
30
#include <drizzled/util/backtrace.h>
30
#include "drizzled/util/backtrace.h"
32
32
#include <algorithm>
46
43
extern string drizzle_tmpdir;
44
extern pid_t current_pid;
46
static const char hexchars[]= "0123456789abcdef";
48
static bool tablename_to_filename(const string &from, string &to);
48
50
static size_t build_schema_filename(string &path, const string &db)
51
53
bool conversion_error= false;
53
conversion_error= util::tablename_to_filename(db, path);
55
conversion_error= tablename_to_filename(db, path);
54
56
if (conversion_error)
56
errmsg_printf(error::ERROR,
58
errmsg_printf(ERRMSG_LVL_ERROR,
57
59
_("Schema name cannot be encoded and fit within filesystem "
58
60
"name length restrictions."));
62
64
return path.length();
65
Schema::Schema(const std::string &db_arg) :
69
Translate a table name to a cursor name (WL #1324).
72
tablename_to_filename()
74
to OUT The cursor name
77
true if errors happen. false on success.
79
static bool tablename_to_filename(const string &from, string &to)
82
string::const_iterator iter= from.begin();
83
for (; iter != from.end(); ++iter)
87
if ((isdigit(*iter)) ||
99
to.push_back(tolower(*iter));
104
/* We need to escape this char in a way that can be reversed */
106
to.push_back(hexchars[(*iter >> 4) & 15]);
107
to.push_back(hexchars[(*iter) & 15]);
110
if (internal::check_if_legal_tablename(to.c_str()))
117
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
70
123
string::size_type lastPos= db.find_first_of('/', 0);
79
132
if (not db_arg.empty())
81
build_schema_filename(db_path, db);
134
drizzled::build_schema_filename(db_path, db);
82
135
assert(db_path.length()); // TODO throw exception, this is a possibility
86
void Schema::getSQLPath(std::string &arg) const
139
const std::string &SchemaIdentifier::getSQLPath()
141
return getSchemaName();
91
const std::string &Schema::getPath() const
144
const std::string &SchemaIdentifier::getPath() const
96
bool Schema::compare(const std::string &arg) const
149
bool SchemaIdentifier::compare(const std::string &arg) const
98
151
return boost::iequals(arg, db);
101
bool Schema::compare(Schema::const_reference arg) const
103
return boost::iequals(arg.getSchemaName(), db);
106
bool Schema::isValid() const
118
if (db.size() > NAME_LEN)
124
if (db.at(db.length() -1) == ' ')
137
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
139
int well_formed_error;
140
uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
141
NAME_CHAR_LEN, &well_formed_error);
142
if (well_formed_error or db.length() != res)
152
my_error(ER_WRONG_DB_NAME, *this);
154
bool SchemaIdentifier::isValid() const
159
if (db.size() > NAME_LEN)
162
if (db.at(db.length() -1) == ' ')
165
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
167
int well_formed_error;
168
uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
169
NAME_CHAR_LEN, &well_formed_error);
171
if (well_formed_error)
173
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", db.c_str());
177
if (db.length() != res)
160
const std::string &Schema::getCatalogName() const
162
return drizzled::catalog::local_identifier().name();
165
std::ostream& operator<<(std::ostream& output, const Schema&identifier)
167
output << "identifier::Schema:(";
168
output << catalog::local_identifier();
170
output << identifier.getSchemaName().c_str();
172
output << identifier.getPath().c_str();
175
return output; // for multiple << operators.
178
} /* namespace identifier */
179
183
} /* namespace drizzled */