~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2009-05-14 08:35:31 UTC
  • mto: This revision was merged to the branch mainline in revision 1016.
  • Revision ID: brian@gaz-20090514083531-shers31p7s7zqldi
Simplify the calling stack for getting schema collation. We need to extend
this further by removing the schema collation from session (in order to
remove the need for a cache).

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
    set, even if the database does not exist.
149
149
*/
150
150
 
151
 
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name)
 
151
const CHARSET_INFO *get_default_db_collation(const char *db_name)
152
152
{
153
153
  HA_CREATE_INFO db_info;
154
154
 
155
 
  if (session->db != NULL && strcmp(db_name, session->db) == 0)
156
 
    return session->db_charset;
157
 
 
158
155
  /*
159
156
    db_info.default_table_charset contains valid character set
160
157
    (collation_server).
161
158
  */
162
159
 
163
 
  load_db_opt_by_name(session, db_name, &db_info);
 
160
  load_db_opt_by_name(db_name, &db_info);
164
161
 
165
162
  return db_info.default_table_charset;
166
163
}
211
208
  return 0;
212
209
}
213
210
 
214
 
int load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create)
 
211
int load_db_opt(const char *path, HA_CREATE_INFO *create)
215
212
{
216
213
  drizzled::message::Schema db;
217
 
  string buffer;
218
214
 
219
215
  memset(create, 0, sizeof(*create));
220
 
  create->default_table_charset= session->variables.collation_server;
 
216
  create->default_table_charset= default_charset_info;
221
217
 
222
218
  int fd= open(path, O_RDONLY);
223
219
 
231
227
  }
232
228
  close(fd);
233
229
 
234
 
  buffer= db.collation();
235
 
  if (!(create->default_table_charset= get_charset_by_name(buffer.c_str())))
 
230
  /* If for some reason the db.opt file lacks a collation, we just return the default */
 
231
  if (db.has_collation())
236
232
  {
237
 
    errmsg_printf(ERRMSG_LVL_ERROR,
238
 
                  _("Error while loading database options: '%s':"),path);
239
 
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
240
 
    create->default_table_charset= default_charset_info;
241
 
    return -1;
 
233
    string buffer;
 
234
    buffer= db.collation();
 
235
    if (!(create->default_table_charset= get_charset_by_name(buffer.c_str())))
 
236
    {
 
237
      errmsg_printf(ERRMSG_LVL_ERROR,
 
238
                    _("Error while loading database options: '%s':"),path);
 
239
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
 
240
      create->default_table_charset= default_charset_info;
 
241
      return -1;
 
242
    }
242
243
  }
243
244
 
244
245
  return 0;
245
246
}
246
247
 
247
 
int load_db_opt_by_name(Session *session, const char *db_name,
248
 
                        HA_CREATE_INFO *db_create_info)
 
248
int load_db_opt_by_name(const char *db_name, HA_CREATE_INFO *db_create_info)
249
249
{
250
250
  char db_opt_path[FN_REFLEN];
251
251
 
256
256
  (void) build_table_filename(db_opt_path, sizeof(db_opt_path),
257
257
                              db_name, "", MY_DB_OPT_FILE, 0);
258
258
 
259
 
  return load_db_opt(session, db_opt_path, db_create_info);
 
259
  return load_db_opt(db_opt_path, db_create_info);
260
260
}
261
261
 
262
262
 
1061
1061
    attributes and will be freed in Session::~Session().
1062
1062
  */
1063
1063
 
1064
 
  db_default_cl= get_default_db_collation(session, new_db_file_name.str);
 
1064
  db_default_cl= get_default_db_collation(new_db_file_name.str);
1065
1065
 
1066
1066
  mysql_change_db_impl(session, &new_db_file_name, db_default_cl);
1067
1067