diff options
author | unknown <georg@lmy002.wdf.sap.corp> | 2005-09-18 21:43:28 +0200 |
---|---|---|
committer | unknown <georg@lmy002.wdf.sap.corp> | 2005-09-18 21:43:28 +0200 |
commit | 458aa0e34b3f4f6f5ccac6b03502e88864a2a18b (patch) | |
tree | 4f40850583dc106a3d2244b93f21e79b9e792a6f /sql/parse_file.cc | |
parent | bf58b698e22efe0849fc8ee18fc30e3914d73409 (diff) | |
download | mariadb-git-458aa0e34b3f4f6f5ccac6b03502e88864a2a18b.tar.gz |
Changes after discussion/review with Sanja
sql/parse_file.cc:
Fix after discussion/review with Sanja: removed rename_view from sql_view to general function rename_in_schema_file
(so it can be used for other .frm types like triggers too)
sql/parse_file.h:
added prototype for rename_in_schema_file
sql/sql_rename.cc:
simplified code (thanks to Sanja)
sql/sql_view.cc:
moved rename_view_files to rename_in_schema_file (parse_file.cc)
corrected MYF parameter from MY_WME to 0.
Diffstat (limited to 'sql/parse_file.cc')
-rw-r--r-- | sql/parse_file.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 82ce2f2d7b5..5c7053e6e2a 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -333,6 +333,59 @@ err_w_file: DBUG_RETURN(TRUE); } +/* + Renames a frm file (including backups) in same schema + + SYNOPSIS + rename_in_schema_file + schema name of given schema + old_name original file name + new_name new file name + revision revision number + num_view_backups number of backups + + RETURN + 0 - OK + 1 - Error (only if renaming of frm failed) + +*/ +my_bool rename_in_schema_file(const char *schema, const char *old_name, + const char *new_name, ulonglong revision, + uint num_view_backups) +{ + char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN]; + + strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/", + old_name, reg_ext, NullS); + (void) unpack_filename(old_path, old_path); + + strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/", + new_name, reg_ext, NullS); + (void) unpack_filename(new_path, new_path); + + if (my_rename(old_path, new_path, MYF(MY_WME))) + return 1; + + /* check if arc_dir exists */ + strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS); + (void) unpack_filename(arc_path, arc_path); + + if (revision > 0 && !access(arc_path, F_OK)) + { + ulonglong limit= (revision > num_view_backups) ? revision - num_view_backups : 0; + while (revision > limit) { + my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu", + arc_path, old_name, reg_ext, (ulong)revision); + (void) unpack_filename(old_path, old_path); + my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu", + arc_path, new_name, reg_ext, (ulong)revision); + (void) unpack_filename(new_path, new_path); + my_rename(old_path, new_path, MYF(0)); + revision--; + } + } + return 0; +} /* Prepare frm to parse (read to memory) |