diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 5e74e6fa68a..670b8754e30 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -59,3 +59,14 @@ t1 CREATE TABLE `t1` ( `length(uuid())` int(10) NOT NULL default '0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +create table t1 (a timestamp default '2005-05-05 01:01:01', +b timestamp default '2005-05-05 01:01:01'); +insert into t1 set a = now(); +select sleep(3); +sleep(3) +0 +update t1 set b = now(); +select timediff(b, a) >= '00:00:03' from t1; +timediff(b, a) >= '00:00:03' +1 +drop table t1; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index 5079e2605ce..f4cbacb93bb 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -46,3 +46,12 @@ drop table t1; create table t1 as select uuid(), length(uuid()); show create table t1; drop table t1; + +# Bug #6760: Add SLEEP() function +create table t1 (a timestamp default '2005-05-05 01:01:01', + b timestamp default '2005-05-05 01:01:01'); +insert into t1 set a = now(); +select sleep(3); +update t1 set b = now(); +select timediff(b, a) >= '00:00:03' from t1; +drop table t1; diff --git a/sql/item_create.cc b/sql/item_create.cc index b7d8d50f9b3..8798bf889fc 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -354,6 +354,11 @@ Item *create_func_sha(Item* a) return new Item_func_sha(a); } +Item *create_func_sleep(Item* a) +{ + return new Item_func_sleep(a); +} + Item *create_func_space(Item *a) { CHARSET_INFO *cs= current_thd->variables.collation_connection; diff --git a/sql/item_create.h b/sql/item_create.h index 0a9af144ec0..d757318bfc1 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -83,6 +83,7 @@ Item *create_func_sec_to_time(Item* a); Item *create_func_sign(Item* a); Item *create_func_sin(Item* a); Item *create_func_sha(Item* a); +Item *create_func_sleep(Item* a); Item *create_func_soundex(Item* a); Item *create_func_space(Item *); Item *create_func_sqrt(Item* a); diff --git a/sql/item_func.cc b/sql/item_func.cc index 71e0f29ffc7..ef1c85f6120 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3259,6 +3259,17 @@ void Item_func_benchmark::print(String *str) str->append(')'); } +/* This function is just used to create tests with time gaps */ + +longlong Item_func_sleep::val_int() +{ + DBUG_ASSERT(fixed == 1); + double time= args[0]->val_real(); + my_sleep((ulong)time*1000000L); + return 0; +} + + #define extra_size sizeof(double) static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, diff --git a/sql/item_func.h b/sql/item_func.h index e8db9d70ae7..1f25b762b70 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -874,6 +874,7 @@ public: } }; + class Item_func_benchmark :public Item_int_func { ulong loop_count; @@ -888,6 +889,16 @@ public: }; +class Item_func_sleep :public Item_int_func +{ +public: + Item_func_sleep(Item *a) :Item_int_func(a) {} + const char *func_name() const { return "sleep"; } + longlong val_int(); +}; + + + #ifdef HAVE_DLOPEN class Item_udf_func :public Item_func diff --git a/sql/lex.h b/sql/lex.h index 122e7040c80..7b6d86e327e 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -734,6 +734,7 @@ static SYMBOL sql_functions[] = { { "SIN", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)}, { "SHA", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)}, { "SHA1", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)}, + { "SLEEP", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sleep)}, { "SOUNDEX", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_soundex)}, { "SPACE", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)}, { "SQRT", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},