Bug #35941 List of error, warning and note messages is lost due to syntax errors
Submitted: 9 Apr 2008 15:28 Modified: 15 Apr 2008 19:32
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:6.0-BK OS:Any
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: show warnings, syntax error, warnings

[9 Apr 2008 15:28] Davi Arnaut
Description:
Although the manual says that "the list of messages is reset for each new statement that uses a table", the list of messages is being reset if parsing of a query fails. For example, if one has a list of warnings and sends a show warnings statement with a typo, the warnings are lost.

How to repeat:
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (a int);
--error ER_TABLE_EXISTS_ERROR
create table t1 (a int);
--error ER_PARSE_ERROR
syntax error;
# should show two errors
show count(*) errors;

Suggested fix:
Don't reset the list of message (errors, warnings and notes) on syntax errors.
[15 Apr 2008 1:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/45399

ChangeSet@1.2642, 2008-04-14 22:15:36-03:00, davi@mysql.com +65 -0
  Bug#35941 List of error, warning and note messages is lost due to syntax errors
  Bug#36004 mysql_stmt_prepare resets the list of warnings
    
  Although the manual says that "the list of messages is reset
  for each new statement that uses a table", the list of messages
  is being reset if parsing of a query fails. For example, if one
  has a list of warnings and sends a show warnings statement with
  a typo, the warnings are lost. The list of messages was also being
  reset for COM_STMT_PREPARE (mysql_stmt_prepare) commands which
  does not use tables.
    
  The solution is to enforce that the list of messages is reset
  for each new statement that uses a table. To properly track
  the per-statement warnings, the handling of the list of messages
  is moved to the diagnostics area which is now responsible for
  maintaining the list of messages.
  
  This patch touches a lot of test case because warnings
  generated during the parsing phase would wrongly
  remove warnings from previous statements. This was
  wrong because it's only possible to know if the statement
  uses a table after parsing.
[15 Apr 2008 19:32] Davi Arnaut
After diverse discussions we arrived at the decision that this not a bug and the confusion is due to the poor wording of the SHOW WARNINGS entry in the manual. I suggest that the first and second paragraphs could be changed to:

"SHOW WARNINGS shows the error, warning, and note messages that resulted from the last statement that generated messages. It shows nothing if the last statement used a table and generated no messages."

"Statements that don't use tables and don't generate messages have no effect on the message list."