unit uDatabaseUtils;

interface

function GetNextAutoInc(const GeneratorName: String): Integer;

function HayClausulaWhere (aSQL: String): Boolean;

implementation

uses
  SysUtils,
  uDADataTable, uDAClasses, uDAInterfaces,
  uDataModuleServer;

function GetNextAutoInc(const GeneratorName: String): Integer;
var
  vConn : IDAConnection;
  ds: IDADataset;
begin
  vConn := dmServer.ConnectionManager.NewConnection(dmServer.ConnectionName);
  vConn.BeginTransaction;
  try
    ds := vConn.NewDataset(Format('SELECT GEN_ID(%s,1) FROM RDB$Database', [GeneratorName]));
    ds.Open;
    Result := ds.Fields[0].AsInteger;
  finally
    vConn.CommitTransaction;
    ds := NIL;
  end;
end;

function HayClausulaWhere (aSQL: String): Boolean;
begin
  Result := (Pos('WHERE', UpperCase(aSQL)) > 0);
end;


end.
