# Test of functions
# 
# mysql -v test < this_file

#
# numerical functions
#
select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),-(1+1)*-2,sign(-5) ;
select floor(5.5),floor(-5.5),ceiling(5.5),ceiling(-5.5),round(5.5),round(-5.5);
select abs(-10),log(exp(10)),exp(log(sqrt(10))*2),pow(10,log10(10)),rand(999999),rand();
select min(1,2),max(3,4,5) ;
select 1 | 2,5 & 3,bit_count(7) ;
#
# test functions
#
select NULL=NULL,0=0,1>0,1>=1,1<0,1<=0,strcmp("abc","abcd"),strcmp("b","a"),strcmp("a","a") ;
select "a"<"b","a"<="b","b">="a","b">"a","a"="A","a"<>"b","abc" like "a%", "abc" not like "%d%" ;
select "Det här är svenska" regexp "h[[:alpha:]]+r", "aba" regexp "^(a|b)*$";
select !0,NOT 0=1,!(0=0),1 AND 1,1 && 0,0 OR 1,1 || NULL ;
select null,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null;
select IF(0,"ERROR","this"),IF(1,"is","ERROR"),IF(NULL,"ERROR","a"),IF(1,2,3) ;
select between(2,1,3),between("monty","max","my"),between(NULL,1,2),between(2,NULL,3),between(2,1,null),between(2,null,1),between(2,3,null),2 between 1 and 3;

#
# string functions
#
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
select concat("monty"," was here ","again"),length("hello"),locate("hello","he"),locate("hello","he",2),locate("hello","lo",2)  ;
select left("hello",2),right("hello",2),substring("hello",2,2),mid("hello",3,2) ;
select concat(left(right(concat("what ",concat("is ","happening")),9),4),substring("monty",5,1)) ;
select concat("!",ltrim("  left  "),"!",rtrim("  right  "),"!");
select insert("txs",2,1,"hi"),insert("is ",4,0,"a"),insert("txxxxt",2,4,"es");
select replace("aaaa","a","b"),replace("aaaa","aa","b"),replace("aaaa","a","bb") ;
select replace(concat(lcase(concat("THIS"," ","IS"," ","A"," ")),ucase("false")," ","test"),"FALSE","REAL") ;
select soundex(""),soundex("he"),soundex("hello all folks");

#
# misc functions
#
select interval(55,10,20,30,40,50,60,70,80,90,100),interval(3,1,1+1,1+1+1+1),field("IBM","NCA","ICL","SUN","IBM","DIGITAL"),elt(2,"ONE","TWO","THREE") ;
select format(1.5555,0),format(123.5555,1),format(1234.5555,2),format(12345.5555,3),format(123456.5555,4),format(1234567.5555,5),format("12345.2399",2);

#
# system functions
#

select database(),user();

#
# time functions
# These should return new values for each test run
#

select from_days(to_days("960101")),to_days(960201)-to_days("19960101"),to_days(curdate()+1)-to_days(curdate()),weekday("1997-01-01") ;
select period_add("9602",-12),period_diff(199505,"9404") ;

select now(),curdate(),weekday(curdate()),weekday(now()),unix_timestamp(),unix_timestamp(now());
