Page 1 of 1

INSERT can be executed with open?

Posted: Wed 19 Jan 2011 08:51
by dust258
Hi,

I'm working on a small module in my application, witch enables the user to edit SQL-Statements (only SELECT).

When TIBCQuery.open is called, the resulting list is displayed in a TDBGrid.
The problem is, that the user can use INSERT or UPDATE-Statements to manipulate the Data.

After the call of an INSERT-Statement (with open), an exception is raised (no Data in the Database).
But with the next Execute-Statement (witch I call in the on-close of the Form), the failed INSERT-Statements also gets executed (and the Data inserted into the Database).

EDIT: I'm workin with Delphi 2007 and Version 6.90.0.60

Posted: Wed 19 Jan 2011 09:10
by dust258
Hmmm, found something:

Code: Select all

  try
    query.Open;
  except
    on e : Exception do
    begin
      query.Transaction.Rollback;
      MessageDLG(e.Message,mtError,[mbOK],0);
    end;
  end;
This fixes my problem, but is there an option for this?

Posted: Wed 19 Jan 2011 14:32
by AndreyZ
Hello,

You shouldn't execute Insert statements using the Open method. If you want to execute Insert, Update, and Select statements in the same way, you should use the Execute method. If SQL statement is a query, Execute calls the Open method.

Posted: Wed 19 Jan 2011 14:33
by AndreyZ
We will fix the problem with active transaction in one of the next builds.