~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.cc

  • Committer: Brian Aker
  • Date: 2010-08-06 01:25:55 UTC
  • mfrom: (1688.1.3 drizzle)
  • Revision ID: brian@gaz-20100806012555-f1bxjm4iesdtiwlw
MergeĀ BuildĀ (rollup)

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <sstream>
33
33
#include <cstdio>
34
34
 
 
35
#include <boost/algorithm/string/compare.hpp>
 
36
 
35
37
using namespace std;
36
38
 
37
39
namespace drizzled
96
98
  for (; iter != from.end(); ++iter)
97
99
  {
98
100
    if ((*iter >= '0' && *iter <= '9') ||
99
 
        (*iter >= 'A' && *iter <= 'Z') ||
100
101
        (*iter >= 'a' && *iter <= 'z') ||
101
 
/* OSX defines an extra set of high-bit and multi-byte characters
102
 
   that cannot be used on the filesystem. Instead of trying to sort
103
 
   those out, we'll just escape encode all high-bit-set chars on OSX.
104
 
   It won't really hurt anything - it'll just make some filenames ugly. */
 
102
        /* OSX defines an extra set of high-bit and multi-byte characters
 
103
          that cannot be used on the filesystem. Instead of trying to sort
 
104
          those out, we'll just escape encode all high-bit-set chars on OSX.
 
105
          It won't really hurt anything - it'll just make some filenames ugly. */
105
106
#if !defined(TARGET_OS_OSX)
106
107
        ((unsigned char)*iter >= 128) ||
107
108
#endif
112
113
      to.push_back(*iter);
113
114
      continue;
114
115
    }
 
116
 
 
117
    if ((*iter >= 'A' && *iter <= 'Z'))
 
118
    {
 
119
      to.push_back(tolower(*iter));
 
120
      continue;
 
121
    }
115
122
   
116
123
    /* We need to escape this char in a way that can be reversed */
117
124
    to.push_back('@');
128
135
 
129
136
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
130
137
  db(db_arg),
131
 
  db_path(""),
132
 
  lower_db(db_arg)
 
138
  db_path("")
133
139
134
 
  std::transform(lower_db.begin(), lower_db.end(),
135
 
                 lower_db.begin(), ::tolower);
136
 
 
137
 
  if (not lower_db.empty())
 
140
  if (not db_arg.empty())
138
141
  {
139
 
    drizzled::build_schema_filename(db_path, lower_db);
 
142
    drizzled::build_schema_filename(db_path, db);
140
143
    assert(db_path.length()); // TODO throw exception, this is a possibility
141
144
  }
142
145
}
151
154
  return db_path;
152
155
}
153
156
 
154
 
bool SchemaIdentifier::compare(std::string arg) const
 
157
bool SchemaIdentifier::compare(const std::string &arg) const
155
158
{
156
 
  std::transform(arg.begin(), arg.end(),
157
 
                 arg.begin(), ::tolower);
158
 
 
159
 
  return arg == lower_db;
 
159
  return boost::iequals(arg, db);
160
160
}
161
161
 
162
162
bool SchemaIdentifier::isValid() const
163
163
{
164
 
  if (lower_db.empty())
165
 
    return false;
166
 
 
167
 
  if (lower_db.size() > NAME_LEN)
168
 
    return false;
169
 
 
170
 
  if (lower_db.at(lower_db.length() -1) == ' ')
 
164
  if (db.empty())
 
165
    return false;
 
166
 
 
167
  if (db.size() > NAME_LEN)
 
168
    return false;
 
169
 
 
170
  if (db.at(db.length() -1) == ' ')
171
171
    return false;
172
172
 
173
173
  const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
174
174
 
175
175
  int well_formed_error;
176
 
  uint32_t res= cs->cset->well_formed_len(cs, lower_db.c_str(), lower_db.c_str() + lower_db.length(),
 
176
  uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
177
177
                                          NAME_CHAR_LEN, &well_formed_error);
178
178
 
179
179
  if (well_formed_error)
180
180
  {
181
 
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", lower_db.c_str());
 
181
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", db.c_str());
182
182
    return false;
183
183
  }
184
184
 
185
 
  if (lower_db.length() != res)
 
185
  if (db.length() != res)
186
186
    return false;
187
187
 
188
188
  return true;