~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/catalog.cc

  • Committer: Brian Aker
  • Date: 2011-02-05 10:53:26 UTC
  • mto: (2147.3.1 alter-table)
  • mto: This revision was merged to the branch mainline in revision 2148.
  • Revision ID: brian@tangent.org-20110205105326-hjmn5xehw5rs46tp
Fix bad error in warnings/errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <assert.h>
 
24
 
 
25
#include "drizzled/identifier.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/current_session.h"
 
28
#include "drizzled/internal/my_sys.h"
 
29
 
 
30
#include "drizzled/util/tablename_to_filename.h"
 
31
#include "drizzled/util/backtrace.h"
 
32
 
 
33
#include <algorithm>
 
34
#include <sstream>
 
35
#include <cstdio>
 
36
 
 
37
#include <boost/algorithm/string/compare.hpp>
 
38
 
 
39
using namespace std;
 
40
 
 
41
namespace drizzled
 
42
{
 
43
 
 
44
namespace identifier
 
45
{
 
46
 
 
47
static void build_schema_filename(string &path, const string &name_arg)
 
48
{
 
49
  path.append("../");
 
50
  bool conversion_error= false;
 
51
 
 
52
  conversion_error= util::tablename_to_filename(name_arg, path);
 
53
  if (conversion_error)
 
54
  {
 
55
    errmsg_printf(error::ERROR,
 
56
                  _("Catalog name cannot be encoded and fit within filesystem "
 
57
                    "name length restrictions."));
 
58
  }
 
59
}
 
60
 
 
61
Catalog::Catalog(const std::string &name_arg) :
 
62
  _name(name_arg)
 
63
 
64
  init();
 
65
}
 
66
 
 
67
Catalog::Catalog(const drizzled::LEX_STRING &name_arg) :
 
68
  _name(name_arg.str, name_arg.length)
 
69
{
 
70
  init();
 
71
}
 
72
 
 
73
void  Catalog::init()
 
74
 
75
  assert(not _name.empty());
 
76
 
 
77
  build_schema_filename(path, _name);
 
78
  assert(path.length()); // TODO throw exception, this is a possibility
 
79
 
 
80
  util::insensitive_hash hasher;
 
81
  hash_value= hasher(path);
 
82
}
 
83
 
 
84
const std::string &Catalog::getPath() const
 
85
{
 
86
  return path;
 
87
}
 
88
 
 
89
bool Catalog::compare(const std::string &arg) const
 
90
{
 
91
  return boost::iequals(arg, _name);
 
92
}
 
93
 
 
94
bool Catalog::isValid() const
 
95
{
 
96
  if (_name.empty())
 
97
    return false;
 
98
 
 
99
  if (_name.size() > NAME_LEN)
 
100
    return false;
 
101
 
 
102
  if (_name.at(_name.length() -1) == ' ')
 
103
    return false;
 
104
 
 
105
  const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
 
106
 
 
107
  int well_formed_error;
 
108
  uint32_t res= cs->cset->well_formed_len(cs, _name.c_str(), _name.c_str() + _name.length(),
 
109
                                          NAME_CHAR_LEN, &well_formed_error);
 
110
 
 
111
  if (well_formed_error)
 
112
  {
 
113
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
 
114
    return false;
 
115
  }
 
116
 
 
117
  if (_name.length() != res)
 
118
    return false;
 
119
 
 
120
  return true;
 
121
}
 
122
 
 
123
std::size_t hash_value(Catalog const& b)
 
124
{
 
125
  return b.getHashValue();
 
126
}
 
127
 
 
128
void Catalog::getSQLPath(std::string &sql_path) const
 
129
{
 
130
  sql_path= _name;
 
131
}
 
132
 
 
133
 
 
134
 
 
135
} /* namespace identifier */
 
136
} /* namespace drizzled */