Commit 6337ea8a authored by konstantin@mysql.com's avatar konstantin@mysql.com

A fix and test case for Bug#6297 "prepared statement, wrong handling

 of <parameter> IS NULL":
we must not only set Item::null_value in Item_param, but implement
Item_param::is_null() to work well with IS NULL/IS NOT NULL clauses.
parent 59c0102e
......@@ -450,3 +450,24 @@ PREPARE stmt FROM 'UPDATE t1 AS P1 INNER JOIN (SELECT N FROM t1 GROUP BY N HAVIN
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
prepare stmt from "select ? is null, ? is not null, ?";
select @no_such_var is null, @no_such_var is not null, @no_such_var;
@no_such_var is null @no_such_var is not null @no_such_var
1 0 NULL
execute stmt using @no_such_var, @no_such_var, @no_such_var;
? is null ? is not null ?
1 0 NULL
set @var='abc';
select @var is null, @var is not null, @var;
@var is null @var is not null @var
0 1 abc
execute stmt using @var, @var, @var;
? is null ? is not null ?
0 1 abc
set @var=null;
select @var is null, @var is not null, @var;
@var is null @var is not null @var
1 0 NULL
execute stmt using @var, @var, @var;
? is null ? is not null ?
1 0 NULL
......@@ -458,3 +458,17 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
# Bug#6297 "prepared statement, wrong handling of <parameter> IS NULL"
# Test that placeholders work with IS NULL/IS NOT NULL clauses.
#
prepare stmt from "select ? is null, ? is not null, ?";
select @no_such_var is null, @no_such_var is not null, @no_such_var;
execute stmt using @no_such_var, @no_such_var, @no_such_var;
set @var='abc';
select @var is null, @var is not null, @var;
execute stmt using @var, @var, @var;
set @var=null;
select @var is null, @var is not null, @var;
execute stmt using @var, @var, @var;
......@@ -266,6 +266,14 @@ public:
virtual bool get_time(TIME *ltime);
virtual bool get_date_result(TIME *ltime,uint fuzzydate)
{ return get_date(ltime,fuzzydate); }
/*
This function is used only in Item_func_isnull/Item_func_isnotnull
(implementations of IS NULL/IS NOT NULL clauses). Item_func_is{not}null
calls this method instead of one of val/result*() methods, which
normally will set null_value. This allows to determine nullness of
a complex expression without fully evaluating it.
Any new item which can be NULL must implement this call.
*/
virtual bool is_null() { return 0; }
/*
it is "top level" item of WHERE clause and we do not need correct NULL
......@@ -573,6 +581,8 @@ public:
void print(String *str) { str->append('?'); }
/* parameter never equal to other parameter of other item */
bool eq(const Item *item, bool binary_cmp) const { return 0; }
bool is_null()
{ DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
};
class Item_int :public Item_num
......
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