diff options
author | unknown <serg@serg.mylan> | 2003-12-13 18:49:10 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2003-12-13 18:49:10 +0100 |
commit | bc1b68f0d866cc31fcbd321f88c216c44198bf79 (patch) | |
tree | f72587e0ec71205d385c6165f0dfbd662cdb0d5c | |
parent | f953acea9290638926cfc3ff2185848bcb80b4ff (diff) | |
download | mariadb-git-bc1b68f0d866cc31fcbd321f88c216c44198bf79.tar.gz |
insert table select * from table2 now converts charsets correctly
-rw-r--r-- | mysql-test/r/ctype_recoding.result | 24 | ||||
-rw-r--r-- | mysql-test/t/ctype_recoding.test | 16 | ||||
-rw-r--r-- | sql/field_conv.cc | 8 |
3 files changed, 40 insertions, 8 deletions
diff --git a/mysql-test/r/ctype_recoding.result b/mysql-test/r/ctype_recoding.result index 646dcb76f96..571c89ef467 100644 --- a/mysql-test/r/ctype_recoding.result +++ b/mysql-test/r/ctype_recoding.result @@ -1,7 +1,8 @@ SET CHARACTER SET koi8r; -DROP TABLE IF EXISTS таблица, t1; +DROP TABLE IF EXISTS таблица, t1, t2; SET CHARACTER SET koi8r; CREATE TABLE t1 (a CHAR(10) CHARACTER SET cp1251) SELECT _koi8r'проба' AS a; +CREATE TABLE t2 (a CHAR(10) CHARACTER SET utf8); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -13,7 +14,26 @@ a SELECT HEX(a) FROM t1; HEX(a) EFF0EEE1E0 -DROP TABLE t1; +INSERT t2 SELECT * FROM t1; +SELECT HEX(a) FROM t2; +HEX(a) +D0BFD180D0BED0B1D0B0 +DROP TABLE t1, t2; +CREATE TABLE t1 (a TEXT CHARACTER SET cp1251) SELECT _koi8r'проба' AS a; +CREATE TABLE t2 (a TEXT CHARACTER SET utf8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text character set cp1251 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT HEX(a) FROM t1; +HEX(a) +EFF0EEE1E0 +INSERT t2 SELECT * FROM t1; +SELECT HEX(a) FROM t2; +HEX(a) +D0BFD180D0BED0B1D0B0 +DROP TABLE t1, t2; CREATE TABLE `таблица` ( поле CHAR(32) CHARACTER SET koi8r NOT NULL COMMENT "комментарий поля" diff --git a/mysql-test/t/ctype_recoding.test b/mysql-test/t/ctype_recoding.test index 2f08e021df2..0b901009041 100644 --- a/mysql-test/t/ctype_recoding.test +++ b/mysql-test/t/ctype_recoding.test @@ -1,15 +1,27 @@ SET CHARACTER SET koi8r; --disable_warnings -DROP TABLE IF EXISTS таблица, t1; +DROP TABLE IF EXISTS таблица, t1, t2; --enable_warnings SET CHARACTER SET koi8r; CREATE TABLE t1 (a CHAR(10) CHARACTER SET cp1251) SELECT _koi8r'проба' AS a; +CREATE TABLE t2 (a CHAR(10) CHARACTER SET utf8); SHOW CREATE TABLE t1; SELECT a FROM t1; SELECT HEX(a) FROM t1; -DROP TABLE t1; +INSERT t2 SELECT * FROM t1; +SELECT HEX(a) FROM t2; +DROP TABLE t1, t2; + +# same with TEXT +CREATE TABLE t1 (a TEXT CHARACTER SET cp1251) SELECT _koi8r'проба' AS a; +CREATE TABLE t2 (a TEXT CHARACTER SET utf8); +SHOW CREATE TABLE t1; +SELECT HEX(a) FROM t1; +INSERT t2 SELECT * FROM t1; +SELECT HEX(a) FROM t2; +DROP TABLE t1, t2; CREATE TABLE `таблица` ( diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 5f08c91372b..67905d35e0d 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -17,7 +17,7 @@ /* Functions to copy data to or from fields - This could be done with a single short function but opencooding this + This could be done with a single short function but opencoding this gives much more speed. */ @@ -549,6 +549,7 @@ void field_conv(Field *to,Field *from) if (to->pack_length() == from->pack_length() && to->real_type() != FIELD_TYPE_ENUM && to->real_type() != FIELD_TYPE_SET && + from->charset() == to->charset() && to->table->db_low_byte_first == from->table->db_low_byte_first) { // Identical fields memcpy(to->ptr,from->ptr,to->pack_length()); @@ -562,7 +563,7 @@ void field_conv(Field *to,Field *from) if (!blob->value.is_alloced() && from->real_type() != FIELD_TYPE_STRING) blob->value.copy(); - blob->store(blob->value.ptr(),blob->value.length(),to->charset()); + blob->store(blob->value.ptr(),blob->value.length(),from->charset()); return; } if ((from->result_type() == STRING_RESULT && @@ -574,8 +575,7 @@ void field_conv(Field *to,Field *from) char buff[MAX_FIELD_WIDTH]; String result(buff,sizeof(buff),from->charset()); from->val_str(&result,&result); - to->store(result.c_ptr_quick(),result.length(),to->charset()); - // QQ: what to do if "from" and "to" are of dirrent charsets? + to->store(result.c_ptr_quick(),result.length(),from->charset()); } else if (from->result_type() == REAL_RESULT) to->store(from->val_real()); |