~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2009-07-16 06:32:37 UTC
  • mfrom: (1095.1.3 merge)
  • Revision ID: brian@gaz-20090716063237-0iyo47mgo46uqaiy
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <drizzled/lock.h>
35
35
#include <drizzled/errmsg_print.h>
36
36
#include <drizzled/transaction_services.h>
 
37
#include <drizzled/message/schema.pb.h>
37
38
 
38
39
extern drizzled::TransactionServices transaction_services;
39
40
 
63
64
 
64
65
const CHARSET_INFO *get_default_db_collation(const char *db_name)
65
66
{
66
 
  HA_CREATE_INFO db_info;
67
 
 
68
 
  /*
69
 
    db_info.default_table_charset contains valid character set
70
 
    (collation_server).
71
 
  */
72
 
 
73
 
  load_db_opt_by_name(db_name, &db_info);
74
 
 
75
 
  return db_info.default_table_charset;
 
67
  drizzled::message::Schema db;
 
68
 
 
69
  get_database_metadata(db_name, &db);
 
70
 
 
71
  /* If for some reason the db.opt file lacks a collation,
 
72
     we just return the default */
 
73
 
 
74
  if (db.has_collation())
 
75
  {
 
76
    const string buffer= db.collation();
 
77
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
 
78
 
 
79
    if (!cs)
 
80
    {
 
81
      errmsg_printf(ERRMSG_LVL_ERROR,
 
82
                    _("Error while loading database options: '%s':"),db_name);
 
83
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
 
84
 
 
85
      return default_charset_info;
 
86
    }
 
87
 
 
88
    return cs;
 
89
  }
 
90
 
 
91
  return default_charset_info;
76
92
}
77
93
 
78
94
/* path is path to database, not schema file */
121
137
  return 0;
122
138
}
123
139
 
124
 
static int load_db_opt(const char *path, HA_CREATE_INFO *create)
125
 
{
126
 
  drizzled::message::Schema db;
127
 
 
128
 
  memset(create, 0, sizeof(*create));
129
 
  create->default_table_charset= default_charset_info;
130
 
 
131
 
  int fd= open(path, O_RDONLY);
132
 
 
133
 
  if (fd == -1)
134
 
    return errno;
135
 
 
136
 
  if (!db.ParseFromFileDescriptor(fd))
137
 
  {
138
 
    close(fd);
139
 
    return -1;
140
 
  }
141
 
  close(fd);
142
 
 
143
 
  /* If for some reason the db.opt file lacks a collation, we just return the default */
144
 
  if (db.has_collation())
145
 
  {
146
 
    string buffer;
147
 
    buffer= db.collation();
148
 
    if (!(create->default_table_charset= get_charset_by_name(buffer.c_str())))
149
 
    {
150
 
      errmsg_printf(ERRMSG_LVL_ERROR,
151
 
                    _("Error while loading database options: '%s':"),path);
152
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
153
 
      create->default_table_charset= default_charset_info;
154
 
      return -1;
155
 
    }
156
 
  }
157
 
 
158
 
  return 0;
159
 
}
160
 
 
161
 
int load_db_opt_by_name(const char *db_name, HA_CREATE_INFO *db_create_info)
 
140
int get_database_metadata(const char *dbname, drizzled::message::Schema *db)
162
141
{
163
142
  char db_opt_path[FN_REFLEN];
164
143
  size_t length;
168
147
    to avoid table name to file name encoding.
169
148
  */
170
149
  length= build_table_filename(db_opt_path, sizeof(db_opt_path),
171
 
                              db_name, "", false);
 
150
                              dbname, "", false);
172
151
  strcpy(db_opt_path + length, MY_DB_OPT_FILE);
173
152
 
174
 
  return load_db_opt(db_opt_path, db_create_info);
 
153
  int fd= open(db_opt_path, O_RDONLY);
 
154
 
 
155
  if (fd == -1)
 
156
    return errno;
 
157
 
 
158
  if (!db->ParseFromFileDescriptor(fd))
 
159
  {
 
160
    close(fd);
 
161
    return -1;
 
162
  }
 
163
  close(fd);
 
164
 
 
165
  return 0;
175
166
}
176
167
 
177
 
 
178
168
/*
179
169
  Create a database
180
170