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
48ee575e
Commit
48ee575e
authored
Aug 21, 2000
by
monty@donna.mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge of last changes
parent
d79b0cc9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
208 additions
and
59 deletions
+208
-59
sql/ChangeLog
sql/ChangeLog
+4
-0
sql/mysql_priv.h
sql/mysql_priv.h
+12
-0
sql/sql_parse.cc
sql/sql_parse.cc
+60
-59
sql/sql_rename.cc
sql/sql_rename.cc
+132
-0
No files found.
sql/ChangeLog
View file @
48ee575e
2000-08-21 Michael Widenius <monty@mysql.com>
* Added RENAME TABLE.
2000-08-20 Michael Widenius <monty@mysql.com>
* Added memory as inline functions to THD to get them a bit faster
...
...
sql/mysql_priv.h
View file @
48ee575e
...
...
@@ -217,6 +217,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags);
int
mysql_rm_table
(
THD
*
thd
,
TABLE_LIST
*
tables
,
my_bool
if_exists
);
int
quick_rm_table
(
enum
db_type
base
,
const
char
*
db
,
const
char
*
table_name
);
bool
mysql_rename_tables
(
THD
*
thd
,
TABLE_LIST
*
table_list
);
bool
mysql_change_db
(
THD
*
thd
,
const
char
*
name
);
void
mysql_parse
(
THD
*
thd
,
char
*
inBuf
,
uint
length
);
void
mysql_init_select
(
LEX
*
lex
);
...
...
@@ -293,6 +294,11 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name,
List
<
Alter_column
>
&
alter_list
,
bool
drop_primary
,
enum
enum_duplicates
handle_duplicates
);
bool
mysql_rename_table
(
enum
db_type
base
,
const
char
*
old_db
,
const
char
*
old_name
,
const
char
*
new_db
,
const
char
*
new_name
);
bool
close_cached_table
(
THD
*
thd
,
TABLE
*
table
);
int
mysql_create_index
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
List
<
Key
>
&
keys
);
int
mysql_drop_index
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
...
...
@@ -316,6 +322,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
void
close_old_data_files
(
THD
*
thd
,
TABLE
*
table
,
bool
abort_locks
);
bool
close_data_tables
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
);
bool
wait_for_tables
(
THD
*
thd
);
bool
table_is_used
(
TABLE
*
table
);
bool
drop_locked_tables
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
);
void
abort_locked_tables
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
);
Field
*
find_field_in_tables
(
THD
*
thd
,
Item_field
*
item
,
TABLE_LIST
*
tables
);
...
...
@@ -488,6 +495,11 @@ void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table);
void
mysql_lock_abort
(
THD
*
thd
,
TABLE
*
table
);
MYSQL_LOCK
*
mysql_lock_merge
(
MYSQL_LOCK
*
a
,
MYSQL_LOCK
*
b
);
/* Lock based on name */
int
lock_table_name
(
THD
*
thd
,
TABLE_LIST
*
table_list
);
void
unlock_table_name
(
THD
*
thd
,
TABLE_LIST
*
table_list
);
bool
wait_for_locked_table_names
(
THD
*
thd
,
TABLE_LIST
*
table_list
);
extern
int
flush_master_info
(
MASTER_INFO
*
mi
);
/* old unireg functions */
...
...
sql/sql_parse.cc
View file @
48ee575e
This diff is collapsed.
Click to expand it.
sql/sql_rename.cc
0 → 100644
View file @
48ee575e
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Atomic rename of table; RENAME TABLE t1 to t2, tmp to t1 [,...]
*/
#include "mysql_priv.h"
static
TABLE_LIST
*
mysql_rename_tables
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
bool
skip_error
);
/*
Every second entry in the table_list is the original name and every
second entry is the new name.
*/
bool
mysql_rename_tables
(
THD
*
thd
,
TABLE_LIST
*
table_list
)
{
bool
error
=
1
,
got_all_locks
=
1
;
db_type
table_type
;
TABLE_LIST
*
lock_table
,
*
ren_table
=
0
,
*
new_table
;
DBUG_ENTER
(
"mysql_rename_tables"
);
/* Avoid problems with a rename on a table that we have locked or
if the user is trying to to do this in a transcation context */
if
(
thd
->
locked_tables
||
thd
->
active_transaction
())
{
my_error
(
ER_LOCK_OR_ACTIVE_TRANSACTION
,
MYF
(
0
));
DBUG_RETURN
(
1
);
}
VOID
(
pthread_mutex_lock
(
&
LOCK_open
));
for
(
lock_table
=
table_list
;
lock_table
;
lock_table
=
lock_table
->
next
)
{
int
got_lock
;
if
((
got_lock
=
lock_table_name
(
thd
,
lock_table
))
<
0
)
goto
end
;
if
(
got_lock
)
got_all_locks
=
0
;
}
if
(
!
got_all_locks
&&
wait_for_locked_table_names
(
thd
,
table_list
))
goto
end
;
if
(
!
(
ren_table
=
mysql_rename_tables
(
thd
,
table_list
,
0
)))
error
=
0
;
end:
if
(
ren_table
)
{
/* Rename didn't succeed; rename back the tables in reverse order */
TABLE_LIST
*
prev
=
0
,
*
table
;
/*
Reverse the table list ; Note that we need to handle the case that
every second entry must stay in place in respect to the previous
*/
while
(
table_list
)
{
TABLE_LIST
*
next
=
table_list
->
next
->
next
;
table_list
->
next
->
next
=
prev
;
prev
=
table_list
;
table_list
=
next
;
}
table_list
=
prev
;
/* Find the last renamed table */
for
(
table
=
table_list
;
table
->
next
!=
ren_table
;
table
=
table
->
next
->
next
)
;
table
=
table
->
next
->
next
;
// Skipp error table
/* Revert to old names */
mysql_rename_tables
(
thd
,
table
,
1
);
/* Note that lock_table == 0 here, so the unlock loop will work */
}
if
(
!
error
)
{
mysql_update_log
.
write
(
thd
->
query
,
thd
->
query_length
);
Query_log_event
qinfo
(
thd
,
thd
->
query
);
mysql_bin_log
.
write
(
&
qinfo
);
}
for
(
TABLE_LIST
*
table
=
table_list
;
table
!=
lock_table
;
table
=
table
->
next
)
unlock_table_name
(
thd
,
table
);
pthread_cond_broadcast
(
&
COND_refresh
);
pthread_mutex_unlock
(
&
LOCK_open
);
DBUG_RETURN
(
error
);
}
/*
Rename all tables in list; Return pointer to wrong entry if something goes
wrong.
*/
static
TABLE_LIST
*
mysql_rename_tables
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
bool
skip_error
)
{
TABLE_LIST
*
ren_table
;
for
(
ren_table
=
table_list
;
ren_table
;
ren_table
=
ren_table
->
next
)
{
db_type
table_type
;
char
name
[
FN_REFLEN
];
TABLE_LIST
*
new_table
=
ren_table
->
next
;
sprintf
(
name
,
"%s/%s/%s%s"
,
mysql_data_home
,
ren_table
->
db
,
ren_table
->
name
,
reg_ext
);
if
((
table_type
=
get_table_type
(
name
))
==
DB_TYPE_UNKNOWN
||
mysql_rename_table
(
table_type
,
ren_table
->
db
,
ren_table
->
name
,
new_table
->
db
,
new_table
->
name
))
{
if
(
!
skip_error
)
return
ren_table
;
}
}
return
0
;
}
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