0

Can someone help me and explain to my why this code crashes on the ExecSQL statement?

function UpdateLastBankResponsesId(ADatabase: TDatabase; AValue: Integer): String;  
var  
AQuery2: TQuery;  
begin 
result:= ''; 
AQuery2:= TQuery.Create(nil); 
AQuery2.DatabaseName:= ADatabase.DatabaseName;  
with AQuery2 do  
begin  
SQL.Text:= 'UPDATE last_id Set TABLENAME =:ATableName, LASTID=:ALastId';  
ParamByName('ATableName').AsString:= 'responses';  
ParamByName('ALastId').AsInteger:= AValue;  
try  
ExecSql; //***** CRASHES HERE *****  
except  
begin  
ExitCode:= 16;  
raise ECustomException.create('Error Updating Last Id table!');  
end;//except  
end; //try  
end; //with  
AQuery2.Free;  
end;  
RRUZ
  • 134,889
  • 20
  • 356
  • 483
IElite
  • 1,818
  • 9
  • 39
  • 64

1 Answers1

0

I was trying to set a value that already existed

Set TABLENAME =:ATableName  

I actually only needed to set the LASTID

UPDATE last_id SET LASTID=:ALastId WHERE TABLENAME =:ATableName  

I can't believe I did that

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
IElite
  • 1,818
  • 9
  • 39
  • 64