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

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.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
#include <drizzled/catalog/local.h>
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
 
extern string drizzle_tmpdir;
47
 
 
48
 
static size_t build_schema_filename(string &path, const string &db)
49
 
{
50
 
  path.append("");
51
 
  bool conversion_error= false;
52
 
 
53
 
  conversion_error= util::tablename_to_filename(db, path);
54
 
  if (conversion_error)
55
 
  {
56
 
    errmsg_printf(error::ERROR,
57
 
                  _("Schema name cannot be encoded and fit within filesystem "
58
 
                    "name length restrictions."));
59
 
    return 0;
60
 
  }
61
 
 
62
 
  return path.length();
63
 
}
64
 
 
65
 
Schema::Schema(const std::string &db_arg) :
66
 
  db(db_arg),
67
 
  db_path("")
 
41
namespace drizzled {
 
42
namespace identifier {
 
43
 
 
44
Schema::Schema(str_ref db_arg) :
 
45
  db(db_arg.data(), db_arg.size())
68
46
69
47
#if 0
70
48
  string::size_type lastPos= db.find_first_of('/', 0);
76
54
  }
77
55
#endif
78
56
 
79
 
  if (not db_arg.empty())
 
57
  if (db_arg.empty() == false)
80
58
  {
81
 
    build_schema_filename(db_path, db);
 
59
    db_path += util::tablename_to_filename(db);
82
60
    assert(db_path.length()); // TODO throw exception, this is a possibility
83
61
  }
84
 
}
85
62
 
86
 
void Schema::getSQLPath(std::string &arg) const
87
 
{
88
 
  arg= db;
 
63
  _corrected_db= boost::to_lower_copy(db);
89
64
}
90
65
 
91
66
const std::string &Schema::getPath() const
98
73
  return boost::iequals(arg, db);
99
74
}
100
75
 
101
 
bool Schema::compare(Schema::const_reference arg) const
 
76
bool Schema::compare(const Schema& arg) const
102
77
{
103
78
  return boost::iequals(arg.getSchemaName(), db);
104
79
}
105
80
 
106
81
bool Schema::isValid() const
107
82
{
108
 
  bool error= false;
109
 
 
110
 
  do
111
 
  {
112
 
    if (db.empty())
113
 
    {
114
 
      error= true;
115
 
      break;
116
 
    }
117
 
 
118
 
    if (db.size() > NAME_LEN)
119
 
    {
120
 
      error= true;
121
 
      break;
122
 
    }
123
 
 
124
 
    if (db.at(db.length() -1) == ' ')
125
 
    {
126
 
      error= true;
127
 
      break;
128
 
    }
129
 
 
130
 
    if (db.at(0) == '.')
131
 
    {
132
 
      error= true;
133
 
      break;
134
 
    }
135
 
 
136
 
    {
137
 
      const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
138
 
 
139
 
      int well_formed_error;
140
 
      uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
141
 
                                              NAME_CHAR_LEN, &well_formed_error);
142
 
      if (well_formed_error or db.length() != res)
143
 
      {
144
 
        error= true;
145
 
        break;
146
 
      }
147
 
    }
148
 
  } while (0);
149
 
 
150
 
  if (error)
151
 
  {
152
 
    my_error(ER_WRONG_DB_NAME, *this);
153
 
 
154
 
    return false;
 
83
  const charset_info_st& cs= my_charset_utf8mb4_general_ci;
 
84
  int well_formed_error;
 
85
  if (not db.empty()
 
86
    && db.size() <= NAME_LEN
 
87
    && db.at(0) != '.'
 
88
    && db.at(db.size() - 1) != ' '
 
89
    && db.size() == cs.cset->well_formed_len(cs, db, NAME_CHAR_LEN, &well_formed_error))
 
90
  {
 
91
    if (not well_formed_error)
 
92
      return true;
155
93
  }
156
 
 
157
 
  return true;
 
94
  my_error(ER_WRONG_DB_NAME, *this);
 
95
  return false;
158
96
}
159
97
 
160
98
const std::string &Schema::getCatalogName() const
164
102
 
165
103
std::ostream& operator<<(std::ostream& output, const Schema&identifier)
166
104
{
167
 
  output << "identifier::Schema:(";
168
 
  output <<  catalog::local_identifier();
169
 
  output << ", ";
170
 
  output <<  identifier.getSchemaName().c_str();
171
 
  output << ", ";
172
 
  output << identifier.getPath().c_str();
173
 
  output << ")";
174
 
 
175
 
  return output;  // for multiple << operators.
 
105
  return output << "identifier::Schema:(" <<  drizzled::catalog::local_identifier() << ", " <<  identifier.getSchemaName() << ", " << identifier.getPath() << ")";
176
106
}
177
107
 
178
108
} /* namespace identifier */