| 276 | */ |
| 277 | |
| 278 | bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create) |
| 279 | { |
| 280 | File file; |
| 281 | char buf[256]; |
| 282 | DBUG_ENTER("load_db_opt"); |
| 283 | bool error=1; |
| 284 | uint nbytes; |
| 285 | |
| 286 | memset(create, 0, sizeof(*create)); |
| 287 | create->default_table_charset= thd->variables.collation_server; |
| 288 | |
| 289 | /* Check if options for this database are already in the hash */ |
| 290 | if (!get_dbopt(path, create)) |
| 291 | DBUG_RETURN(0); |
| 292 | |
| 293 | /* Otherwise, load options from the .opt file */ |
| 294 | if ((file= mysql_file_open(key_file_dbopt, |
| 295 | path, O_RDONLY | O_SHARE, MYF(0))) < 0) |
| 296 | goto err1; |
| 297 | |
| 298 | IO_CACHE cache; |
| 299 | if (init_io_cache(&cache, file, IO_SIZE, READ_CACHE, 0, 0, MYF(0))) |
| 300 | goto err2; |
| 301 | |
| 302 | while ((int) (nbytes= my_b_gets(&cache, (char*) buf, sizeof(buf))) > 0) |
| 303 | { |
| 304 | char *pos= buf+nbytes-1; |
| 305 | /* Remove end space and control characters */ |
| 306 | while (pos > buf && !my_isgraph(&my_charset_latin1, pos[-1])) |
| 307 | pos--; |
| 308 | *pos=0; |
| 309 | if ((pos= strchr(buf, '='))) |
| 310 | { |
| 311 | if (!strncmp(buf,"default-character-set", (pos-buf))) |
| 312 | { |
| 313 | /* |
| 314 | Try character set name, and if it fails |
| 315 | try collation name, probably it's an old |
| 316 | 4.1.0 db.opt file, which didn't have |
| 317 | separate default-character-set and |
| 318 | default-collation commands. |
| 319 | */ |
| 320 | if (!(create->default_table_charset= |
| 321 | get_charset_by_csname(pos+1, MY_CS_PRIMARY, MYF(0))) && |
| 322 | !(create->default_table_charset= |
| 323 | get_charset_by_name(pos+1, MYF(0)))) |
| 324 | { |
| 325 | sql_print_error("Error while loading database options: '%s':",path); |
| 326 | sql_print_error(ER(ER_UNKNOWN_CHARACTER_SET),pos+1); |
| 327 | create->default_table_charset= default_charset_info; |
| 328 | } |
| 329 | } |
| 330 | else if (!strncmp(buf,"default-collation", (pos-buf))) |
| 331 | { |
| 332 | if (!(create->default_table_charset= get_charset_by_name(pos+1, |
| 333 | MYF(0)))) |
| 334 | { |
| 335 | sql_print_error("Error while loading database options: '%s':",path); |
no test coverage detected