From 4230eae8575cd495167d5be99c0fae744673a8b5 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Sat, 18 Sep 2004 01:10:09 +0400 Subject: [PATCH] A fix and test case for bug#5510 "inserting Null in AutoIncrement primary key Column Fails". --- mysql-test/r/ps.result | 19 +++++++++++++++++++ mysql-test/r/ps_2myisam.result | 2 +- mysql-test/r/ps_3innodb.result | 2 +- mysql-test/r/ps_4heap.result | 2 +- mysql-test/r/ps_5merge.result | 4 ++-- mysql-test/r/ps_6bdb.result | 2 +- mysql-test/t/ps.test | 26 ++++++++++++++++++++++++++ sql/item.cc | 2 +- 8 files changed, 52 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 321b8894796..8742ac29989 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -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; diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index 16d3cdbbb47..7e183118e61 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -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 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 865b108d7ed..d33e3c610c0 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -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 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 1cc18575dd1..b5888795666 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -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 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 2d67635cc10..7d78f4b9e1c 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -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 diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index 8fe76dae3ab..c5cde1b755a 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -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 diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index c739e28849e..af356ca2a09 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -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; + diff --git a/sql/item.cc b/sql/item.cc index 8233d050783..14136435a50 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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);