Result of TUniSctipt (SQLite)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
m227
Posts: 75
Joined: Mon 06 Aug 2007 12:41

Result of TUniSctipt (SQLite)

Post by m227 » Thu 20 Aug 2020 12:35

Hi I have TUniScript (SQLite) like below:

Code: Select all

DROP TABLE IF EXISTS tmp;
CREATE TEMP TABLE tmp AS
WITH RECURSIVE
  tt(ID, ParentID, Name, AreaID, Symbol, Source, Path, SumUp, Static, USF, Address, Kind) AS (
    SELECT ID, NULL, Name, AreaID, Symbol, Source, Path, SumUp, Static, USF, Address, Kind
      FROM Scaff WHERE ID = &SrcID
    UNION
    SELECT t.ID, t.ParentID, t.Name, t.AreaID, t.Symbol, t.Source, t.Path, t.SumUp, t.Static, t.USF, t.Address, t.Kind
      FROM Scaff t
      JOIN tt ON t.ParentID = tt.ID
  ) SELECT * FROM tt;
DROP TABLE IF EXISTS var;
CREATE TEMP TABLE var (v1 INT);
INSERT INTO var (v1) 
  SELECT SEQ-MIN(tmp.ID)+1 FROM sqlite_sequence, tmp 
   WHERE sqlite_sequence.name = 'Scaff';
UPDATE tmp SET (ID, ParentID) = (SELECT ID + v1, ParentID + v1 FROM var);
UPDATE tmp SET ParentID = &DstID WHERE ParentID IS NULL; 
INSERT INTO Scaff (ID, ParentID, Name, AreaID, Symbol, Source, Path, SumUp, Static, USF, Address, Kind) 
     SELECT * FROM tmp;
UPDATE Scaff SET OrderFld = rowid * 10 WHERE OrderFld IS NULL;
SELECT ID FROM tmp LIMIT 1;
I want to retrieve value from last Select, my Delphi code is like:

Code: Select all

  usCopyNodeSingleDS.MacroByName('SrcID').AsInteger := 1;
  usCopyNodeSingleDS.MacroByName('DstID').AsInteger := 2;
  usCopyNodeSingleDS.Execute;
  AResult := usCopyNodeSingleDS.DataSet.Fields[0];
then I got AV as DataSet seems to be nil. How to use it then?

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Result of TUniSctipt (SQLite)

Post by MaximG » Mon 31 Aug 2020 12:58

You can use the UniScript.Dataset property to specify the dataset which will hold the result of a SELECT statement:

Code: Select all

var
  UniQuery: TUniQuery;
...
usCopyNodeSingleDS.DataSet := UniQuery;
usCopyNodeSingleDS.Execute;
...

Post Reply