~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

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
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
 
extern string drizzle_tmpdir;
45
 
extern pid_t current_pid;
46
 
 
47
 
static size_t build_schema_filename(string &path, const string &db)
48
 
{
49
 
  path.append("");
50
 
  bool conversion_error= false;
51
 
 
52
 
  conversion_error= util::tablename_to_filename(db, path);
53
 
  if (conversion_error)
54
 
  {
55
 
    errmsg_printf(ERRMSG_LVL_ERROR,
56
 
                  _("Schema name cannot be encoded and fit within filesystem "
57
 
                    "name length restrictions."));
58
 
    return 0;
59
 
  }
60
 
 
61
 
  return path.length();
62
 
}
63
 
 
64
 
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
65
 
  db(db_arg),
66
 
  db_path(""),
67
 
  catalog("LOCAL")
68
 
69
 
#if 0
70
 
  string::size_type lastPos= db.find_first_of('/', 0);
71
 
 
72
 
  if (lastPos != std::string::npos) 
73
 
  {
74
 
    catalog= db.substr(0, lastPos);
75
 
    db.erase(0, lastPos + 1);
76
 
  }
77
 
#endif
78
 
 
79
 
  if (not db_arg.empty())
80
 
  {
81
 
    drizzled::build_schema_filename(db_path, db);
82
 
    assert(db_path.length()); // TODO throw exception, this is a possibility
83
 
  }
84
 
}
85
 
 
86
 
const std::string &SchemaIdentifier::getSQLPath()
87
 
{
88
 
  return getSchemaName();
89
 
}
90
 
 
91
 
const std::string &SchemaIdentifier::getPath() const
92
 
{
93
 
  return db_path;
94
 
}
95
 
 
96
 
bool SchemaIdentifier::compare(const std::string &arg) const
97
 
{
98
 
  return boost::iequals(arg, db);
99
 
}
100
 
 
101
 
bool SchemaIdentifier::isValid() const
102
 
{
103
 
  if (db.empty())
104
 
    return false;
105
 
 
106
 
  if (db.size() > NAME_LEN)
107
 
    return false;
108
 
 
109
 
  if (db.at(db.length() -1) == ' ')
110
 
    return false;
111
 
 
112
 
  const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
113
 
 
114
 
  int well_formed_error;
115
 
  uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
116
 
                                          NAME_CHAR_LEN, &well_formed_error);
117
 
 
118
 
  if (well_formed_error)
119
 
  {
120
 
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", db.c_str());
121
 
    return false;
122
 
  }
123
 
 
124
 
  if (db.length() != res)
125
 
    return false;
126
 
 
127
 
  return true;
128
 
}
129
 
 
130
 
} /* namespace drizzled */