~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/schema.cc

  • Committer: Stewart Smith
  • Date: 2011-03-29 01:30:47 UTC
  • mto: (2257.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: stewart@flamingspork.com-20110329013047-5ujzfx6pahmwuko2
have CachedDirectory print out a warning if we can't stat() something in a directory. We should always have access to at least stat() things in directories Drizzle is running in (otherwise there is likely a problem)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
 
23
 
#include <assert.h>
24
 
 
25
 
#include "drizzled/identifier.h"
26
 
#include "drizzled/session.h"
27
 
#include "drizzled/current_session.h"
28
 
#include "drizzled/internal/my_sys.h"
29
 
 
30
 
#include "drizzled/util/tablename_to_filename.h"
31
 
#include "drizzled/util/backtrace.h"
 
21
#include <config.h>
 
22
#include <cassert>
 
23
#include <drizzled/errmsg_print.h>
 
24
#include <drizzled/gettext.h>
 
25
#include <drizzled/identifier.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/internal/my_sys.h>
 
28
#include <drizzled/catalog/local.h>
 
29
#include <drizzled/util/tablename_to_filename.h>
 
30
#include <drizzled/util/backtrace.h>
 
31
#include <drizzled/charset_info.h>
32
32
 
33
33
#include <algorithm>
34
34
#include <sstream>
38
38
 
39
39
using namespace std;
40
40
 
41
 
namespace drizzled
42
 
{
 
41
namespace drizzled {
 
42
namespace identifier {
43
43
 
44
44
extern string drizzle_tmpdir;
45
 
extern pid_t current_pid;
46
45
 
47
46
static size_t build_schema_filename(string &path, const string &db)
48
47
{
52
51
  conversion_error= util::tablename_to_filename(db, path);
53
52
  if (conversion_error)
54
53
  {
55
 
    errmsg_printf(ERRMSG_LVL_ERROR,
 
54
    errmsg_printf(error::ERROR,
56
55
                  _("Schema name cannot be encoded and fit within filesystem "
57
56
                    "name length restrictions."));
58
57
    return 0;
61
60
  return path.length();
62
61
}
63
62
 
64
 
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) :
65
 
  db(db_arg),
66
 
  db_path(""),
67
 
  catalog("LOCAL")
 
63
Schema::Schema(const std::string &db_arg) :
 
64
  db(db_arg)
68
65
69
66
#if 0
70
67
  string::size_type lastPos= db.find_first_of('/', 0);
78
75
 
79
76
  if (not db_arg.empty())
80
77
  {
81
 
    drizzled::build_schema_filename(db_path, db);
 
78
    build_schema_filename(db_path, db);
82
79
    assert(db_path.length()); // TODO throw exception, this is a possibility
83
80
  }
84
81
}
85
82
 
86
 
void SchemaIdentifier::getSQLPath(std::string &arg) const
87
 
{
88
 
  arg.append(getSchemaName());
89
 
}
90
 
 
91
 
const std::string &SchemaIdentifier::getPath() const
 
83
const std::string &Schema::getPath() const
92
84
{
93
85
  return db_path;
94
86
}
95
87
 
96
 
bool SchemaIdentifier::compare(const std::string &arg) const
 
88
bool Schema::compare(const std::string &arg) const
97
89
{
98
90
  return boost::iequals(arg, db);
99
91
}
100
92
 
101
 
bool SchemaIdentifier::compare(SchemaIdentifier::const_reference arg) const
 
93
bool Schema::compare(const Schema& arg) const
102
94
{
103
95
  return boost::iequals(arg.getSchemaName(), db);
104
96
}
105
97
 
106
 
bool SchemaIdentifier::isValid() const
 
98
bool Schema::isValid() const
107
99
{
108
100
  bool error= false;
109
101
 
134
126
    }
135
127
 
136
128
    {
137
 
      const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
 
129
      const charset_info_st * const cs= &my_charset_utf8mb4_general_ci;
138
130
 
139
131
      int well_formed_error;
140
132
      uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(),
149
141
 
150
142
  if (error)
151
143
  {
152
 
    std::string name;
153
 
 
154
 
    getSQLPath(name);
155
 
    my_error(ER_WRONG_DB_NAME, MYF(0), name.c_str());
 
144
    my_error(ER_WRONG_DB_NAME, *this);
156
145
 
157
146
    return false;
158
147
  }
160
149
  return true;
161
150
}
162
151
 
 
152
const std::string &Schema::getCatalogName() const
 
153
{
 
154
  return drizzled::catalog::local_identifier().name();
 
155
}
 
156
 
 
157
std::ostream& operator<<(std::ostream& output, const Schema&identifier)
 
158
{
 
159
  return output << "identifier::Schema:(" <<  catalog::local_identifier() << ", " <<  identifier.getSchemaName() << ", " << identifier.getPath() << ")";
 
160
}
 
161
 
 
162
} /* namespace identifier */
163
163
} /* namespace drizzled */