~drizzle-trunk/drizzle/development

1415 by Brian Aker
Mass overhaul to use schema_identifier.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1415 by Brian Aker
Mass overhaul to use schema_identifier.
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
1660.1.1 by Brian Aker
Merge in move identifier work.
32
#ifndef DRIZZLED_IDENTIFIER_SCHEMA_H
33
#define DRIZZLED_IDENTIFIER_SCHEMA_H
1415 by Brian Aker
Mass overhaul to use schema_identifier.
34
35
#include <drizzled/enum.h>
36
#include "drizzled/definitions.h"
37
#include "drizzled/message/table.pb.h"
38
#include <string.h>
39
40
#include <assert.h>
41
42
#include <ostream>
43
#include <list>
44
#include <algorithm>
45
#include <functional>
46
#include <iostream>
47
1685.2.12 by Brian Aker
This fixes the lower casing of names from Schema even when we should not.
48
#include <boost/algorithm/string.hpp>
1643.3.9 by Brian Aker
Updated to hold tables in I_S.
49
1415 by Brian Aker
Mass overhaul to use schema_identifier.
50
namespace drizzled {
51
1861.5.1 by Brian Aker
This just fixes our current catalog to be displayed properly.
52
static std::string catalog("local");
1643.3.9 by Brian Aker
Updated to hold tables in I_S.
53
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
54
class SchemaIdentifier : public Identifier
1415 by Brian Aker
Mass overhaul to use schema_identifier.
55
{
56
  std::string db;
57
  std::string db_path;
1861.5.1 by Brian Aker
This just fixes our current catalog to be displayed properly.
58
  std::string catalog;
1415 by Brian Aker
Mass overhaul to use schema_identifier.
59
60
public:
1966.2.3 by Brian Aker
Fix another style issue.
61
  typedef std::vector <SchemaIdentifier> vector;
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
62
  typedef const SchemaIdentifier& const_reference;
1966.2.3 by Brian Aker
Fix another style issue.
63
1613 by Brian Aker
Fix solaris warning.
64
  SchemaIdentifier(const std::string &db_arg);
1415 by Brian Aker
Mass overhaul to use schema_identifier.
65
66
  virtual ~SchemaIdentifier()
67
  { }
68
1954.2.1 by Brian Aker
getSQLPath() modified to take a string so that we can const the table
69
  virtual void getSQLPath(std::string &arg) const;
2041.3.15 by Brian Aker
Cleanup error usage around identifier usage.
70
1613 by Brian Aker
Fix solaris warning.
71
  const std::string &getPath() const;
1415 by Brian Aker
Mass overhaul to use schema_identifier.
72
73
  const std::string &getSchemaName() const
74
  {
75
    return db;
76
  }
77
1643.3.9 by Brian Aker
Updated to hold tables in I_S.
78
  const std::string &getCatalogName() const
79
  {
80
    return catalog;
81
  }
82
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
83
  virtual bool isValid() const;
84
1685.2.11 by Brian Aker
First pass around removing need for lower case version of DB in the
85
  bool compare(const std::string &arg) const;
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
86
  bool compare(SchemaIdentifier::const_reference) const;
1415 by Brian Aker
Mass overhaul to use schema_identifier.
87
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
88
  friend bool operator<(SchemaIdentifier::const_reference left, SchemaIdentifier::const_reference right)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
89
  {
1685.2.12 by Brian Aker
This fixes the lower casing of names from Schema even when we should not.
90
    return  boost::algorithm::to_upper_copy(left.getSchemaName()) < boost::algorithm::to_upper_copy(right.getSchemaName());
1415 by Brian Aker
Mass overhaul to use schema_identifier.
91
  }
92
1418.1.2 by Monty Taylor
Fixed Solaris issue with the operator< by adding some constness. While I was
93
  friend std::ostream& operator<<(std::ostream& output,
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
94
                                  SchemaIdentifier::const_reference identifier)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
95
  {
96
    output << "SchemaIdentifier:(";
1861.5.1 by Brian Aker
This just fixes our current catalog to be displayed properly.
97
    output <<  identifier.catalog;
98
    output << ", ";
1415 by Brian Aker
Mass overhaul to use schema_identifier.
99
    output <<  identifier.db;
100
    output << ", ";
101
    output << identifier.getPath();
102
    output << ")";
103
104
    return output;  // for multiple << operators.
105
  }
106
1992.4.1 by Brian Aker
Update code for testing identifiers/table/schema name correctness.
107
  friend bool operator==(SchemaIdentifier::const_reference left,
108
                         SchemaIdentifier::const_reference right)
1415 by Brian Aker
Mass overhaul to use schema_identifier.
109
  {
1685.2.12 by Brian Aker
This fixes the lower casing of names from Schema even when we should not.
110
    return boost::iequals(left.getSchemaName(), right.getSchemaName());
1415 by Brian Aker
Mass overhaul to use schema_identifier.
111
  }
112
};
113
114
115
} /* namespace drizzled */
116
1660.1.1 by Brian Aker
Merge in move identifier work.
117
#endif /* DRIZZLED_IDENTIFIER_SCHEMA_H */