~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

  • Committer: Brian Aker
  • Date: 2009-11-21 02:00:39 UTC
  • mto: (1226.1.4 push)
  • mto: This revision was merged to the branch mainline in revision 1228.
  • Revision ID: brian@gaz-20091121020039-2h9ze1wfz2lby2y2
Table Identifier patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* 
 
22
  This is a "work in progress". The concept needs to be replicated throughout
 
23
  the code, but we will start with baby steps for the moment. To not incur
 
24
  cost until we are complete, for the moment it will do no allocation.
 
25
 
 
26
  This is mainly here so that it can be used in the SE interface for
 
27
  the time being.
 
28
 
 
29
  This will replace Table_ident.
 
30
  */
 
31
 
 
32
#ifndef DRIZZLED_TABLE_IDENTIFIER_H
 
33
#define DRIZZLED_TABLE_IDENTIFIER_H
 
34
 
 
35
#include <string.h>
 
36
 
 
37
size_t build_tmptable_filename(char *buff, size_t bufflen);
 
38
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp);
 
39
 
 
40
 
 
41
namespace drizzled {
 
42
 
 
43
class TableIdentifier 
 
44
{
 
45
private:
 
46
  bool path_inited;
 
47
  tmp_table_type type;
 
48
  char path[FN_REFLEN];
 
49
  const char *db;
 
50
  const char *table_name;
 
51
 
 
52
public:
 
53
  TableIdentifier( const char *db_arg,
 
54
                   const char *table_name_arg,
 
55
                   tmp_table_type tmp_arg) :
 
56
    path_inited(false),
 
57
    type(tmp_arg),
 
58
    db(db_arg),
 
59
    table_name(table_name_arg)
 
60
  { 
 
61
  }
 
62
 
 
63
  bool isTmp()
 
64
  {
 
65
    return type == NO_TMP_TABLE ? false  : true;
 
66
  }
 
67
 
 
68
  const char *getPath()
 
69
  {
 
70
    if (! path_inited)
 
71
    {
 
72
      size_t path_length;
 
73
 
 
74
      switch (type) {
 
75
      case NO_TMP_TABLE:
 
76
        path_length= build_table_filename(path, sizeof(path),
 
77
                                          db, table_name,
 
78
                                          false);
 
79
        break;
 
80
      case INTERNAL_TMP_TABLE:
 
81
        path_length= build_table_filename(path, sizeof(path),
 
82
                                          db, table_name,
 
83
                                          true);
 
84
        break;
 
85
      case NON_TRANSACTIONAL_TMP_TABLE:
 
86
      case TRANSACTIONAL_TMP_TABLE:
 
87
        build_tmptable_filename(path, sizeof(path));
 
88
        break;
 
89
      case SYSTEM_TMP_TABLE:
 
90
        assert(0);
 
91
      }
 
92
      assert(path_length); // TODO throw exception, this is a possibility
 
93
    }
 
94
 
 
95
    return path;
 
96
  }
 
97
 
 
98
  const char *getDBName()
 
99
  {
 
100
    return db;
 
101
  }
 
102
 
 
103
  const char *getTableName()
 
104
  {
 
105
    return table_name;
 
106
  }
 
107
};
 
108
 
 
109
} /* namespace drizzled */
 
110
 
 
111
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */