Commit 18ad1768 authored by halfspawn's avatar halfspawn Committed by Alexander Barkov

MDEV-12685 Oracle-compatible function CHR()

parent 71fa413c
......@@ -117,4 +117,32 @@ update t1 set pk='test' where pk=@p;
drop table t1;
# End of 4.1 tests
--echo #
--echo # Start of 10.3 tests
--echo #
--echo #
--echo # MDEV-12685 Oracle-compatible function CHR()
--echo #
connection master;
CREATE DATABASE db1 DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
USE db1;
CREATE TABLE t1 AS SELECT CHR(0x60);
sync_slave_with_master;
SHOW CREATE TABLE db1.t1;
connection master;
USE test;
DROP DATABASE db1;
sync_slave_with_master;
--echo #
--echo # End of 10.3 tests
--echo #
--source include/rpl_end.inc
......@@ -4843,6 +4843,22 @@ YQ== 61
Yq== 62
DROP TABLE t1;
#
# MDEV-12685 Oracle-compatible function CHR()
#
select chr(65);
chr(65)
A
create database mysqltest1 CHARACTER SET = 'utf8' COLLATE = 'utf8_bin';
use mysqltest1;
select charset(chr(65)), length(chr(65)),char_length(chr(65));
charset(chr(65)) length(chr(65)) char_length(chr(65))
utf8 1 1
select charset(chr(14844588)), length(chr(14844588)),char_length(chr(14844588));
charset(chr(14844588)) length(chr(14844588)) char_length(chr(14844588))
utf8 3 1
drop database mysqltest1;
use test;
#
# End of 10.1 tests
#
#
......
......@@ -121,4 +121,27 @@ primary key (`pk`)
set @p=_latin1 'test';
update t1 set pk='test' where pk=@p;
drop table t1;
#
# Start of 10.3 tests
#
#
# MDEV-12685 Oracle-compatible function CHR()
#
connection master;
CREATE DATABASE db1 DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
USE db1;
CREATE TABLE t1 AS SELECT CHR(0x60);
connection slave;
SHOW CREATE TABLE db1.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CHR(0x60)` varchar(4) COLLATE latin1_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin
connection master;
USE test;
DROP DATABASE db1;
connection slave;
#
# End of 10.3 tests
#
include/rpl_end.inc
......@@ -1853,6 +1853,16 @@ SELECT f1,HEX(f2) FROM t1 WHERE f1='YQ==' AND (f2= from_base64(
SELECT f1,HEX(f2) FROM t1 WHERE f1='YQ==' AND (f2= from_base64("Yq==") OR f2= from_base64("YQ=="));
DROP TABLE t1;
--echo #
--echo # MDEV-12685 Oracle-compatible function CHR()
--echo #
select chr(65);
create database mysqltest1 CHARACTER SET = 'utf8' COLLATE = 'utf8_bin';
use mysqltest1;
select charset(chr(65)), length(chr(65)),char_length(chr(65));
select charset(chr(14844588)), length(chr(14844588)),char_length(chr(14844588));
drop database mysqltest1;
use test;
--echo #
--echo # End of 10.1 tests
......
......@@ -517,6 +517,19 @@ class Create_func_centroid : public Create_func_arg1
};
class Create_func_chr : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_chr s_singleton;
protected:
Create_func_chr() {}
virtual ~Create_func_chr() {}
};
class Create_func_convexhull : public Create_func_arg1
{
public:
......@@ -3788,6 +3801,16 @@ Create_func_centroid::create_1_arg(THD *thd, Item *arg1)
}
Create_func_chr Create_func_chr::s_singleton;
Item*
Create_func_chr::create_1_arg(THD *thd, Item *arg1)
{
CHARSET_INFO *cs_db= thd->variables.collation_database;
return new (thd->mem_root) Item_func_chr(thd, arg1, cs_db);
}
Create_func_convexhull Create_func_convexhull::s_singleton;
Item*
......@@ -6831,6 +6854,7 @@ static Native_func_registry func_array[] =
{ { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
{ { C_STRING_WITH_LEN("CONVERT_TZ") }, BUILDER(Create_func_convert_tz)},
{ { C_STRING_WITH_LEN("CONVEXHULL") }, GEOM_BUILDER(Create_func_convexhull)},
{ { C_STRING_WITH_LEN("CHR") }, BUILDER(Create_func_chr)},
{ { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
{ { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
{ { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
......
......@@ -2905,29 +2905,51 @@ String *Item_func_char::val_str(String *str)
{
int32 num=(int32) args[i]->val_int();
if (!args[i]->null_value)
{
char tmp[4];
if (num & 0xFF000000L)
{
mi_int4store(tmp, num);
str->append(tmp, 4, &my_charset_bin);
}
else if (num & 0xFF0000L)
{
mi_int3store(tmp, num);
str->append(tmp, 3, &my_charset_bin);
}
else if (num & 0xFF00L)
{
mi_int2store(tmp, num);
str->append(tmp, 2, &my_charset_bin);
}
else
{
tmp[0]= (char) num;
str->append(tmp, 1, &my_charset_bin);
}
}
append_char(str, num);
}
str->realloc(str->length()); // Add end 0 (for Purify)
return check_well_formed_result(str);
}
void Item_func_char::append_char(String *str, int32 num)
{
char tmp[4];
if (num & 0xFF000000L)
{
mi_int4store(tmp, num);
str->append(tmp, 4, &my_charset_bin);
}
else if (num & 0xFF0000L)
{
mi_int3store(tmp, num);
str->append(tmp, 3, &my_charset_bin);
}
else if (num & 0xFF00L)
{
mi_int2store(tmp, num);
str->append(tmp, 2, &my_charset_bin);
}
else
{
tmp[0]= (char) num;
str->append(tmp, 1, &my_charset_bin);
}
}
String *Item_func_chr::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
str->length(0);
str->set_charset(collation.collation);
int32 num=(int32) args[0]->val_int();
if (!args[0]->null_value)
append_char(str, num);
else
{
null_value= 1;
return 0;
}
str->realloc(str->length()); // Add end 0 (for Purify)
return check_well_formed_result(str);
......
......@@ -946,7 +946,11 @@ class Item_func_char :public Item_str_func
Item_func_char(THD *thd, List<Item> &list, CHARSET_INFO *cs):
Item_str_func(thd, list)
{ collation.set(cs); }
Item_func_char(THD *thd, Item *arg1, CHARSET_INFO *cs):
Item_str_func(thd, arg1)
{ collation.set(cs); }
String *val_str(String *);
void append_char(String * str, int32 num);
void fix_length_and_dec()
{
max_length= arg_count * 4;
......@@ -956,6 +960,20 @@ class Item_func_char :public Item_str_func
{ return get_item_copy<Item_func_char>(thd, mem_root, this); }
};
class Item_func_chr :public Item_func_char
{
public:
Item_func_chr(THD *thd, Item *arg1, CHARSET_INFO *cs):
Item_func_char(thd, arg1, cs) {}
String *val_str(String *);
void fix_length_and_dec()
{
max_length= 4;
}
const char *func_name() const { return "chr"; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_chr>(thd, mem_root, this); }
};
class Item_func_repeat :public Item_str_func
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment