Description:
mysqltest uses numeric MySQL error codes in reporting errors,
and SQLSTATE values sometimes. This is confusing and inconsistent.
How to repeat:
If a SQL statement fails, mysqltest reports the numeric error code
in the error message. Assume that the table test.t does not exist
and run this script:
mysqltest test << EOF
drop table t;
EOF
Result: mysqltest displays this error message:
mysqltest: At line 1: query 'drop table t' failed: 1051: Unknown table 't'
Okay, so to suppress that error and indicate that I expect error 1051
to occur, I can add an error command:
mysqltest test << EOF
--error 1051
drop table t;
EOF
Result: mysqltest accepts the error that occurs as okay, and writes
the following as the test output:
drop table t;
ERROR 42S02: Unknown table 't'
Note how the error now is displayed as a SQLSTATE value.
Suggested fix:
The problem here is the inconsistency. As to the fix, I'm not
sure. When errors occur that are not indicated as "expected"
by means of an error command, probably no change is needed
(display the error number, as is done now).
But when an error occurs that is indicated as "expected" by means
of an error command, I can think of two approaches:
1) In the test result, display the error number (not SQLSTATE value)
for consistency with how unexpected errors are reported.
2) In the test result, display the error using the format that was used
in the error command. For example, if I say --error 1051, report 1051
in the test result. If I say --error S42S02, repost 40S02 in the test
result. (This would be trickier in the event that the error command
listed multiple expected errors and used a mix of numbers and SQLSTATE
values.)