#1 2022-11-20 03:08:28

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Can ISQLDBStatement be reused?

@ab,

In situations like in a loop, can `ISQLDBStatement` be reused? Or do I have to get a new instance via `NewThreadSafeStatementPrepared` before calling `Bind*` and `Step` in the loop?

By 'in a loop' I mean something like following:

var
  stmt: ISQLDBStatement;
begin
  stmt := FDatabase.NewThreadSafeStatementPrepared('update...', False);
  for i := 0 to 10 do
  begin
    stmt.Bind(0, i);
    stmt.Step;
    stmt.Reset; // possible?
  end;
end;

Does mORMot has a something like Reset method for ISQLDBStatement? Or do I have to call `NewThreadSafeStatementPrepared` to get a new instance in the for loop?


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2022-11-20 03:17:47

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Can ISQLDBStatement be reused?

Update 1: I just checked `TSQLDBConnection.NewThreadSafeStatementPrepared`, it seems that caching of the statement objects are already taking into account, so calling NewThreadSafeStatementPrepared is already very optimal, no need of things like `Reset` as I suggested in the OP? big_smile

Last edited by edwinsn (2022-11-20 03:27:23)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB