Commit bc1b68f0 authored by unknown's avatar unknown

insert table select * from table2 now converts charsets correctly

parent f953acea
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 " "
......
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 ``
(
......
......@@ -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());
......
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