diff options
author | unknown <monty@mysql.com> | 2005-04-01 15:04:50 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-04-01 15:04:50 +0300 |
commit | db7561ecf8b703e285320f2e0fcec7daf72ca9d6 (patch) | |
tree | 7920c948db7d0f2174fb24ba26cd648144fa4850 /mysql-test/t | |
parent | 750180d2998cc7d04e4a0fb4ccec8b5214c3f145 (diff) | |
download | mariadb-git-db7561ecf8b703e285320f2e0fcec7daf72ca9d6.tar.gz |
Invalid DEFAULT values for CREATE TABLE now generates errors. (Bug #5902)
CAST() now produces warnings when casting a wrong INTEGER or CHAR values. This also applies to implicite string to number casts. (Bug #5912)
ALTER TABLE now fails in STRICT mode if it generates warnings.
Inserting a zero date in a DATE, DATETIME or TIMESTAMP column during TRADITIONAL mode now produces an error. (Bug #5933)
mysql-test/r/bigint.result:
New warning added
mysql-test/r/cast.result:
Added testing of wrong CAST's of strings to numbers and numbers to strings
mysql-test/r/create.result:
Added test for wrong default values (#5902)
mysql-test/r/func_if.result:
Changed tests to produce less warnings
mysql-test/r/func_misc.result:
New warning
mysql-test/r/func_str.result:
Added missing drop table
Changed test to produce less warnings
New warnings
mysql-test/r/ndb_index_unique.result:
Removed wrong default usage
mysql-test/r/ps_1general.result:
Changed tests to produce less warnings
mysql-test/r/row.result:
New warnings
mysql-test/r/rpl_session_var.result:
Changed tests to produce less warnings
mysql-test/r/strict.result:
New tests for CAST() and zero date handling
mysql-test/r/subselect.result:
Changed tests to produce less warnings
mysql-test/r/type_ranges.result:
Changed tests to produce less warnings
mysql-test/t/cast.test:
Added testing of wrong CAST's of strings to numbers and numbers to strings
mysql-test/t/create.test:
Added test for wrong default values (#5902)
mysql-test/t/func_if.test:
Changed tests to produce less warnings
mysql-test/t/func_str.test:
Added missing drop table
Changed test to produce less warnings
New warnings
mysql-test/t/ndb_index_unique.test:
Removed wrong default usage
mysql-test/t/ps_1general.test:
Changed tests to produce less warnings
mysql-test/t/rpl_session_var.test:
Changed tests to produce less warnings
mysql-test/t/strict.test:
New tests for CAST() and zero date handling
mysql-test/t/subselect.test:
Changed tests to produce less warnings
mysql-test/t/type_ranges.test:
Changed tests to produce less warnings
sql/Makefile.am:
Added new include file
sql/field.cc:
Added warnings for zero dates for DATE, DATETIME and TIMESTAMP
Moved Field_blob::max_length() to a more appropriate position
Changed type for 'level' in set_warning() to avoid casts
sql/field.h:
Changed type for 'level' in set_warning() to avoid casts
sql/field_conv.cc:
Copy date and datetime fields through string in 'traditional' mode to detect zero dates
sql/item.cc:
Removed compiler warnings
Give warnings for wrong CAST of strings -> number
sql/item.h:
Moved Item_string::val_real() and ::val_int() to item.cc
sql/item_row.cc:
Better detection of null values (which doesn't produce warnings)
sql/item_sum.cc:
Better detection of null values (which doesn't produce warnings)
sql/item_timefunc.cc:
Give warnings for wrong CAST of number -> string
sql/my_decimal.cc:
Fixed typo in comment
sql/mysql_priv.h:
Removed prototype for static function
Moved defines for error handling to sql_error.h (to be able to use these in field.h)
sql/mysqld.cc:
Simplify code
sql/sql_class.h:
Moved to sql_error.h
sql/sql_load.cc:
Removed wrong cast
sql/sql_parse.cc:
Fixed wrong printf()
sql/sql_table.cc:
Made mysql_prepare_table() static
Changed references to pointers to make code more readable
ALTER TABLE now aborts if one gets warnings in STRICT mode
sql/time.cc:
Fixed possible wrong call
sql/unireg.cc:
Removed one call to current_thd
Give errors if one uses a wrong DEFAULT value
Diffstat (limited to 'mysql-test/t')
-rw-r--r-- | mysql-test/t/cast.test | 13 | ||||
-rw-r--r-- | mysql-test/t/create.test | 19 | ||||
-rw-r--r-- | mysql-test/t/func_if.test | 5 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 5 | ||||
-rw-r--r-- | mysql-test/t/ndb_index_unique.test | 8 | ||||
-rw-r--r-- | mysql-test/t/ps_1general.test | 4 | ||||
-rw-r--r-- | mysql-test/t/rpl_session_var.test | 2 | ||||
-rw-r--r-- | mysql-test/t/strict.test | 52 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 4 | ||||
-rw-r--r-- | mysql-test/t/type_ranges.test | 2 |
10 files changed, 95 insertions, 19 deletions
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 94d9590dd5f..e7dd49394ee 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -5,6 +5,7 @@ select CAST(1-2 AS UNSIGNED); select CAST(CAST(1-2 AS UNSIGNED) AS SIGNED INTEGER); select CONVERT('-1',UNSIGNED); +select CAST('10 ' as unsigned integer); select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1; select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1; select ~5, cast(~5 as signed); @@ -16,11 +17,22 @@ select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A"; select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); select cast("1:2:3" as TIME); select CONVERT("2004-01-22 21:45:33",DATE); +select 10+'10'; +select 10.0+'10'; +select 10E+0+'10'; + +# The following cast creates warnings + select CONVERT(DATE "2004-01-22 21:45:33" USING latin1); select CONVERT(DATE "2004-01-22 21:45:33",CHAR); select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4)); select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4)); select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4)); +select cast('-10a' as signed integer); +select cast('a10' as unsigned integer); +select 10+'a'; +select 10.0+cast('a' as decimal); +select 10E+0+'a'; # # Character set convertion @@ -41,6 +53,7 @@ select cast(_latin1'abc' AS char(2)) as c3, cast(_latin1'a ' AS char(2)) as c4, cast(_latin1'a' AS char(2)) as c5; +select cast(1000 as CHAR(3)); create table t1 select cast(_latin1'ab' AS char) as c1, diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 26b467a398d..1e2cf391221 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -49,14 +49,25 @@ create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int); # -# Some wrong defaults, so these creates should fail too +# Some wrong defaults, so these creates should fail too (Bug #5902) # --error 1067 -create table test (a datetime default now()); +create table t1 (a datetime default now()); --error 1294 -create table test (a datetime on update now()); +create table t1 (a datetime on update now()); --error 1067 -create table test (a int default 100 auto_increment); +create table t1 (a int default 100 auto_increment); +--error 1067 +create table t1 (a tinyint default 1000); +--error 1067 +create table t1 (a varchar(5) default 'abcdef'); + +create table t1 (a varchar(5) default 'abcde'); +insert into t1 values(); +select * from t1; +--error 1067 +alter table t1 alter column a set default 'abcdef'; +drop table t1; # # test of dummy table names diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index 693773b18c8..a2ea26390ca 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -25,9 +25,10 @@ explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order # # NULLIF test # -select nullif(u=0, 'test') from t1; -explain extended select nullif(u=0, 'test') from t1; +select nullif(u, 1) from t1; +explain extended select nullif(u, 1) from t1; drop table t1; +select nullif(1,'test'); # # Bug 2629 diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 8bf36431587..b3c875f7bf5 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -3,7 +3,7 @@ # Testing string functions --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings set names latin1; @@ -244,7 +244,7 @@ select FIELD('b','A' COLLATE latin1_bin,'B'); select FIELD(_latin2'b','A','B'); --error 1270 select FIELD('b',_latin2'A','B'); -select FIELD('b',_latin2'A','B',1); +select FIELD('1',_latin2'3','2',1); select POSITION(_latin1'B' IN _latin1'abcd'); select POSITION(_latin1'B' IN _latin1'abcd' COLLATE latin1_bin); @@ -523,4 +523,3 @@ SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id ORDER BY t1.id; DROP TABLE t1, t2; - diff --git a/mysql-test/t/ndb_index_unique.test b/mysql-test/t/ndb_index_unique.test index 2fc7c496fea..6714f0233cf 100644 --- a/mysql-test/t/ndb_index_unique.test +++ b/mysql-test/t/ndb_index_unique.test @@ -182,8 +182,8 @@ INSERT INTO t3 VALUES (1,'V1',NULL); CREATE TABLE t4 ( uid bigint(20) unsigned NOT NULL default '0', gid bigint(20) unsigned NOT NULL, - rid bigint(20) unsigned NOT NULL default '-1', - cid bigint(20) unsigned NOT NULL default '-1', + rid bigint(20) unsigned NOT NULL, + cid bigint(20) unsigned NOT NULL, UNIQUE KEY m (uid,gid,rid,cid) ) engine=ndbcluster; INSERT INTO t4 VALUES (1,1,2,4); @@ -209,8 +209,8 @@ CREATE TABLE t7 ( mid bigint(20) unsigned NOT NULL PRIMARY KEY, uid bigint(20) unsigned NOT NULL default '0', gid bigint(20) unsigned NOT NULL, - rid bigint(20) unsigned NOT NULL default '-1', - cid bigint(20) unsigned NOT NULL default '-1', + rid bigint(20) unsigned NOT NULL, + cid bigint(20) unsigned NOT NULL, UNIQUE KEY m (uid,gid,rid,cid) ) engine=ndbcluster; INSERT INTO t7 VALUES(1, 1, 1, 1, 1); diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index 22a4a8bf2c9..4800cb831f7 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -500,10 +500,10 @@ select 'a' || 'b' ; prepare stmt4 from ' SET sql_mode="" '; execute stmt4; # check if the sql_mode is not ansi -select 'a' || 'b' ; +select '2' || '3' ; # Will a switch of the sqlmode affect the execution of already prepared # statements ? -prepare stmt5 from ' select ''a'' || ''b'' ' ; +prepare stmt5 from ' select ''2'' || ''3'' ' ; execute stmt5; SET sql_mode=ansi; execute stmt5; diff --git a/mysql-test/t/rpl_session_var.test b/mysql-test/t/rpl_session_var.test index 2379df721b7..a6f4b496a23 100644 --- a/mysql-test/t/rpl_session_var.test +++ b/mysql-test/t/rpl_session_var.test @@ -7,7 +7,7 @@ create table t1(a varchar(100),b int); set @@session.sql_mode=pipes_as_concat; insert into t1 values('My'||'SQL', 1); set @@session.sql_mode=default; -insert into t1 values('My'||'SQL', 2); +insert into t1 values('1'||'2', 2); select * from t1 where b<3 order by a; save_master_pos; connection slave; diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test index 96ba9993c49..f98fc30ff48 100644 --- a/mysql-test/t/strict.test +++ b/mysql-test/t/strict.test @@ -978,6 +978,58 @@ select count(*) from t1 where STR_TO_DATE('2004.12.12 10:22:61','%Y.%m.%d %T') I drop table t1; # +# Check insert with wrong CAST() (Bug #5912) +# + +create table t1 (col1 char(3), col2 integer); +--error 1292 +insert into t1 (col1) values (cast(1000 as char(3))); +--error 1292 +insert into t1 (col1) values (cast(1000E+0 as char(3))); +--error 1292 +insert into t1 (col1) values (cast(1000.0 as char(3))); +--error 1292 +insert into t1 (col2) values (cast('abc' as signed integer)); +--error 1292 +insert into t1 (col2) values (10E+0 + 'a'); +--error 1292 +insert into t1 (col2) values (cast('10a' as unsigned integer)); +insert into t1 (col2) values (cast('10' as unsigned integer)); +insert into t1 (col2) values (cast('10' as signed integer)); +insert into t1 (col2) values (10E+0 + '0 '); +select * from t1; +drop table t1; + +# +# Zero dates using numbers was not checked properly (Bug #5933) +# + +create table t1 (col1 date, col2 datetime, col3 timestamp); +--error 1292 +insert into t1 values (0,0,0); +--error 1292 +insert into t1 values (0.0,0.0,0.0); +set sql_mode='no_zero_date'; +insert into t1 values (0,0,0); +insert into t1 values (0.0,0.0,0.0); +drop table t1; +set sql_mode='traditional'; +create table t1 (col1 date); +insert ignore into t1 values ('0000-00-00'); +--error 1292 +insert into t1 select * from t1; +insert ignore into t1 values ('0000-00-00'); +--error 1292 +insert into t1 select * from t1; +--error 1292 +alter table t1 modify col1 datetime; +alter ignore table t1 modify col1 datetime; +--error 1292 +insert into t1 select * from t1; +select * from t1; +drop table t1; + +# # Restore mode # set sql_mode=@org_mode; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index cfcb32f37c8..69b30d2235d 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -46,9 +46,9 @@ SELECT ROW(1,2,3) > (SELECT 1,2,1); SELECT ROW(1,2,3) = (SELECT 1,2,NULL); SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); -SELECT (SELECT 1.5,2,'a') = ROW('b',2,'b'); +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); -SELECT (SELECT 1.5,2,'a') = ROW(1.5,'c','a'); +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); -- error 1241 diff --git a/mysql-test/t/type_ranges.test b/mysql-test/t/type_ranges.test index 5f035921064..3bd3502766b 100644 --- a/mysql-test/t/type_ranges.test +++ b/mysql-test/t/type_ranges.test @@ -69,7 +69,7 @@ ALTER TABLE t1 add new_field char(10) default "new" not null, change blob_col new_blob_col varchar(20), change date_field date_field char(10), -alter column string set default "new default", +alter column string set default "newdefault", alter short drop default, DROP INDEX utiny, DROP INDEX ushort, |