[MDEV-4943] Error 1758 doesnt have a SQLSTATE? Created: 2013-08-24  Updated: 2022-09-12  Resolved: 2022-09-12

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0.4
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Federico Razzoli Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: upstream


 Description   

This is a MySQL bug, but as you know I prefer not to give lots of my personal data to Oracle.

As far as I can tell, error 1758 seems to have not a SQLSTATE:

MariaDB [(none)]> \W
Show warnings enabled.
MariaDB [(none)]> GET DIAGNOSTICS CONDITION 0 @a = MYSQL_ERRNO;
Query OK, 0 rows affected, 1 warning (0.10 sec)
 
Error (Code 1758): Invalid condition number

From the documentation, SQLSTATE should be '35000':
http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html

This causes some trivial problems:

  • DECLARE HANDLER FOR '35000' doesnt handle it
  • Same for SQLEXCEPTION and other classes
  • mysqld reports it as a warning, not an error (see above)


 Comments   
Comment by Elena Stepanova [ 2013-08-26 ]

Hi Federico,

Could you please help me understand how your example shows that there is no SQLSTATE for 1758? From what I see, it's there all right:

MariaDB [test]> \W
Show warnings enabled.
MariaDB [test]> GET DIAGNOSTICS CONDITION 0 @a = MYSQL_ERRNO ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
Error (Code 1758): Invalid condition number
MariaDB [test]> GET DIAGNOSTICS CONDITION 1 @a = MYSQL_ERRNO, @b = RETURNED_SQLSTATE ;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> SELECT @a, @b;
+------+-------+
| @a   | @b    |
+------+-------+
| 1758 | 35000 |
+------+-------+
1 row in set (0.00 sec)

Reporting it as a warning rather than an error is apparently intentional, at least it's documented (http://dev.mysql.com/doc/refman/5.6/en/get-diagnostics.html):
"A warning occurs if the condition number is not in the range from 1 to the number of condition areas that have information. In this case, the warning is added to the diagnostics area without clearing it."

The fact that it's not handled by a handler is another story. I'd think it's not because of the SQLSTATE, it looks like the warning somehow gets lost (suppressed?) if it happens inside a procedure:

MariaDB [test]> drop procedure if exists p;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> delimiter ||
MariaDB [test]> create procedure p()
    -> begin
    -> GET DIAGNOSTICS CONDITION 0 @a = MYSQL_ERRNO ;
    -> end ||
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> delimiter ;
MariaDB [test]> 
MariaDB [test]> call p();
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> 

(no warning caused by the procedure call).

I'm not quite sure if it's a bug or not (haven't found it in the documentation yet), if you think it is, we might try to create a bug report at Oracle and see what they say.

Comment by Federico Razzoli [ 2013-08-26 ]

My hypotesys (no SQLSTATE) seems to be wrong, but what I find strange is that:

  • The client doesn't display an SQLSTATE (only error code)
  • While it's reported as a warning, SHOW WARNINGS tells it's an error (see Level column). (As far as I understand, only '01...' SQLSTATEs indicate a warning?)
  • About the HANDLER, you seem to be totally right, but I don't know of other errors which are suppressed inside stored procedures

These facts surprised me, so I wanted to report that (in my opinion) there is something strange. If it isn't a bug, or you think it's totally unimportant, please ignore this report.

Comment by Elena Stepanova [ 2013-09-16 ]

Hi Federico,

Sorry for the delay.
Not displaying an SQLSTATE is usual for warnings:

MariaDB [test]> drop table if exists nonexisting;
Query OK, 0 rows affected, 1 warning (0.01 sec)

Note (Code 1051): Unknown table 'test.nonexisting'

The warning of Level error does look weird, I asked for Serg's consult on this. If he reckons it to be a bug, we'll file it at MySQL and see what they say, and will proceed from there.

Comment by Elena Stepanova [ 2013-09-16 ]

Filed as http://bugs.mysql.com/bug.php?id=70358

Comment by Federico Razzoli [ 2014-06-24 ]

My conclusion that it doesn't have an SQLSTATE was wrong. The problem was that I couldn't handle that error in any way.

Here's the story of how I discovered this bug. I wrote a procedure to copy the diagnostics area into a table. There is no easy way to do this, so I loop through the conditions and used MYSQL_ERRNO, etc, to compose a prepared statement INSERT. In the initial version, I thought I could exit from the loop when this warning occurs (DECLARE HANDLER ... LEAVE `this_loop`), but this never happened.

The workaround was easy. So... I guess it's up to you decide if this is a bug.

Comment by Federico Razzoli [ 2014-06-24 ]

Curiously, I've noted that this warning is written in the SQL_ERROR_LOG. But other warnings I tried are not logged.

Comment by Daniel Black [ 2017-12-30 ]

FWIW - 10.3.4.

 
MariaDB [test]> \W
Show warnings enabled.
MariaDB [test]> GET DIAGNOSTICS CONDITION 0 @a = MYSQL_ERRNO;
Query OK, 0 rows affected, 1 warning (0.000 sec)
 
Note (Code 1305): PROCEDURE test.p does not exist
Error (Code 1758): Invalid condition number
Error (Code 1758): Invalid condition number
MariaDB [test]> SHOW WARNINGS;
+-------+------+---------------------------------+
| Level | Code | Message                         |
+-------+------+---------------------------------+
| Note  | 1305 | PROCEDURE test.p does not exist |
| Error | 1758 | Invalid condition number        |
| Error | 1758 | Invalid condition number        |
+-------+------+---------------------------------+
3 rows in set (0.000 sec)
 
MariaDB [test]> 
MariaDB [test]> drop procedure if exists p; 
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> delimiter || 
MariaDB [test]> create procedure p() 
    -> begin 
    ->   GET DIAGNOSTICS CONDITION 0 @a = MYSQL_ERRNO ; 
    -> end || 
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> delimiter ; 
MariaDB [test]> 
MariaDB [test]> call p();
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> show warnings;
+-------+------+---------------------------------+
| Level | Code | Message                         |
+-------+------+---------------------------------+
| Note  | 1305 | PROCEDURE test.p does not exist |
| Error | 1758 | Invalid condition number        |
| Error | 1758 | Invalid condition number        |
+-------+------+---------------------------------+
3 rows in set (0.000 sec)
 
MariaDB [test]> SELECT VERSION();
+----------------+
| VERSION()      |
+----------------+
| 10.3.4-MariaDB |
+----------------+
1 row in set (0.000 sec)
 

Comment by Sergei Golubchik [ 2022-09-12 ]

10.0 was EOLed in March 2019

Generated at Thu Feb 08 07:00:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.