Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get sql statement when exception occurs

Status
Not open for further replies.

cselod

Programmer
Dec 18, 2009
2
RO
Hi, working with database when I get an error because of a wrong sql query I would like to save the SQL statement which caused the exception, using Delphi 7 and Firebird. How could I get it? thank you very much!
 
i usually use a ShowMessage(SQL.Text) before I run the query to make sure it's doing what I want....

Leslie
 
i usually show it in a TMemo before I run the query so I can tweak it if I need to....

Roo
Delphi Rules!
 
Thank you for your posts, I would need a general solution, because it's a big project with a lot of querys, i use a tool to catch the exception but i don't know how could I get the last sql statement which caused the exception
 
when you're debugging it should stop at the query that is causing the exception.

Leslie
 
I use a function to run my SQL. You could add some error trapping code and display the sSQL parameter value in the try..except block.

Code:
procedure TdmDB.RunGeneralQuery(sSQL: string; IsSelect: boolean = false);
begin
  with ADOQuery do
  begin
    close;
    sql.clear;
    sql.add(sSQL);

    if IsSelect then
      Open
    else
      ExecSQL;
  end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top