Don't forget about ExecuteScalar

Posted: (EET/GMT+2)

 

I guess my Wednesday post was made too late in the day for I had totally forgotten that I don't need to use a DataReader when I'm only reading a single value from an SQL query. Duh.

Naturally, the easy to do such a thing (like reading a generator value) is to use the ExecuteScalar method:

Try
    SQLQuery := Borland.Data.Provider.BdpCommand.Create();
    SQLQuery.CommandText := 'SELECT GEN_ID('+GeneratorName+',1) FROM RDB$DATABASE';
    SQLQuery.Connection := Borland.Data.Provider.BdpConnection(IBTrans.Connection);
    Result := System.Int32(SQLQuery.ExecuteScalar());
  Finally
    ...
  End;

Now, who said the returned generator value was a System.Decimal? Not anymore, it seems! Humans learn by doing...