~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-07 11:47:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2385.
  • Revision ID: olafvdspek@gmail.com-20110707114749-2r2bgjhk36o06p1n
Refactor build_table_filename

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
static uint32_t get_counter()
134
134
{
135
135
  boost::mutex::scoped_lock lock(counter_mutex);
136
 
  uint32_t x;
137
 
  x= ++counter;
138
 
 
139
 
  return x;
 
136
  return ++counter;
140
137
}
141
138
 
142
139
#endif
143
140
 
144
 
size_t Table::build_tmptable_filename(std::string &buffer)
145
 
{
146
 
  ostringstream post_tmpdir_str;
147
 
 
148
 
  buffer.append(drizzle_tmpdir);
149
 
  size_t tmpdir_length= buffer.length();
150
 
 
151
 
  post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
152
 
  post_tmpdir_str << pthread_self() << "-" << get_counter();
153
 
 
154
 
  buffer.append(post_tmpdir_str.str());
155
 
 
156
 
  transform(buffer.begin() + tmpdir_length, buffer.end(), buffer.begin() + tmpdir_length, ::tolower);
157
 
 
158
 
  return buffer.length();
159
 
}
160
 
 
161
 
size_t Table::build_tmptable_filename(std::vector<char> &buffer)
162
 
{
163
 
  ostringstream post_tmpdir_str;
164
 
 
165
 
  post_tmpdir_str << drizzle_tmpdir << "/" << TMP_FILE_PREFIX << current_pid;
166
 
  post_tmpdir_str << pthread_self() << "-" << get_counter();
167
 
 
168
 
  buffer.resize(post_tmpdir_str.str().length() + 1);
169
 
  memcpy(&buffer[0], post_tmpdir_str.str().c_str(), post_tmpdir_str.str().size());
170
 
  buffer[post_tmpdir_str.str().size()]= 0;
171
 
 
172
 
  return buffer.size();
173
 
}
174
 
 
 
141
std::string Table::build_tmptable_filename()
 
142
{
 
143
  ostringstream os;
 
144
  os << "/" << TMP_FILE_PREFIX << current_pid << pthread_self() << "-" << get_counter();
 
145
  return drizzle_tmpdir + boost::to_lower_copy(os.str());
 
146
}
175
147
 
176
148
/*
177
149
  Creates path to a cursor: drizzle_data_dir/db/table.ext
205
177
    path length on success, 0 on failure
206
178
*/
207
179
 
208
 
size_t Table::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
 
180
void Table::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
209
181
{
210
182
  if (util::tablename_to_filename(in_db, in_path))
211
183
  {
212
184
    errmsg_printf(error::ERROR, _("Schema name cannot be encoded and fit within filesystem name length restrictions."));
213
 
    return 0;
214
185
  }
215
186
 
216
187
  in_path.append(FN_ROOTDIR);
222
193
  else if (util::tablename_to_filename(in_table_name, in_path))
223
194
  {
224
195
    errmsg_printf(error::ERROR, _("Table name cannot be encoded and fit within filesystem name length restrictions."));
225
 
    return 0;
226
196
  }
227
 
   
228
 
  return in_path.length();
229
197
}
230
198
 
231
199
Table::Table(const drizzled::Table &table) :
248
216
    build_table_filename(path, getSchemaName(), table_name, false);
249
217
    break;
250
218
  case message::Table::INTERNAL:
251
 
    assert(path.size() == 0);
 
219
    assert(path.empty());
252
220
    build_table_filename(path, getSchemaName(), table_name, true);
253
221
    break;
254
222
  case message::Table::TEMPORARY:
255
223
    if (path.empty())
256
 
    {
257
 
      build_tmptable_filename(path);
258
 
    }
 
224
      path= build_tmptable_filename();
259
225
    break;
260
226
  }
261
227
 
266
232
    break;
267
233
  case message::Table::TEMPORARY:
268
234
    {
269
 
      size_t pos;
270
 
 
271
 
      pos= path.find("tmp/#sql");
 
235
      size_t pos= path.find("tmp/#sql");
272
236
      if (pos != std::string::npos) 
273
 
      {
274
237
        key_path= path.substr(pos);
275
 
      }
276
238
    }
277
239
    break;
278
240
  }
279
241
 
280
242
  hash_value= util::insensitive_hash()(path);
281
 
 
282
 
  std::string tb_name(getTableName());
283
 
  boost::to_lower(tb_name);
284
 
  key.set(getKeySize(), getSchemaName(), tb_name);
 
243
  key.set(getKeySize(), getSchemaName(), boost::to_lower_copy(std::string(getTableName())));
285
244
}
286
245
 
287
246