Page 1 of 1

Result of TUniSctipt (SQLite)

Posted: Thu 20 Aug 2020 12:35
by m227
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?

Re: Result of TUniSctipt (SQLite)

Posted: Mon 31 Aug 2020 12:58
by MaximG
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;
...