Commit 99054db6 authored by unknown's avatar unknown

Fixed bug #32335.

Comparison of a BIGINT NOT NULL column with a constant arithmetic
expression that evaluates to NULL caused error 1048: "Column '...'
cannot be null".

Made convert_constant_item() check if the constant expression is NULL
before attempting to store it in a field. Attempts to store NULL in a
NOT NULL field caused query errors.


sql/item_cmpfunc.cc:
  Fixed bug #32335.
  1. Made convert_constant_item() check if the constant expression is NULL
     before attempting to store it in a field. Attempts to store NULL in
     a NOT NULL field caused query errors.
  
  2. Also minor bug has been fixed: the thd->count_cuted_fields value
     was not restored in case of successful conversion.
mysql-test/t/select.test:
  Added test case for bug #32335.
mysql-test/r/select.result:
  Added test case for bug #32335.
parent 4b48eb6f
......@@ -4322,4 +4322,10 @@ c3
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1 (c1 BIGINT NOT NULL);
INSERT INTO t1 (c1) VALUES (1);
SELECT * FROM t1 WHERE c1 > NULL + 1;
c1
DROP TABLE t1;
End of 5.0 tests
......@@ -3661,4 +3661,15 @@ DROP TABLE t2;
###########################################################################
#
# Bug #32335: Error on BIGINT > NULL + 1
#
CREATE TABLE t1 (c1 BIGINT NOT NULL);
INSERT INTO t1 (c1) VALUES (1);
SELECT * FROM t1 WHERE c1 > NULL + 1;
DROP TABLE t1;
--echo
--echo End of 5.0 tests
......@@ -350,11 +350,12 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item)
thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
MODE_INVALID_DATES;
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
if (!(*item)->save_in_field(field, 1) && !((*item)->null_value))
if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
{
Item *tmp=new Item_int_with_ref(field->val_int(), *item,
test(field->flags & UNSIGNED_FLAG));
thd->variables.sql_mode= orig_sql_mode;
thd->count_cuted_fields= orig_count_cuted_fields;
if (tmp)
thd->change_item_tree(item, tmp);
return 1; // Item was replaced
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment