summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKentoku <kentokushiba@gmail.com>2019-04-26 18:57:51 +0900
committerKentoku <kentokushiba@gmail.com>2019-04-29 21:55:41 +0900
commit1b240785c4ee0ec64b6cca31057fd4e515c92004 (patch)
tree1870e2b99c5aaf5de5727b236b452cf62490ebbd
parentd1a43973ef2bb6f8e9de2196cbbfdd682d1c9139 (diff)
downloadmariadb-git-bb-10.4-MDEV-18992.tar.gz
MDEV-18992 Crash when using 'insert into on duplicate update'if session charset different from table charsetbb-10.4-MDEV-18992
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc13
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc29
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/cp932_column.result84
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/cp932_column.cnf3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/cp932_column.test80
-rw-r--r--storage/spider/mysql-test/spider/r/partition_fulltext.result6
-rw-r--r--storage/spider/mysql-test/spider/r/timestamp.result20
-rw-r--r--storage/spider/spd_db_conn.cc27
-rw-r--r--storage/spider/spd_db_conn.h5
-rw-r--r--storage/spider/spd_db_include.h5
-rw-r--r--storage/spider/spd_db_mysql.cc17
-rw-r--r--storage/spider/spd_db_oracle.cc2
-rw-r--r--storage/spider/spd_malloc.cc15
13 files changed, 289 insertions, 17 deletions
diff --git a/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc
new file mode 100644
index 00000000000..930cde889a4
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc
@@ -0,0 +1,13 @@
+--connection master_1
+set session spider_direct_dup_insert= @old_spider_direct_dup_insert;
+--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
+--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
+--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
+--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
+--disable_warnings
+--disable_query_log
+--disable_result_log
+--source ../t/test_deinit.inc
+--enable_result_log
+--enable_query_log
+--enable_warnings
diff --git a/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc
new file mode 100644
index 00000000000..ba412b567f8
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc
@@ -0,0 +1,29 @@
+--disable_warnings
+--disable_query_log
+--disable_result_log
+--source ../t/test_init.inc
+--enable_result_log
+--enable_query_log
+--enable_warnings
+--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
+let $MASTER_1_COMMENT_2_1=
+ COMMENT='table "tbl_a", srv "s_2_1"';
+--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
+let $CHILD2_1_DROP_TABLES=
+ DROP TABLE IF EXISTS tbl_a;
+--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
+let $CHILD2_1_CREATE_TABLES=
+ CREATE TABLE tbl_a (
+ pkey int NOT NULL,
+ txt_utf8 char(8) NOT NULL,
+ txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci,
+ PRIMARY KEY (pkey)
+ ) $CHILD2_1_ENGINE DEFAULT CHARACTER SET utf8;
+--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
+let $CHILD2_1_SELECT_TABLES=
+ SELECT pkey, txt_utf8, txt_cp932 FROM tbl_a ORDER BY pkey;
+let $CHILD2_1_SELECT_ARGUMENT1=
+ SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%update %';
+--connection master_1
+set @old_spider_direct_dup_insert= @@spider_direct_dup_insert;
+set session spider_direct_dup_insert= 1;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result b/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result
new file mode 100644
index 00000000000..30b333c5008
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result
@@ -0,0 +1,84 @@
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
+connection master_1;
+set @old_spider_direct_dup_insert= @@spider_direct_dup_insert;
+set session spider_direct_dup_insert= 1;
+
+this test is for MDEV-18992
+
+drop and create databases
+connection master_1;
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+connection child2_1;
+SET @old_log_output = @@global.log_output;
+SET GLOBAL log_output = 'TABLE,FILE';
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+
+create table and insert
+connection child2_1;
+CHILD2_1_CREATE_TABLES
+TRUNCATE TABLE mysql.general_log;
+connection master_1;
+CREATE TABLE tbl_a (
+pkey int NOT NULL,
+txt_utf8 char(8) NOT NULL,
+txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci,
+PRIMARY KEY (pkey)
+) MASTER_1_ENGINE DEFAULT CHARACTER SET utf8 MASTER_1_COMMENT_2_1
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'',''),(1,'',''),(2,'',''),(3,'',''),(4,'',''),(5,'',''),(6,'',''),(7,'',''),(8,'',''),(9,'','');
+FLUSH TABLES;
+
+test 1
+connection child2_1;
+TRUNCATE TABLE mysql.general_log;
+connection master_1;
+SET NAMES cp932;
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (10,'','中国');
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'','') ON DUPLICATE KEY UPDATE txt_cp932 = '中国';
+UPDATE tbl_a SET txt_cp932 = '中国' WHERE pkey = 2;
+SET NAMES utf8;
+connection child2_1;
+SET NAMES cp932;
+SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%update %';
+argument
+insert into `auto_test_remote`.`tbl_a`(`pkey`,`txt_utf8`,`txt_cp932`)values(10,'',_cp932'\\x92\\x86\\x8D\\x91')
+insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`txt_utf8`,`txt_cp932`)values(0,'',_cp932'') on duplicate key update `txt_cp932` = _cp932'\x92\x86\x8D\x91'
+update `auto_test_remote`.`tbl_a` set `txt_cp932` = _cp932'\x92\x86\x8D\x91' where (`pkey` = 2)
+SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %' OR argument LIKE '%update %'
+SELECT pkey, txt_utf8, txt_cp932 FROM tbl_a ORDER BY pkey;
+pkey txt_utf8 txt_cp932
+0 中国
+1
+2 中国
+3
+4
+5
+6
+7
+8
+9
+10 中国
+SET NAMES utf8;
+
+deinit
+connection master_1;
+DROP DATABASE IF EXISTS auto_test_local;
+connection child2_1;
+DROP DATABASE IF EXISTS auto_test_remote;
+SET GLOBAL log_output = @old_log_output;
+connection master_1;
+set session spider_direct_dup_insert= @old_spider_direct_dup_insert;
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
+
+end of test
diff --git a/storage/spider/mysql-test/spider/bugfix/t/cp932_column.cnf b/storage/spider/mysql-test/spider/bugfix/t/cp932_column.cnf
new file mode 100644
index 00000000000..05dfd8a0bce
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/cp932_column.cnf
@@ -0,0 +1,3 @@
+!include include/default_mysqld.cnf
+!include ../my_1_1.cnf
+!include ../my_2_1.cnf
diff --git a/storage/spider/mysql-test/spider/bugfix/t/cp932_column.test b/storage/spider/mysql-test/spider/bugfix/t/cp932_column.test
new file mode 100644
index 00000000000..8bd0d40cb60
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/cp932_column.test
@@ -0,0 +1,80 @@
+--source ../include/cp932_column_init.inc
+--echo
+--echo this test is for MDEV-18992
+--echo
+--echo drop and create databases
+
+--connection master_1
+--disable_warnings
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+
+--connection child2_1
+SET @old_log_output = @@global.log_output;
+SET GLOBAL log_output = 'TABLE,FILE';
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+--enable_warnings
+
+--echo
+--echo create table and insert
+
+--connection child2_1
+--disable_query_log
+echo CHILD2_1_CREATE_TABLES;
+eval $CHILD2_1_CREATE_TABLES;
+--enable_query_log
+TRUNCATE TABLE mysql.general_log;
+
+--connection master_1
+--disable_query_log
+echo CREATE TABLE tbl_a (
+ pkey int NOT NULL,
+ txt_utf8 char(8) NOT NULL,
+ txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci,
+ PRIMARY KEY (pkey)
+) MASTER_1_ENGINE DEFAULT CHARACTER SET utf8 MASTER_1_COMMENT_2_1;
+eval CREATE TABLE tbl_a (
+ pkey int NOT NULL,
+ txt_utf8 char(8) NOT NULL,
+ txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci,
+ PRIMARY KEY (pkey)
+) $MASTER_1_ENGINE DEFAULT CHARACTER SET utf8 $MASTER_1_COMMENT_2_1;
+--enable_query_log
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'',''),(1,'',''),(2,'',''),(3,'',''),(4,'',''),(5,'',''),(6,'',''),(7,'',''),(8,'',''),(9,'','');
+FLUSH TABLES;
+
+--echo
+--echo test 1
+
+--connection child2_1
+TRUNCATE TABLE mysql.general_log;
+
+--connection master_1
+SET NAMES cp932;
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (10,'','中国');
+INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'','') ON DUPLICATE KEY UPDATE txt_cp932 = '中国';
+UPDATE tbl_a SET txt_cp932 = '中国' WHERE pkey = 2;
+SET NAMES utf8;
+
+--connection child2_1
+SET NAMES cp932;
+eval $CHILD2_1_SELECT_ARGUMENT1;
+eval $CHILD2_1_SELECT_TABLES;
+SET NAMES utf8;
+
+--echo
+--echo deinit
+--disable_warnings
+
+--connection master_1
+DROP DATABASE IF EXISTS auto_test_local;
+
+--connection child2_1
+DROP DATABASE IF EXISTS auto_test_remote;
+SET GLOBAL log_output = @old_log_output;
+
+--enable_warnings
+--source ../include/cp932_column_deinit.inc
+--echo
+--echo end of test
diff --git a/storage/spider/mysql-test/spider/r/partition_fulltext.result b/storage/spider/mysql-test/spider/r/partition_fulltext.result
index 3289473b905..6c001d25444 100644
--- a/storage/spider/mysql-test/spider/r/partition_fulltext.result
+++ b/storage/spider/mysql-test/spider/r/partition_fulltext.result
@@ -71,7 +71,7 @@ pkey words
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
-select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against('+ghi' in boolean mode))
+select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode))
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
@@ -80,7 +80,7 @@ pkey
connection child2_2;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
-select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote2`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against('+ghi' in boolean mode))
+select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote2`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode))
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
@@ -91,7 +91,7 @@ pkey
connection child2_3;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
-select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote3`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against('+ghi' in boolean mode))
+select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote3`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode))
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
diff --git a/storage/spider/mysql-test/spider/r/timestamp.result b/storage/spider/mysql-test/spider/r/timestamp.result
index bd1f442d462..85ca7f6e7f4 100644
--- a/storage/spider/mysql-test/spider/r/timestamp.result
+++ b/storage/spider/mysql-test/spider/r/timestamp.result
@@ -252,11 +252,11 @@ col_a col_dt col_ts unix_timestamp(col_ts)
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2017-12-31 23:00:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < '2018-10-28 01:30:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ('2018-10-28 01:30:00' > t0.`col_ts`)
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between '2018-10-28 00:30:00' and '2018-10-28 01:30:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= '2018-10-28 00:30:00') and (t0.`col_ts` <= '2018-10-28 01:30:00'))
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > _latin1'2017-12-31 23:00:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < _latin1'2018-10-28 01:30:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (_latin1'2018-10-28 01:30:00' > t0.`col_ts`)
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between _latin1'2018-10-28 00:30:00' and _latin1'2018-10-28 01:30:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= _latin1'2018-10-28 00:30:00') and (t0.`col_ts` <= _latin1'2018-10-28 01:30:00'))
select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2018-03-25 01:00:00')
select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '1970-01-01 00:00:01')
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
@@ -339,11 +339,11 @@ col_a col_dt col_ts unix_timestamp(col_ts)
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2017-12-31 23:00:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < '2018-10-28 01:30:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ('2018-10-28 01:30:00' > t0.`col_ts`)
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between '2018-10-28 00:30:00' and '2018-10-28 01:30:00')
-select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= '2018-10-28 00:30:00') and (t0.`col_ts` <= '2018-10-28 01:30:00'))
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > _latin1'2017-12-31 23:00:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < _latin1'2018-10-28 01:30:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (_latin1'2018-10-28 01:30:00' > t0.`col_ts`)
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between _latin1'2018-10-28 00:30:00' and _latin1'2018-10-28 01:30:00')
+select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= _latin1'2018-10-28 00:30:00') and (t0.`col_ts` <= _latin1'2018-10-28 01:30:00'))
select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2018-03-25 01:00:00')
select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '1970-01-01 00:00:01')
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc
index 06e7223b01e..97e2d24c8e7 100644
--- a/storage/spider/spd_db_conn.cc
+++ b/storage/spider/spd_db_conn.cc
@@ -2582,6 +2582,22 @@ int spider_db_append_key_where(
DBUG_RETURN(0);
}
+int spider_db_append_charset_name_before_string(
+ spider_string *str,
+ CHARSET_INFO *cs
+) {
+ const char *csname = cs->csname;
+ uint csname_length = strlen(csname);
+ DBUG_ENTER("spider_db_append_charset_name_before_string");
+ if (str->reserve(SPIDER_SQL_UNDERSCORE_LEN + csname_length))
+ {
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ str->q_append(SPIDER_SQL_UNDERSCORE_STR, SPIDER_SQL_UNDERSCORE_LEN);
+ str->q_append(csname, csname_length);
+ DBUG_RETURN(0);
+}
+
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
int spider_db_refetch_for_item_sum_funcs(
ha_spider *spider
@@ -9291,6 +9307,14 @@ int spider_db_open_item_string(
goto end;
}
}
+ if (str->charset() != tmp_str2->charset())
+ {
+ if ((error_num = spider_db_append_charset_name_before_string(str,
+ tmp_str2->charset())))
+ {
+ goto end;
+ }
+ }
if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 +
tmp_str2->length() * 2))
{
@@ -9300,7 +9324,8 @@ int spider_db_open_item_string(
if (!thd)
tmp_str.mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
- str->append_escape_string(tmp_str2->ptr(), tmp_str2->length());
+ str->append_escape_string(tmp_str2->ptr(), tmp_str2->length(),
+ tmp_str2->charset());
if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
{
error_num = HA_ERR_OUT_OF_MEM;
diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h
index bf09d672685..f082996d3d1 100644
--- a/storage/spider/spd_db_conn.h
+++ b/storage/spider/spd_db_conn.h
@@ -472,6 +472,11 @@ int spider_db_append_key_where(
ha_spider *spider
);
+int spider_db_append_charset_name_before_string(
+ spider_string *str,
+ CHARSET_INFO *cs
+);
+
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
int spider_db_refetch_for_item_sum_funcs(
ha_spider *spider
diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h
index a6d8b9669aa..f759a78c3cb 100644
--- a/storage/spider/spd_db_include.h
+++ b/storage/spider/spd_db_include.h
@@ -533,6 +533,11 @@ public:
const char *st,
uint len
);
+ void append_escape_string(
+ const char *st,
+ uint len,
+ CHARSET_INFO *cs
+ );
bool append_for_single_quote(
const char *st,
uint len
diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc
index 7a8b016824c..d8fdfcec081 100644
--- a/storage/spider/spd_db_mysql.cc
+++ b/storage/spider/spd_db_mysql.cc
@@ -3465,8 +3465,9 @@ int spider_db_mbase_util::append_column_value(
const uchar *new_ptr,
CHARSET_INFO *access_charset
) {
+ int error_num;
char buf[MAX_FIELD_WIDTH];
- spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin);
+ spider_string tmp_str(buf, MAX_FIELD_WIDTH, field->charset());
String *ptr;
uint length;
THD *thd = field->table->in_use;
@@ -3484,7 +3485,7 @@ int spider_db_mbase_util::append_column_value(
) {
length = uint2korr(new_ptr);
tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length,
- &my_charset_bin);
+ field->charset());
ptr = tmp_str.get_str();
} else if (field->type() == MYSQL_TYPE_GEOMETRY)
{
@@ -3600,6 +3601,14 @@ int spider_db_mbase_util::append_column_value(
if (field->result_type() == STRING_RESULT)
{
DBUG_PRINT("info", ("spider STRING_RESULT"));
+ if (str->charset() != field->charset())
+ {
+ if ((error_num = spider_db_append_charset_name_before_string(str,
+ field->charset())))
+ {
+ DBUG_RETURN(error_num);
+ }
+ }
if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
@@ -3610,7 +3619,7 @@ int spider_db_mbase_util::append_column_value(
) {
DBUG_PRINT("info", ("spider append_escaped"));
char buf2[MAX_FIELD_WIDTH];
- spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, access_charset);
+ spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, field->charset());
tmp_str2.init_calc_mem(114);
tmp_str2.length(0);
if (
@@ -6886,10 +6895,12 @@ int spider_mbase_handler::init()
}
sql.set_charset(share->access_charset);
sql_part.set_charset(share->access_charset);
+ sql_part2.set_charset(share->access_charset);
ha_sql.set_charset(share->access_charset);
insert_sql.set_charset(share->access_charset);
update_sql.set_charset(share->access_charset);
tmp_sql.set_charset(share->access_charset);
+ dup_update_sql.set_charset(share->access_charset);
upd_tmp_tbl_prm.init();
upd_tmp_tbl_prm.field_count = 1;
if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *)
diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc
index e2bc3644989..e455ce0e4c0 100644
--- a/storage/spider/spd_db_oracle.cc
+++ b/storage/spider/spd_db_oracle.cc
@@ -5425,10 +5425,12 @@ int spider_oracle_handler::init()
}
sql.set_charset(share->access_charset);
sql_part.set_charset(share->access_charset);
+ sql_part2.set_charset(share->access_charset);
ha_sql.set_charset(share->access_charset);
insert_sql.set_charset(share->access_charset);
update_sql.set_charset(share->access_charset);
tmp_sql.set_charset(share->access_charset);
+ dup_update_sql.set_charset(share->access_charset);
upd_tmp_tbl_prm.init();
upd_tmp_tbl_prm.field_count = 1;
if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *)
diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc
index e7a6e710cbc..5373f8b1be7 100644
--- a/storage/spider/spd_malloc.cc
+++ b/storage/spider/spd_malloc.cc
@@ -1238,6 +1238,21 @@ void spider_string::append_escape_string(
DBUG_VOID_RETURN;
}
+void spider_string::append_escape_string(
+ const char *st,
+ uint len,
+ CHARSET_INFO *cs
+) {
+ DBUG_ENTER("spider_string::append_escape_string");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_ASSERT(mem_calc_inited);
+ DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) ||
+ current_alloc_mem == str.alloced_length());
+ str.length(str.length() + escape_string_for_mysql(
+ cs, (char *) str.ptr() + str.length(), 0, st, len));
+ DBUG_VOID_RETURN;
+}
+
bool spider_string::append_for_single_quote(
const char *st,
uint len