Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
53a7bbf7
Commit
53a7bbf7
authored
Sep 18, 2005
by
georg@lmy002.wdf.sap.corp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes after discussion/review with Sanja
parent
afe8dcf2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
62 deletions
+98
-62
sql/parse_file.cc
sql/parse_file.cc
+53
-0
sql/parse_file.h
sql/parse_file.h
+3
-0
sql/sql_rename.cc
sql/sql_rename.cc
+25
-25
sql/sql_view.cc
sql/sql_view.cc
+17
-37
No files found.
sql/parse_file.cc
View file @
53a7bbf7
...
...
@@ -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)
...
...
sql/parse_file.h
View file @
53a7bbf7
...
...
@@ -48,6 +48,9 @@ my_bool
sql_create_definition_file
(
const
LEX_STRING
*
dir
,
const
LEX_STRING
*
file_name
,
const
LEX_STRING
*
type
,
gptr
base
,
File_option
*
parameters
,
uint
versions
);
my_bool
rename_in_schema_file
(
const
char
*
schema
,
const
char
*
old_name
,
const
char
*
new_name
,
ulonglong
revision
,
uint
num_view_backups
);
class
File_parser
:
public
Sql_alloc
{
...
...
sql/sql_rename.cc
View file @
53a7bbf7
...
...
@@ -138,7 +138,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
for
(
ren_table
=
table_list
;
ren_table
;
ren_table
=
new_table
->
next_local
)
{
db_type
table_type
;
int
rc
=
1
;
char
name
[
FN_REFLEN
];
const
char
*
new_alias
,
*
old_alias
;
...
...
@@ -165,21 +165,20 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
ren_table
->
db
,
old_alias
,
reg_ext
);
unpack_filename
(
name
,
name
);
if
((
frm_type
=
mysql_frm_type
(
name
))
==
FRMTYPE_TABLE
&&
(
table_type
=
get_table_type
(
thd
,
name
))
==
DB_TYPE_UNKNOWN
)
{
my_error
(
ER_FILE_NOT_FOUND
,
MYF
(
0
),
name
,
my_errno
);
if
(
!
skip_error
)
DBUG_RETURN
(
ren_table
);
}
else
{
int
rc
=
1
;
frm_type
=
mysql_frm_type
(
name
);
switch
(
frm_type
)
{
case
FRMTYPE_TABLE
:
{
db_type
table_type
;
if
((
table_type
=
get_table_type
(
thd
,
name
))
==
DB_TYPE_UNKNOWN
)
my_error
(
ER_FILE_NOT_FOUND
,
MYF
(
0
),
name
,
my_errno
);
else
rc
=
mysql_rename_table
(
table_type
,
ren_table
->
db
,
old_alias
,
new_table
->
db
,
new_alias
);
break
;
}
case
FRMTYPE_VIEW
:
/* change of schema is not allowed */
if
(
strcmp
(
ren_table
->
db
,
new_table
->
db
))
...
...
@@ -188,13 +187,14 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
else
rc
=
mysql_rename_view
(
thd
,
new_alias
,
ren_table
);
break
;
case
FRMTYPE_ERROR
:
default:
DBUG_ASSERT
(
0
);
// should never happen
case
FRMTYPE_ERROR
:
my_error
(
ER_FILE_NOT_FOUND
,
MYF
(
0
),
name
,
my_errno
);
break
;
}
if
(
rc
&&
!
skip_error
)
DBUG_RETURN
(
ren_table
);
}
}
DBUG_RETURN
(
0
);
}
sql/sql_view.cc
View file @
53a7bbf7
...
...
@@ -1167,7 +1167,7 @@ frm_type_enum mysql_frm_type(char *path)
int
length
;
DBUG_ENTER
(
"mysql_frm_type"
);
if
((
file
=
my_open
(
path
,
O_RDONLY
|
O_SHARE
,
MYF
(
MY_WME
)))
<
0
)
if
((
file
=
my_open
(
path
,
O_RDONLY
|
O_SHARE
,
MYF
(
0
)))
<
0
)
{
DBUG_RETURN
(
FRMTYPE_ERROR
);
}
...
...
@@ -1372,43 +1372,21 @@ int view_checksum(THD *thd, TABLE_LIST *view)
HA_ADMIN_OK
);
}
bool
rename_view_files
(
const
char
*
schema
,
const
char
*
old_name
,
const
char
*
new_name
,
ulonglong
revision
)
{
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
;
/*
rename view
/* check if arc_dir exists */
strxnmov
(
arc_path
,
FN_REFLEN
,
mysql_data_home
,
"/"
,
schema
,
"/arc"
,
NullS
);
(
void
)
unpack_filename
(
arc_path
,
arc_path
);
Synopsis:
renames a view
if
(
revision
&&
!
access
(
arc_path
,
F_OK
))
{
while
(
revision
)
{
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
);
if
(
my_rename
(
old_path
,
new_path
,
MYF
(
0
)))
return
0
;
revision
--
;
}
}
return
0
;
}
Parameters:
thd thread handler
new_name new name of view
view view
Return values:
FALSE Ok
TRUE Error
*/
bool
mysql_rename_view
(
THD
*
thd
,
const
char
*
new_name
,
...
...
@@ -1438,7 +1416,8 @@ mysql_rename_view(THD *thd,
DBUG_RETURN
(
1
);
/* rename view and it's backups */
if
(
rename_view_files
(
view
->
db
,
view
->
table_name
,
new_name
,
view
->
revision
-
1
))
if
(
rename_in_schema_file
(
view
->
db
,
view
->
table_name
,
new_name
,
view
->
revision
-
1
,
num_view_backups
))
DBUG_RETURN
(
1
);
strxnmov
(
dir_buff
,
FN_REFLEN
,
mysql_data_home
,
"/"
,
view
->
db
,
"/"
,
NullS
);
...
...
@@ -1454,7 +1433,8 @@ mysql_rename_view(THD *thd,
if
(
sql_create_definition_file
(
&
pathstr
,
&
file
,
view_file_type
,
(
gptr
)
view
,
view_parameters
,
num_view_backups
))
{
/* restore renamed view in case of error */
rename_view_files
(
view
->
db
,
new_name
,
view
->
table_name
,
view
->
revision
-
1
);
rename_in_schema_file
(
view
->
db
,
new_name
,
view
->
table_name
,
view
->
revision
-
1
,
num_view_backups
);
DBUG_RETURN
(
1
);
}
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment