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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
349f1023
Commit
349f1023
authored
May 23, 2007
by
evgen@moonbone.local
Browse files
Options
Browse Files
Download
Plain Diff
Merge moonbone.local:/mnt/gentoo64/work/bk-trees/mysql-5.0-opt
into moonbone.local:/mnt/gentoo64/work/test-5.1-opt-mysql
parents
8ae4ebba
debb054d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
3 deletions
+112
-3
mysql-test/r/alter_table.result
mysql-test/r/alter_table.result
+19
-0
mysql-test/t/alter_table.test
mysql-test/t/alter_table.test
+24
-0
sql/sql_table.cc
sql/sql_table.cc
+69
-3
No files found.
mysql-test/r/alter_table.result
View file @
349f1023
...
@@ -846,6 +846,25 @@ id
...
@@ -846,6 +846,25 @@ id
50
50
51
51
drop table t1;
drop table t1;
set @orig_sql_mode = @@sql_mode;
set sql_mode="no_zero_date";
create table t1(f1 int);
alter table t1 add column f2 datetime not null, add column f21 date not null;
insert into t1 values(1,'2000-01-01','2000-01-01');
alter table t1 add column f3 datetime not null;
ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'f3' at row 1
alter table t1 add column f3 date not null;
ERROR 22007: Incorrect date value: '0000-00-00' for column 'f3' at row 1
alter table t1 add column f4 datetime not null default '2002-02-02',
add column f41 date not null;
ERROR 22007: Incorrect date value: '0000-00-00' for column 'f41' at row 1
alter table t1 add column f4 datetime not null default '2002-02-02',
add column f41 date not null default '2002-02-02';
select * from t1;
f1 f2 f21 f4 f41
1 2000-01-01 00:00:00 2000-01-01 2002-02-02 00:00:00 2002-02-02
drop table t1;
set sql_mode= @orig_sql_mode;
create table t1 (v varchar(32));
create table t1 (v varchar(32));
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
select * from t1;
select * from t1;
...
...
mysql-test/t/alter_table.test
View file @
349f1023
...
@@ -631,6 +631,30 @@ insert into t1 values (null);
...
@@ -631,6 +631,30 @@ insert into t1 values (null);
select
*
from
t1
;
select
*
from
t1
;
drop
table
t1
;
drop
table
t1
;
#
# Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the
# NO_ZERO_DATE mode.
#
set
@
orig_sql_mode
=
@@
sql_mode
;
set
sql_mode
=
"no_zero_date"
;
create
table
t1
(
f1
int
);
alter
table
t1
add
column
f2
datetime
not
null
,
add
column
f21
date
not
null
;
insert
into
t1
values
(
1
,
'2000-01-01'
,
'2000-01-01'
);
--
error
1292
alter
table
t1
add
column
f3
datetime
not
null
;
--
error
1292
alter
table
t1
add
column
f3
date
not
null
;
--
error
1292
alter
table
t1
add
column
f4
datetime
not
null
default
'2002-02-02'
,
add
column
f41
date
not
null
;
alter
table
t1
add
column
f4
datetime
not
null
default
'2002-02-02'
,
add
column
f41
date
not
null
default
'2002-02-02'
;
select
*
from
t1
;
drop
table
t1
;
set
sql_mode
=
@
orig_sql_mode
;
#
# Some additional tests for new, faster alter table. Note that most of the
# Some additional tests for new, faster alter table. Note that most of the
# whole alter table code is being tested all around the test suite already.
# whole alter table code is being tested all around the test suite already.
#
#
...
...
sql/sql_table.cc
View file @
349f1023
...
@@ -37,7 +37,8 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
...
@@ -37,7 +37,8 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
List
<
create_field
>
&
create
,
bool
ignore
,
List
<
create_field
>
&
create
,
bool
ignore
,
uint
order_num
,
ORDER
*
order
,
uint
order_num
,
ORDER
*
order
,
ha_rows
*
copied
,
ha_rows
*
deleted
,
ha_rows
*
copied
,
ha_rows
*
deleted
,
enum
enum_enable_or_disable
keys_onoff
);
enum
enum_enable_or_disable
keys_onoff
,
bool
error_if_not_empty
);
static
bool
prepare_blob_field
(
THD
*
thd
,
create_field
*
sql_field
);
static
bool
prepare_blob_field
(
THD
*
thd
,
create_field
*
sql_field
);
static
bool
check_engine
(
THD
*
,
const
char
*
,
HA_CREATE_INFO
*
);
static
bool
check_engine
(
THD
*
,
const
char
*
,
HA_CREATE_INFO
*
);
...
@@ -5405,6 +5406,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
...
@@ -5405,6 +5406,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
legacy_db_type
table_type
;
legacy_db_type
table_type
;
HA_CREATE_INFO
*
create_info
;
HA_CREATE_INFO
*
create_info
;
frm_type_enum
frm_type
;
frm_type_enum
frm_type
;
/*
Throw an error if the table to be altered isn't empty.
Used in DATE/DATETIME fields default value checking.
*/
bool
error_if_not_empty
=
FALSE
;
/*
A field used for error reporting in DATE/DATETIME fields default
value checking.
*/
create_field
*
new_datetime_field
=
0
;
uint
need_copy_table
=
0
;
uint
need_copy_table
=
0
;
bool
no_table_reopen
=
FALSE
,
varchar
=
FALSE
;
bool
no_table_reopen
=
FALSE
,
varchar
=
FALSE
;
#ifdef WITH_PARTITION_STORAGE_ENGINE
#ifdef WITH_PARTITION_STORAGE_ENGINE
...
@@ -5879,6 +5890,22 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
...
@@ -5879,6 +5890,22 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
my_error
(
ER_BAD_FIELD_ERROR
,
MYF
(
0
),
def
->
change
,
table_name
);
my_error
(
ER_BAD_FIELD_ERROR
,
MYF
(
0
),
def
->
change
,
table_name
);
goto
err
;
goto
err
;
}
}
/*
Check that the DATE/DATETIME not null field we are going to add is
either has a default value or the '0000-00-00' is allowed by the
set sql mode.
If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
flag to allow ALTER TABLE only if the table to be altered is empty.
*/
if
((
def
->
sql_type
==
MYSQL_TYPE_DATE
||
def
->
sql_type
==
MYSQL_TYPE_NEWDATE
||
def
->
sql_type
==
MYSQL_TYPE_DATETIME
)
&&
!
new_datetime_field
&&
!
(
~
def
->
flags
&
(
NO_DEFAULT_VALUE_FLAG
|
NOT_NULL_FLAG
))
&&
thd
->
variables
.
sql_mode
&
MODE_NO_ZERO_DATE
)
{
new_datetime_field
=
def
;
error_if_not_empty
=
TRUE
;
}
if
(
!
def
->
after
)
if
(
!
def
->
after
)
create_list
.
push_back
(
def
);
create_list
.
push_back
(
def
);
else
if
(
def
->
after
==
first_keyword
)
else
if
(
def
->
after
==
first_keyword
)
...
@@ -6369,7 +6396,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
...
@@ -6369,7 +6396,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
new_table
->
next_number_field
=
new_table
->
found_next_number_field
;
new_table
->
next_number_field
=
new_table
->
found_next_number_field
;
error
=
copy_data_between_tables
(
table
,
new_table
,
create_list
,
ignore
,
error
=
copy_data_between_tables
(
table
,
new_table
,
create_list
,
ignore
,
order_num
,
order
,
&
copied
,
&
deleted
,
order_num
,
order
,
&
copied
,
&
deleted
,
alter_info
->
keys_onoff
);
alter_info
->
keys_onoff
,
error_if_not_empty
);
}
}
else
else
{
{
...
@@ -6856,6 +6884,37 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
...
@@ -6856,6 +6884,37 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
VOID
(
quick_rm_table
(
new_db_type
,
new_db
,
tmp_name
,
FN_IS_TMP
));
VOID
(
quick_rm_table
(
new_db_type
,
new_db
,
tmp_name
,
FN_IS_TMP
));
err:
err:
/*
No default value was provided for a DATE/DATETIME field, the
current sql_mode doesn't allow the '0000-00-00' value and
the table to be altered isn't empty.
Report error here.
*/
if
(
error_if_not_empty
&&
thd
->
row_count
)
{
const
char
*
f_val
=
0
;
enum
enum_mysql_timestamp_type
t_type
=
MYSQL_TIMESTAMP_DATE
;
switch
(
new_datetime_field
->
sql_type
)
{
case
MYSQL_TYPE_DATE
:
case
MYSQL_TYPE_NEWDATE
:
f_val
=
"0000-00-00"
;
t_type
=
MYSQL_TIMESTAMP_DATE
;
break
;
case
MYSQL_TYPE_DATETIME
:
f_val
=
"0000-00-00 00:00:00"
;
t_type
=
MYSQL_TIMESTAMP_DATETIME
;
break
;
default:
/* Shouldn't get here. */
DBUG_ASSERT
(
0
);
}
bool
save_abort_on_warning
=
thd
->
abort_on_warning
;
thd
->
abort_on_warning
=
TRUE
;
make_truncated_value_warning
(
thd
,
f_val
,
strlength
(
f_val
),
t_type
,
new_datetime_field
->
field_name
);
thd
->
abort_on_warning
=
save_abort_on_warning
;
}
if
(
name_lock
)
if
(
name_lock
)
{
{
pthread_mutex_lock
(
&
LOCK_open
);
pthread_mutex_lock
(
&
LOCK_open
);
...
@@ -6873,7 +6932,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,
...
@@ -6873,7 +6932,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,
uint
order_num
,
ORDER
*
order
,
uint
order_num
,
ORDER
*
order
,
ha_rows
*
copied
,
ha_rows
*
copied
,
ha_rows
*
deleted
,
ha_rows
*
deleted
,
enum
enum_enable_or_disable
keys_onoff
)
enum
enum_enable_or_disable
keys_onoff
,
bool
error_if_not_empty
)
{
{
int
error
;
int
error
;
Copy_field
*
copy
,
*
copy_end
;
Copy_field
*
copy
,
*
copy_end
;
...
@@ -6985,6 +7045,12 @@ copy_data_between_tables(TABLE *from,TABLE *to,
...
@@ -6985,6 +7045,12 @@ copy_data_between_tables(TABLE *from,TABLE *to,
break
;
break
;
}
}
thd
->
row_count
++
;
thd
->
row_count
++
;
/* Return error if source table isn't empty. */
if
(
error_if_not_empty
)
{
error
=
1
;
break
;
}
if
(
to
->
next_number_field
)
if
(
to
->
next_number_field
)
{
{
if
(
auto_increment_field_copied
)
if
(
auto_increment_field_copied
)
...
...
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