~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.cc

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

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) 2009 Sun Microsystems, Inc.
 
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
#include <cassert>
 
23
#include <drizzled/errmsg_print.h>
 
24
#include <drizzled/gettext.h>
 
25
#include <drizzled/identifier.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/internal/my_sys.h>
 
28
#include <drizzled/catalog/local.h>
 
29
#include <drizzled/util/tablename_to_filename.h>
 
30
#include <drizzled/util/backtrace.h>
 
31
#include <drizzled/charset.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
namespace identifier {
 
43
 
 
44
Schema::Schema(const std::string &db_arg) :
 
45
  db(db_arg)
 
46
 
47
#if 0
 
48
  string::size_type lastPos= db.find_first_of('/', 0);
 
49
 
 
50
  if (lastPos != std::string::npos) 
 
51
  {
 
52
    catalog= db.substr(0, lastPos);
 
53
    db.erase(0, lastPos + 1);
 
54
  }
 
55
#endif
 
56
 
 
57
  if (not db_arg.empty())
 
58
  {
 
59
    db_path += util::tablename_to_filename(db);
 
60
    assert(db_path.length()); // TODO throw exception, this is a possibility
 
61
  }
 
62
}
 
63
 
 
64
const std::string &Schema::getPath() const
 
65
{
 
66
  return db_path;
 
67
}
 
68
 
 
69
bool Schema::compare(const std::string &arg) const
 
70
{
 
71
  return boost::iequals(arg, db);
 
72
}
 
73
 
 
74
bool Schema::compare(const Schema& arg) const
 
75
{
 
76
  return boost::iequals(arg.getSchemaName(), db);
 
77
}
 
78
 
 
79
bool Schema::isValid() const
 
80
{
 
81
  bool error= false;
 
82
 
 
83
  do
 
84
  {
 
85
    if (db.empty())
 
86
    {
 
87
      error= true;
 
88
      break;
 
89
    }
 
90
 
 
91
    if (db.size() > NAME_LEN)
 
92
    {
 
93
      error= true;
 
94
      break;
 
95
    }
 
96
 
 
97
    if (db.at(db.length() -1) == ' ')
 
98
    {
 
99
      error= true;
 
100
      break;
 
101
    }
 
102
 
 
103
    if (db.at(0) == '.')
 
104
    {
 
105
      error= true;
 
106
      break;
 
107
    }
 
108
 
 
109
    {
 
110
      const charset_info_st * const cs= &my_charset_utf8mb4_general_ci;
 
111
 
 
112
      int well_formed_error;
 
113
      uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
 
114
                                              NAME_CHAR_LEN, &well_formed_error);
 
115
      if (well_formed_error or db.length() != res)
 
116
      {
 
117
        error= true;
 
118
        break;
 
119
      }
 
120
    }
 
121
  } while (0);
 
122
 
 
123
  if (error)
 
124
  {
 
125
    my_error(ER_WRONG_DB_NAME, *this);
 
126
 
 
127
    return false;
 
128
  }
 
129
 
 
130
  return true;
 
131
}
 
132
 
 
133
const std::string &Schema::getCatalogName() const
 
134
{
 
135
  return drizzled::catalog::local_identifier().name();
 
136
}
 
137
 
 
138
std::ostream& operator<<(std::ostream& output, const Schema&identifier)
 
139
{
 
140
  return output << "identifier::Schema:(" <<  drizzled::catalog::local_identifier() << ", " <<  identifier.getSchemaName() << ", " << identifier.getPath() << ")";
 
141
}
 
142
 
 
143
} /* namespace identifier */
 
144
} /* namespace drizzled */