Commit ec06f3e7 authored by ramil@mysql.com's avatar ramil@mysql.com

a fix (bug #9029 Traditional: Wrong SQLSTATE returned for string truncation).

parent db4ca33f
...@@ -906,14 +906,14 @@ INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello '); ...@@ -906,14 +906,14 @@ INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello ');
INSERT INTO t1 (col1) VALUES ('hellobob'); INSERT INTO t1 (col1) VALUES ('hellobob');
ERROR 22001: Data too long for column 'col1' at row 1 ERROR 22001: Data too long 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 22001: Data too long for column 'col2' at row 1
INSERT INTO t1 (col2) VALUES ('hello '); INSERT INTO t1 (col2) VALUES ('hello ');
Warnings: Warnings:
Note 1265 Data truncated for column 'col2' at row 1 Note 1265 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 22001: Data too long for column 'col1' at row 2 ERROR 22001: Data too long for column 'col1' at row 2
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he'; UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
ERROR 01000: Data truncated for column 'col2' at row 2 ERROR 22001: Data too long for column 'col2' at row 2
INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob'); INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob');
Warnings: Warnings:
Warning 1265 Data truncated for column 'col1' at row 1 Warning 1265 Data truncated for column 'col1' at row 1
...@@ -1011,3 +1011,22 @@ col1 col2 ...@@ -1011,3 +1011,22 @@ col1 col2
3 3
99 99
DROP TABLE t1; DROP TABLE t1;
set sql_mode='traditional';
create table t1 (charcol char(255), varcharcol varchar(255),
binarycol binary(255), varbinarycol varbinary(255), tinytextcol tinytext,
tinyblobcol tinyblob);
insert into t1 (charcol) values (repeat('x',256));
ERROR 22001: Data too long for column 'charcol' at row 1
insert into t1 (varcharcol) values (repeat('x',256));
ERROR 22001: Data too long for column 'varcharcol' at row 1
insert into t1 (binarycol) values (repeat('x',256));
ERROR 22001: Data too long for column 'binarycol' at row 1
insert into t1 (varbinarycol) values (repeat('x',256));
ERROR 22001: Data too long for column 'varbinarycol' at row 1
insert into t1 (tinytextcol) values (repeat('x',256));
ERROR 22001: Data too long for column 'tinytextcol' at row 1
insert into t1 (tinyblobcol) values (repeat('x',256));
ERROR 22001: Data too long for column 'tinyblobcol' at row 1
select * from t1;
charcol varcharcol binarycol varbinarycol tinytextcol tinyblobcol
drop table t1;
...@@ -868,12 +868,12 @@ CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6)); ...@@ -868,12 +868,12 @@ CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6));
INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello '); INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello ');
--error 1406 --error 1406
INSERT INTO t1 (col1) VALUES ('hellobob'); INSERT INTO t1 (col1) VALUES ('hellobob');
--error 1265 --error 1406
INSERT INTO t1 (col2) VALUES ('hellobob'); INSERT INTO t1 (col2) VALUES ('hellobob');
INSERT INTO t1 (col2) VALUES ('hello '); INSERT INTO t1 (col2) VALUES ('hello ');
--error 1406 --error 1406
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he'; UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
--error 1265 --error 1406
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he'; UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob'); INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob');
UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he'; UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he';
...@@ -939,3 +939,26 @@ INSERT IGNORE INTO t1 (col1) values (3); ...@@ -939,3 +939,26 @@ INSERT IGNORE INTO t1 (col1) values (3);
INSERT IGNORE INTO t1 () values (); INSERT IGNORE INTO t1 () values ();
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
#
# Bug #9029 Traditional: Wrong SQLSTATE returned for string truncation
#
set sql_mode='traditional';
create table t1 (charcol char(255), varcharcol varchar(255),
binarycol binary(255), varbinarycol varbinary(255), tinytextcol tinytext,
tinyblobcol tinyblob);
--error 1406
insert into t1 (charcol) values (repeat('x',256));
--error 1406
insert into t1 (varcharcol) values (repeat('x',256));
--error 1406
insert into t1 (binarycol) values (repeat('x',256));
--error 1406
insert into t1 (varbinarycol) values (repeat('x',256));
--error 1406
insert into t1 (tinytextcol) values (repeat('x',256));
--error 1406
insert into t1 (tinyblobcol) values (repeat('x',256));
select * from t1;
drop table t1;
...@@ -5332,7 +5332,7 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5332,7 +5332,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[STRING_BUFFER_USUAL_SIZE]; char buff[STRING_BUFFER_USUAL_SIZE];
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; bool lost_only_spaces= FALSE;
/* Convert character set if necessary */ /* Convert character set if necessary */
if (String::needs_conversion(length, cs, field_charset, &not_used)) if (String::needs_conversion(length, cs, field_charset, &not_used))
...@@ -5370,11 +5370,18 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5370,11 +5370,18 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
then don't reset level to NOTE. then don't reset level to NOTE.
*/ */
if (from == end && !error) if (from == end && !error)
level= MYSQL_ERROR::WARN_LEVEL_NOTE; lost_only_spaces= TRUE;
error= 1; error= 1;
} }
if (error) if (error)
set_warning(level, WARN_DATA_TRUNCATED, 1); {
if (lost_only_spaces)
set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
else if (table->in_use->abort_on_warning)
set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
}
return error; return error;
} }
...@@ -5971,7 +5978,12 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) ...@@ -5971,7 +5978,12 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
bmove(ptr+packlength,(char*) &from,sizeof(char*)); bmove(ptr+packlength,(char*) &from,sizeof(char*));
} }
if (error) if (error)
{
if (table->in_use->abort_on_warning)
set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
}
return 0; return 0;
} }
......
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