Commit c7cf529f authored by unknown's avatar unknown

Fixed bug in strict mode (A state was not properly cleared on successful insert/update's)


mysql-test/mysql-test-run.sh:
  Print less text on failure
mysql-test/r/strict.result:
  More tests for strict mode
mysql-test/t/strict.test:
  More tests for strict mode
sql/set_var.cc:
  Don't clear any flags in traditional mode
sql/sql_insert.cc:
  Fixed bug in strict mode
sql/sql_update.cc:
  Fixed bug in strict mode
parent 6966e869
......@@ -1184,17 +1184,19 @@ stop_master ()
mysql_stop ()
{
$ECHO "Ending Tests"
$ECHO "Shutting-down MySQL daemon"
$ECHO ""
stop_master
$ECHO "Master shutdown finished"
stop_slave
stop_slave 1
stop_slave 2
$ECHO "Slave shutdown finished"
return 1
if [ "$MASTER_RUNNING" = 1 ]
then
$ECHO "Ending Tests"
$ECHO "Shutting-down MySQL daemon"
$ECHO ""
stop_master
$ECHO "Master shutdown finished"
stop_slave
stop_slave 1
stop_slave 2
$ECHO "Slave shutdown finished"
fi
return 1
}
mysql_restart ()
......@@ -1383,8 +1385,6 @@ run_testcase ()
then
mysql_restart
fi
$ECHO "Resuming Tests"
$ECHO ""
fi
fi
fi
......
......@@ -26,14 +26,20 @@ ERROR 22007: Incorrect date value: '59' for column 'col1' at row 1
set @@sql_mode='STRICT_ALL_TABLES';
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
INSERT INTO t1 VALUES('2004-0-31');
ERROR 22007: Incorrect date value: '2004-0-31' for column 'col1' at row 1
INSERT INTO t1 VALUES('2004-0-30');
ERROR 22007: Incorrect date value: '2004-0-30' for column 'col1' at row 1
INSERT INTO t1 VALUES('2004-01-04'),('2004-0-31'),('2004-01-05');
ERROR 22007: Incorrect date value: '2004-0-31' for column 'col1' at row 2
INSERT INTO t1 VALUES('0000-00-00');
INSERT IGNORE INTO t1 VALUES('2004-0-29');
Warnings:
Warning 1265 Data truncated for column 'col1' at row 1
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
INSERT INTO t1 VALUES('0000-00-00');
ERROR 22007: Incorrect date value: '0000-00-00' for column 'col1' at row 1
INSERT IGNORE INTO t1 VALUES('0000-00-00');
Warnings:
Warning 1265 Data truncated for column 'col1' at row 1
INSERT INTO t1 VALUES ('2004-0-30');
INSERT INTO t1 VALUES ('2004-2-30');
ERROR 22007: Incorrect date value: '2004-2-30' for column 'col1' at row 1
......@@ -54,6 +60,8 @@ col1
2004-00-31
2004-01-04
0000-00-00
0000-00-00
0000-00-00
2004-00-30
2004-02-30
2004-02-29
......@@ -188,6 +196,13 @@ col1
DROP TABLE t1;
CREATE TABLE t1(col1 TINYINT, col2 TINYINT UNSIGNED);
INSERT INTO t1 VALUES(-128,0),(0,0),(127,255),('-128','0'),('0','0'),('127','255'),(-128.0,0.0),(0.0,0.0),(127.0,255.0);
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
MOD(col1,0)
NULL
NULL
Warnings:
Error 1365 Division by 0
Error 1365 Division by 0
INSERT INTO t1 (col1) VALUES(-129);
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES(128);
......@@ -210,14 +225,30 @@ INSERT INTO t1 (col2) VALUES(-1.0);
ERROR 22003: Out of range value adjusted for column 'col2' at row 1
INSERT INTO t1 (col2) VALUES(256.0);
ERROR 22003: Out of range value adjusted for column 'col2' at row 1
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 1;
MOD(col1,0)
NULL
Warnings:
Error 1365 Division by 0
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
UPDATE t1 SET col2=col2 + 50 WHERE col2 > 0;
ERROR 22003: Out of range value adjusted for column 'col2' at row 3
UPDATE t1 SET col1=col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
ERROR 22012: Division by 0
set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
INSERT INTO t1 values (1/0,1/0);
Warnings:
Error 1365 Division by 0
Error 1365 Division by 0
set @@sql_mode='ansi,traditional';
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
MOD(col1,0)
NULL
NULL
Warnings:
Error 1365 Division by 0
Error 1365 Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR HY000: Incorrect integer value: '' for column 'col1' at row 1
INSERT INTO t1 (col1) VALUES ('a59b');
......@@ -231,6 +262,9 @@ INSERT IGNORE INTO t1 values (1/0,1/0);
Warnings:
Error 1365 Division by 0
Error 1365 Division by 0
set @@sql_mode='ansi';
INSERT INTO t1 values (1/0,1/0);
set @@sql_mode='ansi,traditional';
INSERT IGNORE INTO t1 VALUES('-129','-1'),('128','256');
Warnings:
Warning 1264 Out of range value adjusted for column 'col1' at row 1
......@@ -255,8 +289,10 @@ col1 col2
-128 0
0 NULL
127 255
NULL NULL
2 NULL
NULL NULL
NULL NULL
-128 0
127 255
-128 0
......@@ -294,7 +330,7 @@ UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
ERROR 22003: Out of range value adjusted for column 'col2' at row 3
UPDATE t1 SET col1 = col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR HY000: Incorrect integer value: '' for column 'col1' at row 1
......@@ -378,7 +414,7 @@ UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
ERROR 22003: Out of range value adjusted for column 'col2' at row 3
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR HY000: Incorrect integer value: '' for column 'col1' at row 1
......@@ -462,7 +498,7 @@ UPDATE t1 SET col2 =col2 + 50 WHERE col2 > 0;
ERROR 22003: Out of range value adjusted for column 'col2' at row 3
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
......@@ -541,7 +577,7 @@ INSERT INTO t1 (col2) VALUES(18446744073709551616.0);
ERROR 22003: Out of range value adjusted for column 'col2' at row 1
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR 22003: Out of range value adjusted for column 'col1' at row 1
......@@ -621,7 +657,7 @@ UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11;
ERROR 22003: Out of range value adjusted for column 'col1' at row 6
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR 01000: Data truncated for column 'col1' at row 1
......@@ -692,7 +728,7 @@ UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
ERROR 22003: Out of range value adjusted for column 'col1' at row 2
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR 01000: Data truncated for column 'col1' at row 1
......@@ -742,7 +778,7 @@ UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
ERROR 22003: Out of range value adjusted for column 'col1' at row 2
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
ERROR 22012: Division by 0
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
ERROR 22012: Division by 0
INSERT INTO t1 (col1) VALUES ('');
ERROR 01000: Data truncated for column 'col1' at row 1
......
......@@ -38,13 +38,15 @@ set @@sql_mode='STRICT_ALL_TABLES';
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
--error 1292
INSERT INTO t1 VALUES('2004-0-31');
INSERT INTO t1 VALUES('2004-0-30');
--error 1292
INSERT INTO t1 VALUES('2004-01-04'),('2004-0-31'),('2004-01-05');
INSERT INTO t1 VALUES('0000-00-00');
INSERT IGNORE INTO t1 VALUES('2004-0-29');
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
--error 1292
INSERT INTO t1 VALUES('0000-00-00');
INSERT IGNORE INTO t1 VALUES('0000-00-00');
INSERT INTO t1 VALUES ('2004-0-30');
--error 1292
INSERT INTO t1 VALUES ('2004-2-30');
......@@ -165,6 +167,8 @@ DROP TABLE t1;
CREATE TABLE t1(col1 TINYINT, col2 TINYINT UNSIGNED);
INSERT INTO t1 VALUES(-128,0),(0,0),(127,255),('-128','0'),('0','0'),('127','255'),(-128.0,0.0),(0.0,0.0),(127.0,255.0);
# Test that we restored the mode checking properly after an ok query
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
-- error 1264
INSERT INTO t1 (col1) VALUES(-129);
-- error 1264
......@@ -187,14 +191,17 @@ INSERT INTO t1 (col1) VALUES(128.0);
INSERT INTO t1 (col2) VALUES(-1.0);
-- error 1264
INSERT INTO t1 (col2) VALUES(256.0);
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 1;
--error 1264
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
--error 1264
UPDATE t1 SET col2=col2 + 50 WHERE col2 > 0;
--error 1365
UPDATE t1 SET col1=col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
INSERT INTO t1 values (1/0,1/0);
set @@sql_mode='ansi,traditional';
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
# Should return SQLSTATE 22018 invalid character value for cast
--error 1366
INSERT INTO t1 (col1) VALUES ('');
......@@ -204,6 +211,9 @@ INSERT INTO t1 (col1) VALUES ('a59b');
INSERT INTO t1 (col1) VALUES ('1a');
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
INSERT IGNORE INTO t1 values (1/0,1/0);
set @@sql_mode='ansi';
INSERT INTO t1 values (1/0,1/0);
set @@sql_mode='ansi,traditional';
INSERT IGNORE INTO t1 VALUES('-129','-1'),('128','256');
INSERT IGNORE INTO t1 VALUES(-129.0,-1.0),(128.0,256.0);
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
......@@ -247,7 +257,7 @@ UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
--error 1365
UPDATE t1 SET col1 = col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error 1366
INSERT INTO t1 (col1) VALUES ('');
--error 1366
......@@ -300,7 +310,7 @@ UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
--error 1365
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error 1366
INSERT INTO t1 (col1) VALUES ('');
--error 1366
......@@ -353,7 +363,7 @@ UPDATE t1 SET col2 =col2 + 50 WHERE col2 > 0;
--error 1365
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error 1264
INSERT INTO t1 (col1) VALUES ('');
--error 1264
......@@ -411,7 +421,7 @@ INSERT INTO t1 (col2) VALUES(18446744073709551616.0);
--error 1365
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error 1264
INSERT INTO t1 (col1) VALUES ('');
--error 1264
......@@ -461,7 +471,7 @@ UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11;
--error 1365
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error 1265
INSERT INTO t1 (col1) VALUES ('');
--error 1265
......@@ -497,7 +507,7 @@ UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
--error 1365
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
--error 1265
INSERT INTO t1 (col1) VALUES ('');
--error 1265
......@@ -531,7 +541,7 @@ UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
--error 1365
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
--error 1365
SELECT MOD(col1,0) FROM t1;
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
--error 1265
INSERT INTO t1 (col1) VALUES ('');
--error 1265
......
......@@ -3102,12 +3102,9 @@ ulong fix_sql_mode(ulong sql_mode)
if (sql_mode & MODE_MYSQL323)
sql_mode|= MODE_NO_FIELD_OPTIONS;
if (sql_mode & MODE_TRADITIONAL)
{
sql_mode|= (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES |
MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
MODE_ERROR_FOR_DIVISION_BY_ZERO);
sql_mode&= ~MODE_INVALID_DATES;
}
return sql_mode;
}
......
......@@ -453,6 +453,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
free_underlaid_joins(thd, &thd->lex->select_lex);
table->insert_values=0;
thd->abort_on_warning= 0;
DBUG_RETURN(0);
abort:
......
......@@ -457,6 +457,7 @@ int mysql_update(THD *thd,
DBUG_PRINT("info",("%d records updated",updated));
}
thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */
thd->abort_on_warning= 0;
free_io_cache(table);
DBUG_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