Commit 3507a52e authored by unknown's avatar unknown
Browse files

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.


mysql-test/r/ps.result:
  Test case for Bug#6297: test results fixed.
mysql-test/t/ps.test:
  A test case for Bug#6297 "prepared statement, wrong handling of 
  <parameter> IS NULL"
sql/item.h:
  A fix for Bug#6297: we must not only set null_value in Item_param, but
  also implement Item_param::is_null() to work well with  IS NULL/
  IS NOT NULL.
  Item::is_null() commented.
parent 99d2d100
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -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
+14 −0
Original line number Diff line number Diff line
@@ -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;
+10 −0
Original line number Diff line number Diff line
@@ -266,6 +266,14 @@ class Item {
  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 @@ class Item_param :public Item
  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