From 948bb77d4eb2c6d0684227219bf577626ceb6c11 Mon Sep 17 00:00:00 2001 From: unknown <pem@mysql.comhem.se> Date: Fri, 25 Feb 2005 13:19:44 +0100 Subject: [PATCH] Fixed BUG#6857: current_time() in STORED PROCEDURES Have to thd->set_time() before each substatement execution, to make current_time() et al return different times within the same procedure. mysql-test/r/sp.result: New test case for BUG#6857: current_time() in STORED PROCEDURES. Note: The actual call is disable, to save time when running with slow debugging tools. mysql-test/t/sp.test: New test case for BUG#6857: current_time() in STORED PROCEDURES. Note: The actual call is disable, to save time when running with slow debugging tools. sql/sp_head.cc: Make current_time() et all work in stored procedures. --- mysql-test/r/sp.result | 16 ++++++++++++++++ mysql-test/t/sp.test | 31 +++++++++++++++++++++++++++++++ sql/sp_head.cc | 1 + 3 files changed, 48 insertions(+) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index f2b99b7074a..dc1a01e5ab9 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -2158,6 +2158,22 @@ call bug8116(42)| userid drop procedure bug8116| drop table t3| +drop procedure if exists bug6857| +create procedure bug6857(counter int) +begin +declare t0, t1 int; +declare plus bool default 0; +set t0 = current_time(); +while counter > 0 do +set counter = counter - 1; +end while; +set t1 = current_time(); +if t1 > t0 then +set plus = 1; +end if; +select plus; +end| +drop procedure bug6857| drop table if exists fac| create table fac (n int unsigned not null primary key, f bigint unsigned)| drop procedure if exists ifac| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 2cfd27134ad..21c7756fcc4 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -2645,6 +2645,37 @@ call bug8116(42)| drop procedure bug8116| drop table t3| +# +# BUG#6857: current_time() in STORED PROCEDURES +# +--disable_warnings +drop procedure if exists bug6857| +--enable_warnings +create procedure bug6857(counter int) +begin + declare t0, t1 int; + declare plus bool default 0; + + set t0 = current_time(); + while counter > 0 do + set counter = counter - 1; + end while; + set t1 = current_time(); + if t1 > t0 then + set plus = 1; + end if; + select plus; +end| + +# QQ: This is currently disabled. Not only does it slow down a normal test +# run, it makes running with valgrind (or similar tools) extremely +# painful. +# Make sure this takes at least one second on all machines in all builds. +# 30000 makes it about 3 seconds on an old 1.1GHz linux. +#call bug6857(300000)| + +drop procedure bug6857| + # # Some "real" examples diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 72e2204f1b4..148e8db990e 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -503,6 +503,7 @@ sp_head::execute(THD *thd) if (i == NULL) break; DBUG_PRINT("execute", ("Instruction %u", ip)); + thd->set_time(); // Make current_time() et al work ret= i->execute(thd, &ip); thd->rollback_item_tree_changes(); if (i->free_list) -- 2.30.9