~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2010-02-14 02:02:48 UTC
  • mfrom: (1273.13.64 fix_is)
  • Revision ID: brian@gaz-20100214020248-bhovaejhz9fmer3q
MergeĀ inĀ data_dictionary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
{
77
77
  message::Schema db;
78
78
 
79
 
  get_database_metadata(db_name, &db);
 
79
  get_database_metadata(db_name, db);
80
80
 
81
81
  /* If for some reason the db.opt file lacks a collation,
82
82
     we just return the default */
130
130
    close(fd);
131
131
    return errno;
132
132
  }
133
 
 
134
133
  close(fd);
 
134
 
135
135
  return 0;
136
136
}
137
137
 
138
 
int get_database_metadata(const char *dbname, message::Schema *db)
 
138
int get_database_metadata(const std::string &dbname, message::Schema &schema_message)
139
139
{
 
140
  int rc= 0;
140
141
  char db_opt_path[FN_REFLEN];
141
142
  size_t length;
142
143
 
145
146
    to avoid table name to file name encoding.
146
147
  */
147
148
  length= build_table_filename(db_opt_path, sizeof(db_opt_path),
148
 
                              dbname, "", false);
 
149
                               dbname.c_str(), "", false);
149
150
  strcpy(db_opt_path + length, MY_DB_OPT_FILE);
150
151
 
151
152
  int fd= open(db_opt_path, O_RDONLY);
152
153
 
153
 
  if (fd == -1)
154
 
    return errno;
 
154
  if (fd == -1 && errno != ENOENT)
 
155
    rc= errno;
155
156
 
156
 
  if (!db->ParseFromFileDescriptor(fd))
 
157
  /**
 
158
    @note If parsing fails, either someone has done a "mkdir" or has deleted their opt file.
 
159
    So what do we do? We muddle through the adventure by generating 
 
160
    one with a name in it, and the charset set to the default.
 
161
  */
 
162
  if (fd == -1 || not schema_message.ParseFromFileDescriptor(fd))
157
163
  {
 
164
    struct stat directory_stat_buffer;
 
165
 
 
166
    /* Remove the opt file name and see if we can just open up the directory. */
 
167
    db_opt_path[length]= 0;
 
168
    if (lstat(db_opt_path, &directory_stat_buffer))
 
169
    {
 
170
      rc= errno;
 
171
    }
 
172
    else if (not S_ISDIR(directory_stat_buffer.st_mode))
 
173
    {
 
174
      rc= -1;
 
175
    }
 
176
    else
 
177
    {
 
178
      schema_message.set_name(dbname);
 
179
      rc= 0;
 
180
    }
 
181
 
 
182
#if 0 //@todo fill this in with something totally acceptable
 
183
    schema_message.set_collation("utf8_general_ci"); 
 
184
#endif
 
185
  }
 
186
 
 
187
  if (fd != -1)
158
188
    close(fd);
159
 
    return -1;
160
 
  }
161
 
  close(fd);
162
189
 
163
 
  return 0;
 
190
  return rc;
164
191
}
165
192
 
166
193
/*
356
383
    return true;
357
384
  }
358
385
 
359
 
 
360
386
  /*
361
387
    Do not drop database if another thread is holding read lock.
362
388
    Wait for global read lock before acquiring LOCK_create_db.
813
839
 
814
840
    return false;
815
841
  }
816
 
 
817
842
  /*
818
843
    Now we need to make a copy because check_db_name requires a
819
844
    non-constant argument. Actually, it takes database file name.