Bug #2653 Undeclared variables not detected in stored procedures
Submitted: 5 Feb 2004 9:05 Modified: 21 Jul 2004 14:55
Reporter: Per-Erik Martin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0 OS:Any (Any)
Assigned to: Per-Erik Martin CPU Architecture:Any

[5 Feb 2004 9:05] Per-Erik Martin
Description:
In some cases a reference to an undeclared variable is not detected, with
a server crash as a result.

How to repeat:
delimiter |;
create procedure foo(a int, out b int) set b = aa|
create procedure bar(a int, out b int)
begin
  if aa < 0 then
    set b = - a;
  else
    set b = a;
  end if;
end|
delimiter ;|
[20 May 2004 6:18] Stuart Clark
Not sure if this is exactly the same thing.  Ran a PHP web page that contained the incorrect syntax below:

$query_scalehold = sprintf("SELECT tblFigureScale.ID, tblFigureScale.fldScaleDesc FROM tblFigureScale WHERE tblFigureScale.ID=%s", $scaleid_mfr);

Had scaleid_mfr instead of $scaleid_mfr

 and the server appeared to lock up for several minutes, showing the message:

Fatal error: Maximum execution time of 60 seconds exceeded in Unknown on line 0

During this time any attempt to access the database failed.
[21 Jul 2004 14:55] Per-Erik Martin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

References to undeclared variables are now detected.
The fix is not perfect:
- It's only detected in run-time.
- The error message is somewhat misleading ("Unknown column in...")
...but at least it's not crashing.