mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
If VARCHAR strips only trailing spaces, then produce
a note, not a warning or error.
This commit is contained in:
parent
a55cd1f1c4
commit
691b3283d2
5 changed files with 23 additions and 9 deletions
|
@ -1300,7 +1300,7 @@ insert into t1 values('+ ', '+ ', '+ ');
|
|||
set @a=repeat(' ',20);
|
||||
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
|
||||
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;
|
||||
concat('*',v,'*',c,'*',t,'*')
|
||||
*+ *+*+ *
|
||||
|
@ -1346,7 +1346,7 @@ t1 CREATE TABLE `t1` (
|
|||
) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1
|
||||
alter table t1 modify t varchar(10);
|
||||
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;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
|
|
|
@ -255,7 +255,7 @@ insert into t1 values('+ ', '+ ', '+ ');
|
|||
set @a=repeat(' ',20);
|
||||
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
|
||||
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;
|
||||
concat('*',v,'*',c,'*',t,'*')
|
||||
*+ *+*+ *
|
||||
|
|
|
@ -571,7 +571,7 @@ insert into t1 values('+ ', '+ ', '+ ');
|
|||
set @a=repeat(' ',20);
|
||||
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
|
||||
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;
|
||||
concat('*',v,'*',c,'*',t,'*')
|
||||
*+ *+*+ *
|
||||
|
@ -617,7 +617,7 @@ t1 CREATE TABLE `t1` (
|
|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
alter table t1 modify t varchar(10);
|
||||
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;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
|
|
|
@ -818,7 +818,6 @@ ERROR 01000: Data truncated for column 'col1' at row 1
|
|||
INSERT INTO t1 (col2) VALUES ('hellobob');
|
||||
ERROR 01000: Data truncated for column 'col2' at row 1
|
||||
INSERT INTO t1 (col2) VALUES ('hello ');
|
||||
ERROR 01000: Data truncated for column 'col2' at row 1
|
||||
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
|
||||
ERROR 01000: Data truncated for column 'col1' at row 2
|
||||
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
|
||||
|
@ -835,6 +834,7 @@ col1 col2
|
|||
hello hello
|
||||
he hellot
|
||||
hello hello
|
||||
NULL hello
|
||||
hello hellob
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (col1 enum('red','blue','green'));
|
||||
|
|
20
sql/field.cc
20
sql/field.cc
|
@ -4672,6 +4672,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
|
|||
uint32 not_used, copy_length;
|
||||
char buff[80];
|
||||
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 */
|
||||
if (String::needs_conversion(length, cs, field_charset, ¬_used))
|
||||
|
@ -4696,11 +4697,24 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
|
|||
*ptr= (uchar) copy_length;
|
||||
else
|
||||
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;
|
||||
}
|
||||
if (error)
|
||||
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
|
||||
set_warning(level, ER_WARN_DATA_TRUNCATED, 1);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue