A fix and test case for bug#5510 "inserting Null in AutoIncrement primary

key Column Fails".
This commit is contained in:
konstantin@mysql.com 2004-09-18 01:10:09 +04:00
parent c12c9af224
commit 4230eae857
8 changed files with 52 additions and 7 deletions

View File

@ -270,3 +270,22 @@ execute stmt using @var;
a
deallocate prepare stmt;
drop table t1;
create table t1 (a bigint(20) not null primary key auto_increment);
insert into t1 (a) values (null);
select * from t1;
a
1
prepare stmt from "insert into t1 (a) values (?)";
set @var=null;
execute stmt using @var;
select * from t1;
a
1
2
drop table t1;
create table t1 (a timestamp not null);
prepare stmt from "insert into t1 (a) values (?)";
execute stmt using @var;
select * from t1;
deallocate prepare stmt;
drop table t1;

View File

@ -1015,7 +1015,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
1 one

View File

@ -1015,7 +1015,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
0 two

View File

@ -1016,7 +1016,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
1 one

View File

@ -1058,7 +1058,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
3 three
@ -2253,7 +2253,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
3 three

View File

@ -1015,7 +1015,7 @@ set @arg00=NULL;
set @arg01=2;
execute stmt1 using @arg00, @arg01;
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'a' at row 1
select a,b from t1;
a b
0 two

View File

@ -278,3 +278,29 @@ execute stmt using @var;
deallocate prepare stmt;
drop table t1;
#
# BUG#5510 "inserting Null in AutoIncrement primary key Column Fails"
# (prepared statements)
# The cause: misuse of internal MySQL 'Field' API.
#
create table t1 (a bigint(20) not null primary key auto_increment);
insert into t1 (a) values (null);
select * from t1;
prepare stmt from "insert into t1 (a) values (?)";
set @var=null;
execute stmt using @var;
select * from t1;
drop table t1;
#
# check the same for timestamps
#
create table t1 (a timestamp not null);
prepare stmt from "insert into t1 (a) values (?)";
execute stmt using @var;
--disable_result_log
select * from t1;
--enable_result_log
deallocate prepare stmt;
drop table t1;

View File

@ -891,7 +891,7 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
return field->store(str_value.ptr(), str_value.length(),
str_value.charset());
case NULL_VALUE:
return set_field_to_null(field);
return set_field_to_null_with_conversions(field, no_conversions);
case NO_VALUE:
default:
DBUG_ASSERT(0);