mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fixed BUG#3486: FOUND_ROWS() fails inside stored procedure [and prepared statement].
This commit is contained in:
@ -119,3 +119,21 @@ EXECUTE stmt1 USING @var;
|
|||||||
_utf8 'A' collate utf8_bin = ?
|
_utf8 'A' collate utf8_bin = ?
|
||||||
1
|
1
|
||||||
DEALLOCATE PREPARE stmt1;
|
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';
|
set @var='A';
|
||||||
EXECUTE stmt1 USING @var;
|
EXECUTE stmt1 USING @var;
|
||||||
DEALLOCATE PREPARE stmt1;
|
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 *thd=current_thd;
|
||||||
thd->lex->safe_to_cache_query= 0;
|
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)
|
Item *create_func_from_days(Item* a)
|
||||||
|
@ -3234,3 +3234,12 @@ longlong Item_func_is_used_lock::val_int()
|
|||||||
null_value=0;
|
null_value=0;
|
||||||
return ull->thread_id;
|
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_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
|
||||||
ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR
|
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");
|
DBUG_ENTER("JOIN::exec");
|
||||||
|
|
||||||
error= 0;
|
error= 0;
|
||||||
thd->limit_found_rows= thd->examined_row_count= 0;
|
|
||||||
if (procedure)
|
if (procedure)
|
||||||
{
|
{
|
||||||
if (procedure->change_columns(fields_list) ||
|
if (procedure->change_columns(fields_list) ||
|
||||||
result->prepare(fields_list, unit))
|
result->prepare(fields_list, unit))
|
||||||
|
{
|
||||||
|
thd->limit_found_rows= thd->examined_row_count= 0;
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tables_list)
|
if (!tables_list)
|
||||||
@ -1119,8 +1121,10 @@ JOIN::exec()
|
|||||||
else
|
else
|
||||||
error=(int) result->send_eof();
|
error=(int) result->send_eof();
|
||||||
}
|
}
|
||||||
|
thd->limit_found_rows= thd->examined_row_count= 0;
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
thd->limit_found_rows= thd->examined_row_count= 0;
|
||||||
|
|
||||||
if (zero_result_cause)
|
if (zero_result_cause)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user