~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/identifier/catalog.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include <config.h>
22
 
 
23
 
#include <assert.h>
24
 
 
 
22
#include <cassert>
 
23
#include <drizzled/errmsg_print.h>
 
24
#include <drizzled/gettext.h>
25
25
#include <drizzled/identifier.h>
26
26
#include <drizzled/session.h>
27
27
#include <drizzled/internal/my_sys.h>
28
28
 
29
29
#include <drizzled/util/tablename_to_filename.h>
30
30
#include <drizzled/util/backtrace.h>
 
31
#include <drizzled/charset.h>
31
32
 
32
33
#include <algorithm>
33
34
#include <sstream>
37
38
 
38
39
using namespace std;
39
40
 
40
 
namespace drizzled
41
 
{
42
 
 
43
 
namespace identifier
44
 
{
45
 
 
46
 
static void build_schema_filename(string &path, const string &name_arg)
47
 
{
48
 
  path.append("../");
49
 
  bool conversion_error= false;
50
 
 
51
 
  conversion_error= util::tablename_to_filename(name_arg, path);
52
 
  if (conversion_error)
53
 
  {
54
 
    errmsg_printf(error::ERROR,
55
 
                  _("Catalog name cannot be encoded and fit within filesystem "
56
 
                    "name length restrictions."));
57
 
  }
58
 
}
59
 
 
60
 
Catalog::Catalog(const std::string &name_arg) :
61
 
  _name(name_arg)
 
41
namespace drizzled {
 
42
namespace identifier {
 
43
 
 
44
Catalog::Catalog(str_ref name_arg) :
 
45
  _name(name_arg.data(), name_arg.size())
62
46
63
47
  init();
64
48
}
65
49
 
66
 
Catalog::Catalog(const drizzled::LEX_STRING &name_arg) :
67
 
  _name(name_arg.str, name_arg.length)
68
 
{
69
 
  init();
70
 
}
71
 
 
72
 
void  Catalog::init()
 
50
void Catalog::init()
73
51
74
52
  assert(not _name.empty());
75
 
 
76
 
  build_schema_filename(path, _name);
 
53
  path += "../";
 
54
  path += util::tablename_to_filename(_name);
77
55
  assert(path.length()); // TODO throw exception, this is a possibility
78
 
 
79
 
  util::insensitive_hash hasher;
80
 
  hash_value= hasher(path);
81
 
}
82
 
 
83
 
const std::string &Catalog::getPath() const
84
 
{
85
 
  return path;
 
56
  hash_value= util::insensitive_hash()(path);
86
57
}
87
58
 
88
59
bool Catalog::compare(const std::string &arg) const
92
63
 
93
64
bool Catalog::isValid() const
94
65
{
95
 
  if (_name.empty())
96
 
    return false;
97
 
 
98
 
  if (_name.size() > NAME_LEN)
99
 
    return false;
100
 
 
101
 
  if (_name.at(_name.length() -1) == ' ')
102
 
    return false;
103
 
 
104
 
  const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
105
 
 
 
66
  if (_name.empty()
 
67
    || _name.size() > NAME_LEN
 
68
    || _name.at(_name.length() -1 ) == ' ')
 
69
    return false;
 
70
  const charset_info_st& cs= my_charset_utf8mb4_general_ci;
106
71
  int well_formed_error;
107
 
  uint32_t res= cs->cset->well_formed_len(cs, _name.c_str(), _name.c_str() + _name.length(),
108
 
                                          NAME_CHAR_LEN, &well_formed_error);
109
 
 
 
72
  uint32_t res= cs.cset->well_formed_len(cs, _name, NAME_CHAR_LEN, &well_formed_error);
110
73
  if (well_formed_error)
111
74
  {
112
75
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
113
76
    return false;
114
77
  }
115
 
 
116
78
  if (_name.length() != res)
117
79
    return false;
118
 
 
119
80
  return true;
120
81
}
121
82
 
122
 
std::size_t hash_value(Catalog const& b)
123
 
{
124
 
  return b.getHashValue();
125
 
}
126
 
 
127
 
void Catalog::getSQLPath(std::string &sql_path) const
128
 
{
129
 
  sql_path= _name;
130
 
}
131
 
 
132
 
 
133
 
 
134
83
} /* namespace identifier */
135
84
} /* namespace drizzled */