I saw that... it "works" but don't like the way it formats the data.
VAR qInventory : tadoquery;
..
aDBXReader := TDBXDataSetReader.Create (qInventory, False );
result := TDBXJSONTools.TableToJSON (aDBXReader, qInventory.RecordCount , False);
..
What it does is break it up into columns...
So if got 5 columns of data, with 100 records.
It will output 5 nodes in the json... each with 100 records in it.
Way I need it to be broken up is 100 nodes..... (each row) ... with the 5 columns of data in it.
That way the end user can look at record 1 ... and pull out any of the 5 columns easily.
Using FireDac it does this... but its a bit clunky on its break out of the data... but does work.... but more complex to
do and bit clunky on the output...
var qData : TFDQuery;
Connection: TFDConnection;
fStream : tstringstream;
FDStanStorageJSONLink1: TFDStanStorageJSONLink;
begin
FDStanStorageJSONLink1:= TFDStanStorageJSONLink.Create(nil);
Connection := TFDConnection.Create(nil);
Connection.Params.AddPair('DriverID','ODBC');
Connection.Params.AddPair('DataSource','MyDB1');
Connection.LoginPrompt := false;
qData := TFDQuery.Create(nil);
qData.Connection := Connection;
qData.SQL.Text := mySQLstr;
qData.Open;
fStream := tstringstream.Create;
qData.SaveToStream(fStream,tfdstorageformat.sfJSON);
fStream.Position := 0;
result := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(fStream.DataString),0) as TJSONObject;
freeandnil(FDStanStorageJSONLink1);
freeandnil(qData);
freeandnil(fStream);
freeandnil(connection);
end;
Edited by: steven chesser on Jul 6, 2016 8:30 AM
Connect with Us