Commit 7eebb751 authored by unknown's avatar unknown
Browse files

Add SLEEP(seconds) function, which always returns 0 after the given

number of seconds (which can include microseconds). (Bug #6760)


mysql-test/r/func_misc.result:
  Add new results
mysql-test/t/func_misc.test:
  Add new regression test.
sql/item_create.cc:
  Add create_func_sleep()
sql/item_create.h:
  Add create_func_sleep()
sql/item_func.cc:
  Add sleep() implementation
sql/item_func.h:
  Add class for sleep() function
sql/lex.h:
  Handle SLEEP() function
parent 036c5b28
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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;
+9 −0
Original line number Diff line number Diff line
@@ -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;
+5 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -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,
Loading