~drizzle-trunk/drizzle/development

1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
2239.1.6 by Olaf van der Spek
Refactor includes
22
#include <cassert>
23
#include <drizzled/errmsg_print.h>
24
#include <drizzled/gettext.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
25
#include <drizzled/identifier.h>
26
#include <drizzled/session.h>
27
#include <drizzled/internal/my_sys.h>
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
28
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
29
#include <drizzled/util/tablename_to_filename.h>
30
#include <drizzled/util/backtrace.h>
2281.5.1 by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file.
31
#include <drizzled/charset.h>
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
32
33
#include <algorithm>
34
#include <sstream>
35
#include <cstdio>
36
37
#include <boost/algorithm/string/compare.hpp>
38
39
using namespace std;
40
2240.2.2 by Olaf van der Spek
Refactor
41
namespace drizzled {
42
namespace identifier {
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
43
44
Catalog::Catalog(const std::string &name_arg) :
2039.6.6 by Brian Aker
Update so that CATALOG is correctly being displayed.
45
  _name(name_arg)
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
46
{ 
2073.1.2 by Brian Aker
Basic DDL for catalog.
47
  init();
48
}
49
2371.1.2 by Brian Aker
Remove the typedef on lexkey
50
Catalog::Catalog(const drizzled::lex_string_t &name_arg) :
2073.1.2 by Brian Aker
Basic DDL for catalog.
51
  _name(name_arg.str, name_arg.length)
52
{
53
  init();
54
}
55
2240.2.2 by Olaf van der Spek
Refactor
56
void Catalog::init()
2073.1.2 by Brian Aker
Basic DDL for catalog.
57
{ 
58
  assert(not _name.empty());
2318.9.8 by Olaf van der Spek
Refactor tablename_to_filename()
59
  path += "../";
60
  path += util::tablename_to_filename(_name);
1960.1.8 by Brian Aker
Big hunk of burning create/drop work.
61
  assert(path.length()); // TODO throw exception, this is a possibility
2240.2.2 by Olaf van der Spek
Refactor
62
  hash_value= util::insensitive_hash()(path);
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
63
}
64
65
bool Catalog::compare(const std::string &arg) const
66
{
2039.6.6 by Brian Aker
Update so that CATALOG is correctly being displayed.
67
  return boost::iequals(arg, _name);
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
68
}
69
70
bool Catalog::isValid() const
71
{
2240.2.2 by Olaf van der Spek
Refactor
72
  if (_name.empty()
73
    || _name.size() > NAME_LEN
74
    || _name.at(_name.length() -1 ) == ' ')
75
    return false;
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
76
  const charset_info_st& cs= my_charset_utf8mb4_general_ci;
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
77
  int well_formed_error;
2240.2.2 by Olaf van der Spek
Refactor
78
  uint32_t res= cs.cset->well_formed_len(&cs, _name.c_str(), _name.c_str() + _name.length(), NAME_CHAR_LEN, &well_formed_error);
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
79
  if (well_formed_error)
80
  {
2039.6.6 by Brian Aker
Update so that CATALOG is correctly being displayed.
81
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", _name.c_str());
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
82
    return false;
83
  }
2039.6.6 by Brian Aker
Update so that CATALOG is correctly being displayed.
84
  if (_name.length() != res)
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
85
    return false;
86
  return true;
87
}
88
89
} /* namespace identifier */
90
} /* namespace drizzled */