~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.cc

  • Committer: Lee Bieber
  • Date: 2010-11-20 01:33:21 UTC
  • mfrom: (1878.10.4 drizzle_bug665252)
  • Revision ID: kalebral@gmail.com-20101120013321-7nk9lq4nnr20zk6b
Merge Billy - removed my_getsysdate, my_micro_time and my_micro_time_and_time and replaced with boost::date_time for compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
namespace drizzled
43
43
{
44
44
 
45
 
class SchemaIdentifier;
46
 
 
47
45
extern std::string drizzle_tmpdir;
48
46
extern pid_t current_pid;
49
47
 
272
270
  util::insensitive_hash hasher;
273
271
  hash_value= hasher(path);
274
272
 
275
 
  std::string tb_name(getTableName());
276
 
  std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
277
 
 
278
 
  key.set(getKeySize(), getSchemaName(), tb_name);
 
273
  key.set(getKeySize(), getSchemaName(), getTableName());
279
274
}
280
275
 
281
276
 
284
279
  return path;
285
280
}
286
281
 
287
 
void TableIdentifier::getSQLPath(std::string &sql_path) const  // @todo this is just used for errors, we should find a way to optimize it
288
 
{
289
 
  switch (type) {
290
 
  case message::Table::FUNCTION:
291
 
  case message::Table::STANDARD:
292
 
    sql_path.append(getSchemaName());
293
 
    sql_path.append(".");
294
 
    sql_path.append(table_name);
295
 
    break;
296
 
  case message::Table::INTERNAL:
297
 
    sql_path.append("temporary.");
298
 
    sql_path.append(table_name);
299
 
    break;
300
 
  case message::Table::TEMPORARY:
301
 
    sql_path.append(getSchemaName());
302
 
    sql_path.append(".#");
303
 
    sql_path.append(table_name);
304
 
    break;
305
 
  }
306
 
}
307
 
 
308
 
bool TableIdentifier::isValid() const
309
 
{
310
 
  if (not SchemaIdentifier::isValid())
311
 
    return false;
312
 
 
313
 
  bool error= false;
314
 
  do
315
 
  {
316
 
    if (table_name.empty())
317
 
    {
318
 
      error= true;
319
 
      break;
320
 
    }
321
 
 
322
 
    if (table_name.size() > NAME_LEN)
323
 
    {
324
 
      error= true;
325
 
      break;
326
 
    }
327
 
 
328
 
    if (table_name.at(table_name.length() -1) == ' ')
329
 
    {
330
 
      error= true;
331
 
      break;
332
 
    }
333
 
 
334
 
    if (table_name.at(0) == '.')
335
 
    {
336
 
      error= true;
337
 
      break;
338
 
    }
339
 
 
340
 
    {
341
 
      const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
342
 
 
343
 
      int well_formed_error;
344
 
      uint32_t res= cs->cset->well_formed_len(cs, table_name.c_str(), table_name.c_str() + table_name.length(),
345
 
                                              NAME_CHAR_LEN, &well_formed_error);
346
 
      if (well_formed_error or table_name.length() != res)
347
 
      {
348
 
        error= true;
349
 
        break;
350
 
      }
351
 
    }
352
 
  } while (0);
353
 
 
354
 
  if (error)
355
 
  {
356
 
    std::string name;
357
 
 
358
 
    getSQLPath(name);
359
 
    my_error(ER_WRONG_TABLE_NAME, MYF(0), name.c_str());
360
 
 
361
 
    return false;
362
 
  }
363
 
 
364
 
  return true;
 
282
const std::string &TableIdentifier::getSQLPath()  // @todo this is just used for errors, we should find a way to optimize it
 
283
{
 
284
  if (sql_path.empty())
 
285
  {
 
286
    switch (type) {
 
287
    case message::Table::FUNCTION:
 
288
    case message::Table::STANDARD:
 
289
      sql_path.append(getSchemaName());
 
290
      sql_path.append(".");
 
291
      sql_path.append(table_name);
 
292
      break;
 
293
    case message::Table::INTERNAL:
 
294
      sql_path.append("temporary.");
 
295
      sql_path.append(table_name);
 
296
      break;
 
297
    case message::Table::TEMPORARY:
 
298
      sql_path.append(getSchemaName());
 
299
      sql_path.append(".#");
 
300
      sql_path.append(table_name);
 
301
      break;
 
302
    }
 
303
  }
 
304
 
 
305
  return sql_path;
365
306
}
366
307
 
367
308