Commit b7b69c5d authored by unknown's avatar unknown

Fix for #3266 (garbled TEXT fields as a result of CREATE TABLE SELECT)

Problem is that Item::save_in_field modifies str_value member
 before it calls val_str but Item_copy_string::val_str just returns
this str_value as the result.
I added local String variable to the Item::save_in_field


mysql-test/r/create.result:
  appropriate test result
mysql-test/t/create.test:
  test case
sql/item.cc:
  local variable added to keep the result
parent a25455ee
......@@ -529,3 +529,14 @@ t5 CREATE TABLE `t5` (
KEY `PRIMARY_2` (`PRIMARY`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3, t4, t5;
CREATE TABLE t1(id varchar(10) NOT NULL PRIMARY KEY, dsc longtext);
INSERT INTO t1 VALUES ('5000000001', NULL),('5000000003', 'Test'),('5000000004', NULL);
CREATE TABLE t2(id varchar(15) NOT NULL, proc varchar(100) NOT NULL, runID varchar(16) NOT NULL, start datetime NOT NULL, PRIMARY KEY (id,proc,runID,start));
INSERT INTO t2 VALUES ('5000000001', 'proc01', '20031029090650', '2003-10-29 13:38:40'),('5000000001', 'proc02', '20031029090650', '2003-10-29 13:38:51'),('5000000001', 'proc03', '20031029090650', '2003-10-29 13:38:11'),('5000000002', 'proc09', '20031024013310', '2003-10-24 01:33:11'),('5000000002', 'proc09', '20031024153537', '2003-10-24 15:36:04'),('5000000004', 'proc01', '20031024013641', '2003-10-24 01:37:29'),('5000000004', 'proc02', '20031024013641', '2003-10-24 01:37:39');
CREATE TABLE t3 SELECT t1.dsc,COUNT(DISTINCT t2.id) AS countOfRuns FROM t1 LEFT JOIN t2 ON (t1.id=t2.id) GROUP BY t1.id;
SELECT * FROM t3;
dsc countOfRuns
NULL 1
Test 0
NULL 1
drop table t1, t2, t3;
......@@ -410,3 +410,17 @@ alter table t5 add index(`PRIMARY`);
show create table t5;
drop table t1, t2, t3, t4, t5;
#
# bug #3266 TEXT in CREATE TABLE SELECT
#
CREATE TABLE t1(id varchar(10) NOT NULL PRIMARY KEY, dsc longtext);
INSERT INTO t1 VALUES ('5000000001', NULL),('5000000003', 'Test'),('5000000004', NULL);
CREATE TABLE t2(id varchar(15) NOT NULL, proc varchar(100) NOT NULL, runID varchar(16) NOT NULL, start datetime NOT NULL, PRIMARY KEY (id,proc,runID,start));
INSERT INTO t2 VALUES ('5000000001', 'proc01', '20031029090650', '2003-10-29 13:38:40'),('5000000001', 'proc02', '20031029090650', '2003-10-29 13:38:51'),('5000000001', 'proc03', '20031029090650', '2003-10-29 13:38:11'),('5000000002', 'proc09', '20031024013310', '2003-10-24 01:33:11'),('5000000002', 'proc09', '20031024153537', '2003-10-24 15:36:04'),('5000000004', 'proc01', '20031024013641', '2003-10-24 01:37:29'),('5000000004', 'proc02', '20031024013641', '2003-10-24 01:37:39');
CREATE TABLE t3 SELECT t1.dsc,COUNT(DISTINCT t2.id) AS countOfRuns FROM t1 LEFT JOIN t2 ON (t1.id=t2.id) GROUP BY t1.id;
SELECT * FROM t3;
drop table t1, t2, t3;
......@@ -1282,8 +1282,8 @@ int Item::save_in_field(Field *field, bool no_conversions)
String *result;
CHARSET_INFO *cs= collation.collation;
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns
str_value.set_quick(buff,sizeof(buff),cs);
result=val_str(&str_value);
String loc_value(buff, sizeof(buff), cs);
result=val_str(&loc_value);
if (null_value)
return set_field_to_null_with_conversions(field, no_conversions);
field->set_notnull();
......
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