Commit 409afdc8 authored by unknown's avatar unknown

Fixed BUG#3486: FOUND_ROWS() fails inside stored procedure [and prepared statement].


mysql-test/r/ps.result:
  New test case for BUG#3486.
mysql-test/t/ps.test:
  New test case for BUG#3486.
sql/item_create.cc:
  Create an Item_func_found_rows() at parse time, not an Item_int.
sql/item_func.cc:
  Added val_int() method for new Item_func_found_rows class.
sql/item_func.h:
  New class Item_func_found_rows for FOUND_ROWS() function.
sql/sql_select.cc:
  Don't reset thd->limit_found_rows too early, or FOUND_ROWS() wont work.
parent 3d87ec49
......@@ -119,3 +119,21 @@ EXECUTE stmt1 USING @var;
_utf8 'A' collate utf8_bin = ?
1
DEALLOCATE PREPARE stmt1;
create table t1 (id int);
prepare stmt1 from "select FOUND_ROWS()";
select SQL_CALC_FOUND_ROWS * from t1;
id
execute stmt1;
FOUND_ROWS()
0
insert into t1 values (1);
select SQL_CALC_FOUND_ROWS * from t1;
id
1
execute stmt1;
FOUND_ROWS()
1
execute stmt1;
FOUND_ROWS()
0
deallocate prepare stmt1;
......@@ -124,3 +124,19 @@ PREPARE stmt1 FROM "select _utf8 'A' collate utf8_bin = ?";
set @var='A';
EXECUTE stmt1 USING @var;
DEALLOCATE PREPARE stmt1;
#
# BUG#3486: FOUND_ROWS() fails inside stored procedure [and prepared statement]
#
create table t1 (id int);
prepare stmt1 from "select FOUND_ROWS()";
select SQL_CALC_FOUND_ROWS * from t1;
# Expect 0
execute stmt1;
insert into t1 values (1);
select SQL_CALC_FOUND_ROWS * from t1;
# Expect 1
execute stmt1;
# Expect 0
execute stmt1;
deallocate prepare stmt1;
......@@ -154,7 +154,7 @@ Item *create_func_found_rows(void)
{
THD *thd=current_thd;
thd->lex->safe_to_cache_query= 0;
return new Item_int(NullS,(longlong) thd->found_rows(),21);
return new Item_func_found_rows();
}
Item *create_func_from_days(Item* a)
......
......@@ -3234,3 +3234,12 @@ longlong Item_func_is_used_lock::val_int()
null_value=0;
return ull->thread_id;
}
longlong Item_func_found_rows::val_int()
{
DBUG_ASSERT(fixed == 1);
THD *thd= current_thd;
return thd->found_rows();
}
......@@ -1071,3 +1071,13 @@ enum Cast_target
ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR
};
class Item_func_found_rows :public Item_int_func
{
public:
Item_func_found_rows() :Item_int_func() {}
longlong val_int();
const char *func_name() const { return "found_rows"; }
void fix_length_and_dec() { decimals= 0; maybe_null=0; }
};
......@@ -1088,12 +1088,14 @@ JOIN::exec()
DBUG_ENTER("JOIN::exec");
error= 0;
thd->limit_found_rows= thd->examined_row_count= 0;
if (procedure)
{
if (procedure->change_columns(fields_list) ||
result->prepare(fields_list, unit))
{
thd->limit_found_rows= thd->examined_row_count= 0;
DBUG_VOID_RETURN;
}
}
if (!tables_list)
......@@ -1119,8 +1121,10 @@ JOIN::exec()
else
error=(int) result->send_eof();
}
thd->limit_found_rows= thd->examined_row_count= 0;
DBUG_VOID_RETURN;
}
thd->limit_found_rows= thd->examined_row_count= 0;
if (zero_result_cause)
{
......
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