How to find the response of a simple atomic Query?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
marc_3
Posts: 6
Joined: Thu 10 Mar 2016 11:19

How to find the response of a simple atomic Query?

Post by marc_3 » Thu 10 Mar 2016 12:18

Hello,

I'm trying to to use UniQuery and I just need to select the last current Index from a database.

This is what I would like to do :

Code: Select all

if sql_UniQuery.Connection.Connected
      then begin
           sql_UniQuery.SQL.Text := 'SELECT MAX(TW_LEG_ID)FROM TW_LEG;';
           sql_UniQuery.Execute;


           id := sql_UniQuery.FieldByName('TW_LEG_ID').AsInteger; // I don't find a way to have the result                    

I know already that the connection work because I have been able to do the following update :
sql_UniQuery.SQL.Text := 'UPDATE TW_LEG SET AIRLINE_CD = ''AA'' WHERE TW_LEG_ID = 2;';
I don't find a way to have the result from the query back. I just want to have the ID that is an Integer
Does exists a simple way to have it directly through the UniQuery and how to do it?


Thanks for helping

BG

Marc_3

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: How to find the response of a simple atomic Query?

Post by azyk » Thu 10 Mar 2016 13:16

In the provided sample you are trying to retrieve a field named TW_LEG_ID. But there is no field with such name in the SELECT query. To retrieve the query execution result, you can call the field by index:

Code: Select all

  sql_UniQuery.SQL.Text := 'SELECT MAX(TW_LEG_ID) FROM TW_LEG;';
  sql_UniQuery.Execute;
  id := sql_UniQuery.Fields[0].AsInteger;
Or set an alias for the MAX() function in the SELECT query, in order to call the field by alias name:

Code: Select all

  sql_UniQuery.SQL.Text := 'SELECT MAX(TW_LEG_ID) AS TW_LEG_ID FROM TW_LEG;';
  sql_UniQuery.Execute;
  id := sql_UniQuery.FieldByName('TW_LEG_ID').AsInteger;

marc_3
Posts: 6
Joined: Thu 10 Mar 2016 11:19

Re: How to find the response of a simple atomic Query?

Post by marc_3 » Fri 11 Mar 2016 06:43

Thanks for the answer, it helps much

BG

Post Reply