~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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 <drizzled/enum.h>
 
36
#include "drizzled/definitions.h"
 
37
#include <string.h>
 
38
 
 
39
#include <assert.h>
 
40
 
 
41
#include <ostream>
 
42
#include <set>
 
43
 
 
44
namespace drizzled {
 
45
 
 
46
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
47
bool tablename_to_filename(const char *from, char *to, size_t to_length);
 
48
size_t build_tmptable_filename(char *buff, size_t bufflen);
 
49
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp);
 
50
 
 
51
 
 
52
class TableIdentifier
 
53
{
 
54
private:
 
55
  bool path_inited;
 
56
 
 
57
  tmp_table_type type;
 
58
  char path[FN_REFLEN];
 
59
  std::string db;
 
60
  std::string table_name;
 
61
  std::string sql_path;
 
62
 
 
63
public:
 
64
  TableIdentifier( const char *db_arg,
 
65
                   const char *table_name_arg,
 
66
                   tmp_table_type tmp_arg= STANDARD_TABLE) :
 
67
    path_inited(false),
 
68
    type(tmp_arg),
 
69
    db(db_arg),
 
70
    table_name(table_name_arg),
 
71
    sql_path(db)
 
72
  { 
 
73
    sql_path.append(".");
 
74
    sql_path.append(table_name);
 
75
  }
 
76
 
 
77
  bool isTmp() const
 
78
  {
 
79
    return type == STANDARD_TABLE ? false  : true;
 
80
  }
 
81
 
 
82
  const std::string &getSQLPath()
 
83
  {
 
84
    return sql_path;
 
85
  }
 
86
 
 
87
  const char *getPath();
 
88
 
 
89
  const char *getDBName() const
 
90
  {
 
91
    return db.c_str();
 
92
  }
 
93
 
 
94
  const char *getSchemaName() const
 
95
  {
 
96
    return db.c_str();
 
97
  }
 
98
 
 
99
  const char *getTableName() const
 
100
  {
 
101
    return table_name.c_str();
 
102
  }
 
103
 
 
104
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
 
105
  {
 
106
    const char *type_str;
 
107
 
 
108
    output << "TableIdentifier:(";
 
109
    output <<  identifier.getDBName();
 
110
    output << ", ";
 
111
    output << identifier.getTableName();
 
112
    output << ", ";
 
113
 
 
114
    switch (identifier.type) {
 
115
    case STANDARD_TABLE:
 
116
      type_str= "standard";
 
117
      break;
 
118
    case INTERNAL_TMP_TABLE:
 
119
      type_str= "internal";
 
120
      break;
 
121
    case TEMP_TABLE:
 
122
      type_str= "temporary";
 
123
      break;
 
124
    case SYSTEM_TMP_TABLE:
 
125
      type_str= "system";
 
126
    }
 
127
 
 
128
    output << type_str;
 
129
    output << ")";
 
130
 
 
131
    return output;  // for multiple << operators.
 
132
  }
 
133
 
 
134
  friend bool operator==(const TableIdentifier &left, const TableIdentifier &right)
 
135
  {
 
136
    if (left.type == right.type)
 
137
    {
 
138
      if (not strcmp(left.db.c_str(), right.db.c_str()))
 
139
      {
 
140
        if (not strcmp(left.table_name.c_str(), right.table_name.c_str()))
 
141
        {
 
142
          return true;
 
143
        }
 
144
      }
 
145
    }
 
146
 
 
147
    return false;
 
148
  }
 
149
 
 
150
};
 
151
 
 
152
typedef std::set <TableIdentifier> TableIdentifierList;
 
153
 
 
154
} /* namespace drizzled */
 
155
 
 
156
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */