Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Prepared statements in Delphi
Tue, Apr 21 2009 8:01 AMPermanent Link

Jon Lennart Aasenden
I have several quite simple sql statements that are executed hundreds or thousands of times in my application.
I figured I could speed things up a bit by preparing the insert/update queries, but im unsure what happens after they are executed.

For excample:

I have a query object (created from code) that is setup like this:

     if MakeQueryObj(FMarkQuery) then
     Begin
       FMarkQuery.sql.add('UPDATE JTFiles SET state=:P_state where id=:P_id');
       FMarkQuery.Prepare;
     end else
     Raise Exception.Create('Failed to create query object error');

The makequeryobj() function just created an instance of TEDBQuery and sets the session and database name automatically.
The above query is then used as such:

         With FMarkQuery do
         Begin
           ParamByName('P_state').AsInteger:=ord(newstate);
           ParamByName('P_id').AsInteger:=id;
           ExecSQL;
         end;

My question is, if I add the line:

FMarkQuery.active:=False;

..afterwards, does this unprepare the query? If I leave it as it - is the target record locked until the next call?
Tue, Apr 21 2009 11:22 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Jon,

> .afterwards, does this unprepare the query?

No.
If you explicitly prepare a query you must also explicitly unprepare it.

If I leave it as it - is the target record locked until the next call?

No.
Rows remain locked only during the update operation and are automatically
unlocked after the update, unless the lock occurs inside a transaction - row
locks acquired during a transaction remain until the transaction is committed.

--
Fernando Dias
[Team Elevate]
Image