/**
 * mysql兼容函数：java udr
 */
-- JASCII(s)函数：返回字符对应的ASCII码值
-- ascii
drop function if exists jascii(lvarchar);
create dba function jascii(lvarchar)
returns int with (not variant)
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.ascii(java.lang.String)'
language java;

-- RANDOM()函数：返回0-1之间的随机数
-- random 随机函数（0-1之间）
drop function if exists random();
create dba function random()
returns float
  external name 'com.gbasedbt.judr.math.Math.randdouble()'
language java;

-- BIN(x)函数：返回数值x对应的字符型二进制值
-- bin(x)，返回二进制
drop function if exists BIN(int);
create dba function BIN(x int)
returns lvarchar with (not variant)
  external name 'com.gbasedbt.judr.math.Math.dec2bin(int)'
language java;

-- CONV(x,from,to)函数：进制转换函数，支持2，8，10，16进制间转换
-- conv 进制转换函数
drop function if exists conv(lvarchar,int,int);
create dba function conv(lvarchar,int,int)
returns lvarchar
with (not variant)
  external name 'com.gbasedbt.judr.math.Math.conv(java.lang.String,int,int)'
language java;

-- IFNULL(str1,str)函数：如果str1为null，返回str2
-- ifnull
drop function if exists ifnull(lvarchar,lvarchar);
create dba function ifnull(lvarchar,lvarchar)
returns lvarchar
with (not variant, handlesnulls)
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.ifnull(java.lang.String,java.lang.String)'
language java;

-- ENCRYPTAES(str, key)函数：AES加密函数
-- encryptAES，指定key
drop function if exists encryptAES(lvarchar,lvarchar);
create dba function encryptAES(lvarchar,lvarchar)
returns lvarchar with (not variant)
  external name 'com.gbasedbt.judr.crypt.Crypt.encryptAESHex(java.lang.String,java.lang.String)'
language java;

-- 默认key
drop function if exists encryptAES(lvarchar);
create dba function encryptAES(lvarchar)
returns lvarchar with (not variant)
  external name 'com.gbasedbt.judr.crypt.Crypt.encryptAESHex(java.lang.String)'
language java;

-- DECRYPTAES(str, key)函数：AES解密函数
-- decryptAES (PKCS5)，指定key
drop function if exists decryptAES(lvarchar,lvarchar);
create dba function decryptAES(lvarchar,lvarchar)
returns lvarchar with (not variant)
  external name 'com.gbasedbt.judr.crypt.Crypt.decryptAES(java.lang.String,java.lang.String)'
language java;

-- 默认key
drop function if exists decryptAES(lvarchar);
create dba function decryptAES(lvarchar)
returns lvarchar with (not variant)
  external name 'com.gbasedbt.judr.crypt.Crypt.decryptAES(java.lang.String)'
language java;

--其他函数，可使用UDR也可以使用Java UDR，视情况使用：
-- JUUID()函数：兼容mysql的UUID()函数
-- uuid
drop function if exists juuid;
create dba function juuid()
returns lvarchar
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.UUID()'
language java;

-- UNIX_TIMESTAMP()函数：返回当前或者指定日期时间的相对于1970-01-01 08:00:00的秒数
-- unix_timestamp
drop function if exists unix_timestamp();
create dba function unix_timestamp()
returns int with (not variant)
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.unix_timestamp()'
language java;

drop function if exists unix_timestamp(lvarchar);
create dba function unix_timestamp(lvarchar)
returns int
with (not variant)
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.unix_timestamp(java.lang.String)'
language java;

-- FROM_UNIXTIME()函数：返回给定秒数相对于1970-01-01 08:00:00的日期时间
-- from_unixtime
drop function if exists from_unixtime(int);
create dba function from_unixtime(int)
returns lvarchar
with (not variant)
  external name 'com.gbasedbt.judr.mysql.MysqlFunc.from_unixtime(long)'
language java;
