Commit 7bdd452d authored by unknown's avatar unknown

If VARCHAR strips only trailing spaces, then produce

a note, not a warning or error.

parent e7b38aa7
...@@ -1300,7 +1300,7 @@ insert into t1 values('+ ', '+ ', '+ '); ...@@ -1300,7 +1300,7 @@ insert into t1 values('+ ', '+ ', '+ ');
set @a=repeat(' ',20); set @a=repeat(' ',20);
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
Warnings: Warnings:
Warning 1265 Data truncated for column 'v' at row 1 Note 1265 Data truncated for column 'v' at row 1
select concat('*',v,'*',c,'*',t,'*') from t1; select concat('*',v,'*',c,'*',t,'*') from t1;
concat('*',v,'*',c,'*',t,'*') concat('*',v,'*',c,'*',t,'*')
*+ *+*+ * *+ *+*+ *
...@@ -1346,7 +1346,7 @@ t1 CREATE TABLE `t1` ( ...@@ -1346,7 +1346,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1 ) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1
alter table t1 modify t varchar(10); alter table t1 modify t varchar(10);
Warnings: Warnings:
Warning 1265 Data truncated for column 't' at row 2 Note 1265 Data truncated for column 't' at row 2
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
......
...@@ -255,7 +255,7 @@ insert into t1 values('+ ', '+ ', '+ '); ...@@ -255,7 +255,7 @@ insert into t1 values('+ ', '+ ', '+ ');
set @a=repeat(' ',20); set @a=repeat(' ',20);
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
Warnings: Warnings:
Warning 1265 Data truncated for column 'v' at row 1 Note 1265 Data truncated for column 'v' at row 1
select concat('*',v,'*',c,'*',t,'*') from t1; select concat('*',v,'*',c,'*',t,'*') from t1;
concat('*',v,'*',c,'*',t,'*') concat('*',v,'*',c,'*',t,'*')
*+ *+*+ * *+ *+*+ *
......
...@@ -571,7 +571,7 @@ insert into t1 values('+ ', '+ ', '+ '); ...@@ -571,7 +571,7 @@ insert into t1 values('+ ', '+ ', '+ ');
set @a=repeat(' ',20); set @a=repeat(' ',20);
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
Warnings: Warnings:
Warning 1265 Data truncated for column 'v' at row 1 Note 1265 Data truncated for column 'v' at row 1
select concat('*',v,'*',c,'*',t,'*') from t1; select concat('*',v,'*',c,'*',t,'*') from t1;
concat('*',v,'*',c,'*',t,'*') concat('*',v,'*',c,'*',t,'*')
*+ *+*+ * *+ *+*+ *
...@@ -617,7 +617,7 @@ t1 CREATE TABLE `t1` ( ...@@ -617,7 +617,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t1 modify t varchar(10); alter table t1 modify t varchar(10);
Warnings: Warnings:
Warning 1265 Data truncated for column 't' at row 2 Note 1265 Data truncated for column 't' at row 2
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
......
...@@ -818,7 +818,6 @@ ERROR 01000: Data truncated for column 'col1' at row 1 ...@@ -818,7 +818,6 @@ ERROR 01000: Data truncated for column 'col1' at row 1
INSERT INTO t1 (col2) VALUES ('hellobob'); INSERT INTO t1 (col2) VALUES ('hellobob');
ERROR 01000: Data truncated for column 'col2' at row 1 ERROR 01000: Data truncated for column 'col2' at row 1
INSERT INTO t1 (col2) VALUES ('hello '); INSERT INTO t1 (col2) VALUES ('hello ');
ERROR 01000: Data truncated for column 'col2' at row 1
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he'; UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
ERROR 01000: Data truncated for column 'col1' at row 2 ERROR 01000: Data truncated for column 'col1' at row 2
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he'; UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
...@@ -835,6 +834,7 @@ col1 col2 ...@@ -835,6 +834,7 @@ col1 col2
hello hello hello hello
he hellot he hellot
hello hello hello hello
NULL hello
hello hellob hello hellob
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (col1 enum('red','blue','green')); CREATE TABLE t1 (col1 enum('red','blue','green'));
......
...@@ -4672,6 +4672,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -4672,6 +4672,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
uint32 not_used, copy_length; uint32 not_used, copy_length;
char buff[80]; char buff[80];
String tmpstr(buff,sizeof(buff), &my_charset_bin); String tmpstr(buff,sizeof(buff), &my_charset_bin);
enum MYSQL_ERROR::enum_warning_level level= MYSQL_ERROR::WARN_LEVEL_WARN;
/* Convert character set if nesessary */ /* Convert character set if nesessary */
if (String::needs_conversion(length, cs, field_charset, &not_used)) if (String::needs_conversion(length, cs, field_charset, &not_used))
...@@ -4696,11 +4697,24 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -4696,11 +4697,24 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
*ptr= (uchar) copy_length; *ptr= (uchar) copy_length;
else else
int2store(ptr, copy_length); int2store(ptr, copy_length);
if (copy_length < length) // Check if we lost something other than just trailing spaces
if ((copy_length < length) && table->in_use->count_cuted_fields)
{
const char *end= from + length;
from+= copy_length;
from+= field_charset->cset->scan(field_charset, from, end, MY_SEQ_SPACES);
/*
If we lost only spaces then produce a NOTE, not a WARNING.
But if we have already had errors (e.g with charset conversion),
then don't reset level to NOTE.
*/
if (from == end && !error)
level= MYSQL_ERROR::WARN_LEVEL_NOTE;
error= 1; error= 1;
}
if (error) if (error)
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1); set_warning(level, ER_WARN_DATA_TRUNCATED, 1);
return error; return error;
} }
......
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