~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.cc

  • Committer: Brian Aker
  • Date: 2011-02-17 10:09:00 UTC
  • mfrom: (2173.2.1 clean-include-usuage)
  • Revision ID: brian@tangent.org-20110217100900-4tpuxxzdl1sj00sh
Merge Monty for headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <assert.h>
24
24
 
25
 
#include "drizzled/identifier.h"
26
 
#include "drizzled/session.h"
27
 
#include "drizzled/current_session.h"
28
 
#include "drizzled/internal/my_sys.h"
 
25
#include <drizzled/identifier.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/internal/my_sys.h>
29
28
 
30
 
#include "drizzled/util/tablename_to_filename.h"
31
 
#include "drizzled/util/backtrace.h"
 
29
#include <drizzled/util/tablename_to_filename.h>
 
30
#include <drizzled/util/backtrace.h>
32
31
 
33
32
#include <algorithm>
34
33
#include <sstream>
41
40
namespace drizzled
42
41
{
43
42
 
 
43
namespace identifier
 
44
{
 
45
 
44
46
extern string drizzle_tmpdir;
45
 
extern pid_t current_pid;
46
47
 
47
48
static size_t build_schema_filename(string &path, const string &db)
48
49
{
52
53
  conversion_error= util::tablename_to_filename(db, path);
53
54
  if (conversion_error)
54
55
  {
55
 
    errmsg_printf(ERRMSG_LVL_ERROR,
 
56
    errmsg_printf(error::ERROR,
56
57
                  _("Schema name cannot be encoded and fit within filesystem "
57
58
                    "name length restrictions."));
58
59
    return 0;
61
62
  return path.length();
62
63
}
63
64
 
64
 
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
 
65
Schema::Schema(const std::string &db_arg) :
65
66
  db(db_arg),
66
 
  db_path(""),
67
 
  catalog("LOCAL")
 
67
  db_path("")
68
68
69
69
#if 0
70
70
  string::size_type lastPos= db.find_first_of('/', 0);
78
78
 
79
79
  if (not db_arg.empty())
80
80
  {
81
 
    drizzled::build_schema_filename(db_path, db);
 
81
    build_schema_filename(db_path, db);
82
82
    assert(db_path.length()); // TODO throw exception, this is a possibility
83
83
  }
84
84
}
85
85
 
86
 
void SchemaIdentifier::getSQLPath(std::string &arg) const
 
86
void Schema::getSQLPath(std::string &arg) const
87
87
{
88
 
  arg.append(getSchemaName());
 
88
  arg= db;
89
89
}
90
90
 
91
 
const std::string &SchemaIdentifier::getPath() const
 
91
const std::string &Schema::getPath() const
92
92
{
93
93
  return db_path;
94
94
}
95
95
 
96
 
bool SchemaIdentifier::compare(const std::string &arg) const
 
96
bool Schema::compare(const std::string &arg) const
97
97
{
98
98
  return boost::iequals(arg, db);
99
99
}
100
100
 
101
 
bool SchemaIdentifier::compare(SchemaIdentifier::const_reference arg) const
 
101
bool Schema::compare(Schema::const_reference arg) const
102
102
{
103
103
  return boost::iequals(arg.getSchemaName(), db);
104
104
}
105
105
 
106
 
bool SchemaIdentifier::isValid() const
 
106
bool Schema::isValid() const
107
107
{
108
108
  bool error= false;
109
109
 
149
149
 
150
150
  if (error)
151
151
  {
152
 
    std::string name;
153
 
 
154
 
    getSQLPath(name);
155
 
    my_error(ER_WRONG_DB_NAME, MYF(0), name.c_str());
 
152
    my_error(ER_WRONG_DB_NAME, *this);
156
153
 
157
154
    return false;
158
155
  }
160
157
  return true;
161
158
}
162
159
 
 
160
const std::string &Schema::getCatalogName() const
 
161
{
 
162
  return drizzled::catalog::local_identifier().name();
 
163
}
 
164
 
 
165
std::ostream& operator<<(std::ostream& output, const Schema&identifier)
 
166
{
 
167
  output << "identifier::Schema:(";
 
168
  output <<  catalog::local_identifier();
 
169
  output << ", ";
 
170
  output <<  identifier.getSchemaName().c_str();
 
171
  output << ", ";
 
172
  output << identifier.getPath().c_str();
 
173
  output << ")";
 
174
 
 
175
  return output;  // for multiple << operators.
 
176
}
 
177
 
 
178
} /* namespace identifier */
163
179
} /* namespace drizzled */