~drizzle-trunk/drizzle/development

1223.4.18 by Brian Aker
More TableIdentifier code.
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 <drizzled/table_identifier.h>
22
23
using namespace std;
24
using namespace drizzled;
25
26
// Prototypes, these will be removed.
27
size_t build_tmptable_filename(char *buff, size_t bufflen);
28
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp);
29
30
const char *TableIdentifier::getPath()
31
{
32
  if (! path_inited)
33
  {
34
    size_t path_length= 0;
35
36
    switch (type) {
37
    case NO_TMP_TABLE:
38
      path_length= build_table_filename(path, sizeof(path),
39
                                        db, table_name,
40
                                        false);
41
      break;
42
    case INTERNAL_TMP_TABLE:
43
      path_length= build_table_filename(path, sizeof(path),
44
                                        db, table_name,
45
                                        true);
46
      break;
47
    case NON_TRANSACTIONAL_TMP_TABLE:
48
    case TRANSACTIONAL_TMP_TABLE:
49
      path_length= build_tmptable_filename(path, sizeof(path));
50
      break;
51
    case SYSTEM_TMP_TABLE:
52
      assert(0);
53
    }
54
    path_inited= true;
55
    assert(path_length); // TODO throw exception, this is a possibility
56
  }
57
58
  return path;
59
}