~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

Add in new show work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
{
76
76
  message::Schema db;
77
77
 
78
 
  get_database_metadata(db_name, &db);
 
78
  get_database_metadata(db_name, db);
79
79
 
80
80
  /* If for some reason the db.opt file lacks a collation,
81
81
     we just return the default */
129
129
    close(fd);
130
130
    return errno;
131
131
  }
132
 
 
133
132
  close(fd);
 
133
 
134
134
  return 0;
135
135
}
136
136
 
137
 
int get_database_metadata(const char *dbname, message::Schema *db)
 
137
int get_database_metadata(const std::string &dbname, message::Schema &schema_message)
138
138
{
 
139
  int rc= 0;
139
140
  char db_opt_path[FN_REFLEN];
140
141
  size_t length;
141
142
 
144
145
    to avoid table name to file name encoding.
145
146
  */
146
147
  length= build_table_filename(db_opt_path, sizeof(db_opt_path),
147
 
                              dbname, "", false);
 
148
                               dbname.c_str(), "", false);
148
149
  strcpy(db_opt_path + length, MY_DB_OPT_FILE);
149
150
 
150
151
  int fd= open(db_opt_path, O_RDONLY);
151
152
 
152
 
  if (fd == -1)
153
 
    return errno;
 
153
  if (fd == -1 && errno != ENOENT)
 
154
    rc= errno;
154
155
 
155
 
  if (!db->ParseFromFileDescriptor(fd))
 
156
  /**
 
157
    @note If parsing fails, either someone has done a "mkdir" or has deleted their opt file.
 
158
    So what do we do? We muddle through the adventure by generating 
 
159
    one with a name in it, and the charset set to the default.
 
160
  */
 
161
  if (fd == -1 || not schema_message.ParseFromFileDescriptor(fd))
156
162
  {
157
 
    close(fd);
158
 
    return -1;
 
163
    struct stat directory_stat_buffer;
 
164
 
 
165
    /* Remove the opt file name and see if we can just open up the directory. */
 
166
    db_opt_path[length]= 0;
 
167
    if (lstat(db_opt_path, &directory_stat_buffer))
 
168
    {
 
169
      rc= errno;
 
170
    }
 
171
    else if (not S_ISDIR(directory_stat_buffer.st_mode))
 
172
    {
 
173
      rc= -1;
 
174
    }
 
175
    else
 
176
    {
 
177
      schema_message.set_name(dbname);
 
178
      rc= 0;
 
179
    }
 
180
 
 
181
#if 0 
 
182
    //@todo fill this in with something totally acceptable
 
183
    schema_message.set_collation("utf8_general_ci"); 
 
184
#endif
159
185
  }
 
186
 
160
187
  close(fd);
161
188
 
162
 
  return 0;
 
189
  return rc;
163
190
}
164
191
 
165
192
/*