Execute SQL from Aurelius

Hi,

It is possible to execute the following SQL using Aurelius?
"SELECT GEN_ID(GEN_CODIGOUSR,1) FROM rdb$database"

Thanks in advance,

Omar Zelaya

Hi, I'm not sure there is already a function for that, but you can easily implement one:

uses
  Aurelius.Drivers.Interfaces;

function GenId(const ASequenceName: string): Int64;
var
  AConn: IDBConnection;
begin
  AConn := **YourAureliusConnection**;
  with AConn.CreateStatement do
  begin
    SetSQLCommand(Format('SELECT GEN_ID(%s, 1) FROM rdb$database', [ASequenceName]));
    Result := ExecuteQuery.GetFieldValue(0);
  end;
end;

Than use it:

var
  NewId: Int64;
begin
  NewId := GenId('GEN_CODIGOUSR');

HTH

2 Likes