Commit c897c59c authored by Mikael Ronstrom's avatar Mikael Ronstrom

Fixed so that character set constants are encoded as hex strings in frm file,...

Fixed so that character set constants are encoded as hex strings in frm file, but as utf8 strings in the same manner as default values in show create table and information schema tables
parent 66b37d31
...@@ -28,14 +28,6 @@ create table t1 (a varchar(2) character set ucs2) ...@@ -28,14 +28,6 @@ create table t1 (a varchar(2) character set ucs2)
partition by list columns (a) partition by list columns (a)
(partition p0 values in (0x2020), (partition p0 values in (0x2020),
partition p1 values in ('')); partition p1 values in (''));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(2) CHARACTER SET ucs2 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY LIST COLUMNS(a)
(PARTITION p0 VALUES IN (_ucs2 0x2020) ENGINE = MyISAM,
PARTITION p1 VALUES IN (_ucs2 '') ENGINE = MyISAM) */
insert into t1 values (''); insert into t1 values ('');
insert into t1 values (_ucs2 0x2020); insert into t1 values (_ucs2 0x2020);
drop table t1; drop table t1;
...@@ -77,9 +69,9 @@ t1 CREATE TABLE `t1` ( ...@@ -77,9 +69,9 @@ t1 CREATE TABLE `t1` (
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c,d) /*!50100 PARTITION BY RANGE COLUMNS(a,b,c,d)
SUBPARTITION BY HASH (to_seconds(d)) SUBPARTITION BY HASH (to_seconds(d))
SUBPARTITIONS 4 SUBPARTITIONS 4
(PARTITION p0 VALUES LESS THAN (1,_latin1 0x30,MAXVALUE,'1900-01-01') ENGINE = MyISAM, (PARTITION p0 VALUES LESS THAN (1,'0',MAXVALUE,'1900-01-01') ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (1,_latin1 0x61,MAXVALUE,'1999-01-01') ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (1,'a',MAXVALUE,'1999-01-01') ENGINE = MyISAM,
PARTITION p2 VALUES LESS THAN (1,_latin1 0x61,MAXVALUE,MAXVALUE) ENGINE = MyISAM, PARTITION p2 VALUES LESS THAN (1,'a',MAXVALUE,MAXVALUE) ENGINE = MyISAM,
PARTITION p3 VALUES LESS THAN (1,MAXVALUE,MAXVALUE,MAXVALUE) ENGINE = MyISAM) */ PARTITION p3 VALUES LESS THAN (1,MAXVALUE,MAXVALUE,MAXVALUE) ENGINE = MyISAM) */
drop table t1; drop table t1;
create table t1 (a int, b int) create table t1 (a int, b int)
...@@ -298,10 +290,10 @@ t1 CREATE TABLE `t1` ( ...@@ -298,10 +290,10 @@ t1 CREATE TABLE `t1` (
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c) /*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
SUBPARTITION BY KEY (c,d) SUBPARTITION BY KEY (c,d)
SUBPARTITIONS 3 SUBPARTITIONS 3
(PARTITION p0 VALUES LESS THAN (1,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM, (PARTITION p0 VALUES LESS THAN (1,'abc','abc') ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (2,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM, PARTITION p1 VALUES LESS THAN (2,'abc','abc') ENGINE = MyISAM,
PARTITION p2 VALUES LESS THAN (3,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM, PARTITION p2 VALUES LESS THAN (3,'abc','abc') ENGINE = MyISAM,
PARTITION p3 VALUES LESS THAN (4,_latin1 0x616263,_latin1 0x616263) ENGINE = MyISAM) */ PARTITION p3 VALUES LESS THAN (4,'abc','abc') ENGINE = MyISAM) */
insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3); insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3);
insert into t1 values (1,'b','c',1),(2,'b','c',2),(3,'b','c',3); insert into t1 values (1,'b','c',1),(2,'b','c',2),(3,'b','c',3);
insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3); insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3);
...@@ -329,8 +321,8 @@ t1 CREATE TABLE `t1` ( ...@@ -329,8 +321,8 @@ t1 CREATE TABLE `t1` (
`c` int(11) DEFAULT NULL `c` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c) /*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
(PARTITION p0 VALUES LESS THAN (1,_latin1 0x41,1) ENGINE = MyISAM, (PARTITION p0 VALUES LESS THAN (1,'A',1) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (1,_latin1 0x42,1) ENGINE = MyISAM) */ PARTITION p1 VALUES LESS THAN (1,'B',1) ENGINE = MyISAM) */
insert into t1 values (1, 'A', 1); insert into t1 values (1, 'A', 1);
explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1; explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
......
...@@ -47,7 +47,6 @@ create table t1 (a varchar(2) character set ucs2) ...@@ -47,7 +47,6 @@ create table t1 (a varchar(2) character set ucs2)
partition by list columns (a) partition by list columns (a)
(partition p0 values in (0x2020), (partition p0 values in (0x2020),
partition p1 values in ('')); partition p1 values in (''));
show create table t1;
insert into t1 values (''); insert into t1 values ('');
insert into t1 values (_ucs2 0x2020); insert into t1 values (_ucs2 0x2020);
drop table t1; drop table t1;
......
...@@ -2062,10 +2062,8 @@ int partition_info::fix_parser_data(THD *thd) ...@@ -2062,10 +2062,8 @@ int partition_info::fix_parser_data(THD *thd)
{ {
List_iterator<partition_element> it(partitions); List_iterator<partition_element> it(partitions);
partition_element *part_elem; partition_element *part_elem;
part_elem_value *val;
uint num_elements; uint num_elements;
uint i= 0, j, k; uint i= 0, j, k;
int result;
DBUG_ENTER("partition_info::fix_parser_data"); DBUG_ENTER("partition_info::fix_parser_data");
if (!(part_type == RANGE_PARTITION || if (!(part_type == RANGE_PARTITION ||
......
...@@ -1818,46 +1818,6 @@ static int add_write(File fptr, const char *buf, uint len) ...@@ -1818,46 +1818,6 @@ static int add_write(File fptr, const char *buf, uint len)
return 1; return 1;
} }
static int add_string(File fptr, const char *string);
static int write_hex_char(File fptr, uint number)
{
char buf[2];
char c= '0';
/* Write number between 0 and 15 as 0-9,A-F */
if (number < 10)
c+= number;
else
{
c= 'A';
c+= (number - 10);
}
buf[0]= c;
buf[1]= 0;
return add_string(fptr, (const char*)buf);
}
static int add_hex_string_object(File fptr, String *string)
{
uint len= string->length();
uint i;
const char *ptr= string->ptr();
char c;
int err;
uint low, high;
err= add_string(fptr, "0x");
for (i= 0; i < len; i++)
{
c= *ptr;
ptr++;
high= c >> 4;
low= c & 15;
err+= write_hex_char(fptr, high);
err+= write_hex_char(fptr, low);
}
return err;
}
static int add_string_object(File fptr, String *string) static int add_string_object(File fptr, String *string)
{ {
return add_write(fptr, string->ptr(), string->length()); return add_write(fptr, string->ptr(), string->length());
...@@ -2095,7 +2055,7 @@ static int check_part_field(enum_field_types sql_type, ...@@ -2095,7 +2055,7 @@ static int check_part_field(enum_field_types sql_type,
case MYSQL_TYPE_TIME: case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_DATETIME:
*result_type= STRING_RESULT; *result_type= STRING_RESULT;
*need_cs_check= FALSE; *need_cs_check= TRUE;
return FALSE; return FALSE;
case MYSQL_TYPE_VARCHAR: case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
...@@ -2140,6 +2100,69 @@ static Create_field* get_sql_field(char *field_name, ...@@ -2140,6 +2100,69 @@ static Create_field* get_sql_field(char *field_name,
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
int get_converted_part_value_from_string(Item *item,
String *res,
CHARSET_INFO *field_cs,
String *val_conv,
bool use_hex)
{
String val;
uint dummy_errors;
uint len, high, low, i;
const char *ptr;
char buf[3];
if (!res)
{
my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
return 1;
}
if (item->result_type() == INT_RESULT)
{
longlong value= item->val_int();
val_conv->set(value, system_charset_info);
return 0;
}
val_conv->length(0);
if (!field_cs || res->length() == 0)
{
val_conv->append("'");
if (res->length() != 0)
val_conv->append(*res);
val_conv->append("'");
return 0;
}
if (field_cs && use_hex)
{
val_conv->append("_");
val_conv->append(field_cs->csname);
val_conv->append(" ");
}
if (use_hex)
{
val_conv->append("0x");
len= res->length();
ptr= res->ptr();
for (i= 0; i < len; i++)
{
high= (*ptr) >> 4;
low= (*ptr) & 0x0F;
buf[0]= _dig_vec_upper[high];
buf[1]= _dig_vec_upper[low];
buf[2]= 0;
val_conv->append((const char*)buf);
ptr++;
}
}
else
{
val.copy(res->ptr(), res->length(), field_cs,
system_charset_info, &dummy_errors);
append_unescaped(val_conv, val.ptr(), val.length());
}
return 0;
}
static int add_column_list_values(File fptr, partition_info *part_info, static int add_column_list_values(File fptr, partition_info *part_info,
part_elem_value *list_value, part_elem_value *list_value,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
...@@ -2231,42 +2254,14 @@ static int add_column_list_values(File fptr, partition_info *part_info, ...@@ -2231,42 +2254,14 @@ static int add_column_list_values(File fptr, partition_info *part_info,
my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0)); my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0));
return 1; return 1;
} }
if (result_type == INT_RESULT)
{
longlong val;
val= item_expr->val_int();
err+= add_int(fptr, val);
}
else
{ {
String val_conv;
res= item_expr->val_str(&str); res= item_expr->val_str(&str);
if (!res) if (get_converted_part_value_from_string(item_expr, res,
{ field_cs, &val_conv,
my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); (bool)(alter_info != NULL)))
return 1; return 1;
} err+= add_string_object(fptr, &val_conv);
if (field_cs)
{
err+= add_string(fptr,"_");
err+= add_string(fptr, field_cs->csname);
err+= add_space(fptr);
if (res->length())
{
err+= add_hex_string_object(fptr, res);
}
else
{
err+= add_string(fptr,"'");
err+= add_string(fptr,"'");
}
}
else
{
err+= add_string(fptr,"'");
err+= add_string_object(fptr, res);
err+= add_string(fptr,"'");
}
} }
} }
} }
......
...@@ -75,6 +75,11 @@ void get_partition_set(const TABLE *table, uchar *buf, const uint index, ...@@ -75,6 +75,11 @@ void get_partition_set(const TABLE *table, uchar *buf, const uint index,
const key_range *key_spec, const key_range *key_spec,
part_id_range *part_spec); part_id_range *part_spec);
uint get_partition_field_store_length(Field *field); uint get_partition_field_store_length(Field *field);
int get_converted_part_value_from_string(Item *item,
String *res,
CHARSET_INFO *cs,
String *val_conv,
bool use_hex);
void get_full_part_id_from_key(const TABLE *table, uchar *buf, void get_full_part_id_from_key(const TABLE *table, uchar *buf,
KEY *key_info, KEY *key_info,
const key_range *key_spec, const key_range *key_spec,
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "sql_trigger.h" #include "sql_trigger.h"
#include "authors.h" #include "authors.h"
#include "contributors.h" #include "contributors.h"
#include "sql_partition.h"
#ifdef HAVE_EVENT_SCHEDULER #ifdef HAVE_EVENT_SCHEDULER
#include "events.h" #include "events.h"
#include "event_data_objects.h" #include "event_data_objects.h"
...@@ -4970,6 +4971,7 @@ get_partition_column_description(partition_info *part_info, ...@@ -4970,6 +4971,7 @@ get_partition_column_description(partition_info *part_info,
{ {
char buffer[MAX_KEY_LENGTH]; char buffer[MAX_KEY_LENGTH];
String str(buffer, sizeof(buffer), &my_charset_bin); String str(buffer, sizeof(buffer), &my_charset_bin);
String val_conv;
Item *item= col_val->item_expression; Item *item= col_val->item_expression;
if (!(item= part_info->get_column_item(item, if (!(item= part_info->get_column_item(item,
...@@ -4978,16 +4980,13 @@ get_partition_column_description(partition_info *part_info, ...@@ -4978,16 +4980,13 @@ get_partition_column_description(partition_info *part_info,
DBUG_RETURN(1); DBUG_RETURN(1);
} }
String *res= item->val_str(&str); String *res= item->val_str(&str);
if (!res) if (get_converted_part_value_from_string(item, res,
part_info->part_field_array[i]->charset(),
&val_conv, FALSE))
{ {
my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if (item->result_type() == STRING_RESULT) tmp_str.append(val_conv);
tmp_str.append("'");
tmp_str.append(*res);
if (item->result_type() == STRING_RESULT)
tmp_str.append("'");
} }
if (i != num_elements - 1) if (i != num_elements - 1)
tmp_str.append(","); tmp_str.append(",");
...@@ -5004,7 +5003,6 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables, ...@@ -5004,7 +5003,6 @@ static int get_schema_partitions_record(THD *thd, TABLE_LIST *tables,
char buff[61]; char buff[61];
String tmp_res(buff, sizeof(buff), cs); String tmp_res(buff, sizeof(buff), cs);
String tmp_str; String tmp_str;
uint num_elements;
TABLE *show_table= tables->table; TABLE *show_table= tables->table;
handler *file; handler *file;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
......
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