Icon View Incident Report

Minor Minor
Reported By: Peter
Reported On: 3/20/2013
For: Version 2.12 Build 2
# 3818 TEDBScript Can Cause AV When Using WITH RETURN for Statement That Does Not Return a Cursor

I am having problems with the TEDBScript component. I use it to run a script that creates an in-memory table, and that process has just started giving an AV in the TEDBScript.CreateCursor area. I recently updated to 2.12 Build 1, then Build 2.

As far as I can tell, it is not the fault of the script, or the SQL that the script uses to create the in-memory table, as both of those work perfectly in EDBManager; together and separately.

I recently moved away from having the engine created on the fly to a TEDBEngine component in a DataModule, but apart from that I can't imagine what other change is causing the AV. MadExcept tells me that it is in edbcomps in TEDBScript.CreateCursor, but apart from that I can't suggest what it might be.

SCRIPT (IN SQLStatement VARCHAR, IN TableName VARCHAR, IN AddBool BOOLEAN)
BEGIN
DECLARE InfoCursor SENSITIVE CURSOR FOR InfoStmt;
DECLARE ResultCursor SENSITIVE CURSOR WITH RETURN FOR ResultStmt;
PREPARE InfoStmt FROM 'SELECT * FROM Information.Tables WHERE Name=?';
OPEN InfoCursor USING TableName;
IF (ROWCOUNT(InfoCursor) > 0) THEN
 EXECUTE IMMEDIATE 'DROP TABLE "'+TableName+'"';
END IF;
CLOSE InfoCursor;
PREPARE ResultStmt FROM 'CREATE TABLE "' + TableName + '" AS ' + SQLStatement + ' WITH DATA';
EXECUTE ResultStmt;
IF AddBool THEN
 EXECUTE IMMEDIATE 'ALTER TABLE "'+TableName+'" ADD COLUMN "SelRow" BOOLEAN DEFAULT %s';
 END IF;
END

and the parameters are:
TableName = InMemOne
AddBool = False
SQLStatement = SELECT * FROM PlanB.Client WHERE ClientID = 1

The Delphi XE3 code is:
...
var aScript: TEDBScript;
begin
aScript := TEDBScript.Create(nil);
try
 aScript.SessionName  := DM.EDBDatabase1.SessionName;
 aScript.DatabaseName := INMEMDB; 
 aScript.SQL.Add(Format(SQLSCR, [GetTF_YNStr(False, BoolVal)]));
 aScript.Prepare;
 aScript.ParamByName('SQLStatement').AsString := SSQL;
 aScript.ParamByName('TableName').AsString    := STableName;
 aScript.ParamByName('AddBool').AsBoolean     := UsesBool;
 try
  aScript.ExecScript;
 except
  raise;
 end;
finally
 aScript.Free;
end;



Comments Comments and Workarounds
The workaround is to remove the WITH RETURN clause in the ResultCursor declaration.


Resolution Resolution
Fixed Problem on 3/20/2013 in version 2.13 build 1


Products Affected Products Affected
ElevateDB Additional Software and Utilities
ElevateDB DAC Client-Server
ElevateDB DAC Client-Server with Source
ElevateDB DAC Standard
ElevateDB DAC Standard with Source
ElevateDB DAC Trial
ElevateDB LCL Standard with Source
ElevateDB PHP Standard
ElevateDB PHP Standard with Source
ElevateDB PHP Trial
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image