Search code examples
delphifirebirddbexpress

How to change generator value with dbExpress framework whithout using stored procedures?


How to change a generator value with dbExpress framework? I want to change generator value directly with dbExpress, without writing a stored procedure in RDBMS side or etc. Please help me for doing that.


Solution

  • AFAIK DBExpress don't have any class specialized in dealing with sequences/generators.

    You still can use a standard TSQLQuery to instruct the dbEngine to alter a generator value, like this:

    procedure TMyDataModule.RestartMyGenerator;
    begin
      Q := TSQLQuery.Create;
      try
        Q.SQLConnection := MyConnection;
        //compatible with firebird 1.x and 2.x
        //Q.SQL.Text := 'set generator mygenerator to 0';  
        //better alternative, but compatible only with firebird 2.x
        Q.SQL.Text := 'alter sequence mygenerator restart with 0';
        Q.ExecSQL;
      finally
        Q.Free;
      end;
    end;
    

    (untested code, written directly in this window)