#1 2015-09-14 11:25:28

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Strange behavior of "GetJSONValues"

Hi all

After last update, I detected strange behavior on UPDATE operation

I write data to one field with name "Otchety_termo0", but in result, I see data in many fields of database.

{
   "IDZakaza":1,
   "IDTipoisp":1,
   "SerNomer":"",
   "Otchety_nastrk":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
   "Otchety_termo0":"{\"Href\":\"\",\"Report\":\"<html></html>\",\"Result\":\"Success\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo8":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo16":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo24":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo36":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo48":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_termo72":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_Koeff":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_HtmKoeff":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",
   "Otchety_Test":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}"
}

This is my TEST code model, server and client for repeat situation

MODEL

unit uModel;

interface
uses
  Classes, SynCommons,  mORMot,  mORMotHttpServer;

type
  TDateTermoprAll = (NoTest, Nastrk, Termo0, Termo8, Termo16, Termo24, Termo36, Termo48, Termo72, KoeffDSP, KoeffHTML, Test);
  TDateTermopr = Nastrk..Test;

const
//  Data name Blob field in DB
  strDateTermopr : array[TDateTermopr] of ShortString = ('Otchety_nastrk', 'Otchety_termo0', 'Otchety_termo8',
                                                         'Otchety_termo16','Otchety_termo24','Otchety_termo36',
                                                         'Otchety_termo48','Otchety_termo72','Otchety_Koeff','Otchety_HtmKoeff','Otchety_Test');
type
  /// here we declare the class containing the data
  // - it just has to inherits from TSQLRecord, and the published
  // properties will be used for the ORM (and all SQL creation)
  // - the beginning of the class name must be 'TSQL' for proper table naming
  // in client/server environnment

    TDataReport = class(TPersistent)
    private
      fHref     : RawUTF8;
      fReport   : RawUTF8;
      fResult   : RawUTF8;
      fDateTest : RawUTF8;
    public
      procedure Clear;
    published
      property Href     : RawUTF8       read fHref         write fHref;
      property Report   : RawUTF8       read fReport       write fReport;
      property Result   : RawUTF8       read fResult       write fResult;
      property DateTest : RawUTF8       read fDateTest     write fDateTest;
    end;

  TSQLRecordZakaz = class(TSQLRecord)
  private
    fNomerZakaza      : RawUTF8;
    fZakazchik        : RawUTF8;
    fVypolnen         : Boolean;
    FTimeVypoln       : TDateTime;
  published
    property NomerZakaza      : RawUTF8     read fNomerZakaza       write fNomerZakaza;
    property Zakazchik        : RawUTF8     read fZakazchik         write fZakazchik;
    property Vypolnen         : Boolean     read fVypolnen          write fVypolnen;
    property TimeVypoln       : TDateTime   read FTimeVypoln        write FTimeVypoln;
  end;

  TSQLRecordTip = class(TSQLRecord)
  private
    fNameTipoisp          : RawUTF8;
  published
    property NameTipoisp          : RawUTF8           read fNameTipoisp           write fNameTipoisp;
  end;

  TSQLRecordDevice = class(TSQLRecord)
  private
    fIDZakaza         : TSQLRecordZakaz;
    fIDTipoisp        : TSQLRecordTip;
    fSerNomer         : RawUTF8;

    fOtchety_nastrk     : TDataReport;
    fOtchety_termo0     : TDataReport;
    fOtchety_termo8     : TDataReport;
    fOtchety_termo16    : TDataReport;
    fOtchety_termo24    : TDataReport;
    fOtchety_termo36    : TDataReport;
    fOtchety_termo48    : TDataReport;
    fOtchety_termo72    : TDataReport;
    fOtchety_Koeff      : TDataReport;
    fOtchety_HtmKoeff   : TDataReport;
    fOtchety_Test       : TDataReport;
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property IDZakaza         : TSQLRecordZakaz   read fIDZakaza          write fIDZakaza;
    property IDTipoisp        : TSQLRecordTip     read fIDTipoisp         write fIDTipoisp;
    property SerNomer         : RawUTF8           read fSerNomer          write fSerNomer;

    property Otchety_nastrk     : TDataReport read fOtchety_nastrk  write fOtchety_nastrk;
    property Otchety_termo0     : TDataReport read fOtchety_termo0  write fOtchety_termo0;
    property Otchety_termo8     : TDataReport read fOtchety_termo8  write fOtchety_termo8;
    property Otchety_termo16    : TDataReport read fOtchety_termo16 write fOtchety_termo16;
    property Otchety_termo24    : TDataReport read fOtchety_termo24 write fOtchety_termo24;
    property Otchety_termo36    : TDataReport read fOtchety_termo36 write fOtchety_termo36;
    property Otchety_termo48    : TDataReport read fOtchety_termo48 write fOtchety_termo48;
    property Otchety_termo72    : TDataReport read fOtchety_termo72 write fOtchety_termo72;
    property Otchety_Koeff      : TDataReport read fOtchety_Koeff   write fOtchety_Koeff;
    property Otchety_HtmKoeff   : TDataReport read fOtchety_HtmKoeff write fOtchety_HtmKoeff;
    property Otchety_Test       : TDataReport read fOtchety_Test    write fOtchety_Test;
  end;

/// an easy way to create a database model for client and server
function CreateSampleModel: TSQLModel;

var Model:TSQLModel;
    Database:TSQLRest;
    Server: TSQLHttpServer;
    
implementation

function CreateSampleModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLRecordZakaz,TSQLRecordTip,TSQLRecordDevice]);
end;

{ TSQLRecordDevice }

constructor TSQLRecordDevice.Create;
begin
  inherited;
  fOtchety_nastrk:=TDataReport.Create;
  fOtchety_termo0:=TDataReport.Create;
  fOtchety_termo8:=TDataReport.Create;
  fOtchety_termo16:=TDataReport.Create;
  fOtchety_termo24:=TDataReport.Create;
  fOtchety_termo36:=TDataReport.Create;
  fOtchety_termo48:=TDataReport.Create;
  fOtchety_termo72:=TDataReport.Create;
  fOtchety_Koeff:=TDataReport.Create;
  fOtchety_HtmKoeff:=TDataReport.Create;
  fOtchety_Test:=TDataReport.Create;
end;

destructor TSQLRecordDevice.Destroy;
begin
  fOtchety_nastrk.Free;
  fOtchety_termo0.Free;
  fOtchety_termo8.Free;
  fOtchety_termo16.Free;
  fOtchety_termo24.Free;
  fOtchety_termo36.Free;
  fOtchety_termo48.Free;
  fOtchety_termo72.Free;
  fOtchety_Koeff.Free;
  fOtchety_HtmKoeff.Free;
  fOtchety_Test.Free;
  inherited;
end;

{ TDataOtchet }

procedure TDataReport.Clear;
begin
  fHref:='';
  fReport:='';
  fResult:='';
  fDateTest:='';
end;

end.

SERVER

program pServer;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  mORMot,
  SynSQlite3,
  DB,
  SynDBVCL,
  SynDBSQLite3,
  SynDB,
  SynSQlite3Static,
  mORMotSQLite3,
  mORMotHttpServer,
  Classes,
  Forms,
  uModel in 'uModel.pas';

begin
  Model := CreateSampleModel;
  try
    Database := TSQLRestServerDB.Create(Model, ChangeFileExt(Application.ExeName,'.db'));
    if not Assigned(Database) then raise Exception.Create('Error connect or create db');
    try
      TSQLRestServerDB(Database).CreateMissingTables(0);
      TSQLRestServerDB(Database).NoAJAXJSON:=False;

      Server := TSQLHttpServer.Create('777',[TSQLRestServerDB(Database)],'+',{useHttpSocket}useHttpApiRegisteringURI,32,secNone,'report');
      Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries

      write('Press [Enter] to close the server.');
      Readln;
    finally
      Database.Free;
    end;
  finally
    Model.Free;
  end;
end.

CLIENT

program pClient;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  StrUtils,
  SynCommons,
  mORMot,
  mORMotSQLite3,
  mORMotHttpClient,
  uModel;


procedure CreateRecordDB(sNomerZakaza,stipoisp:string;var iId_BD:TID);
var
  RecordOrder: TSQLRecordZakaz;RecordTip: TSQLRecordTip; RecordDevice: TSQLRecordDevice;
  iId_Order,iId_Tip: integer;
  s:string;
begin
  s:=Database.OneFieldValue(Model['Zakaz'],'ID',Format('NOMERZAKAZA=''%s''',[StringToUTF8(sNomerZakaza)]));
  if not TryStrToInt(s,iId_Order) then
  begin
    RecordOrder:=TSQLRecordZakaz.Create;
    try
      RecordOrder.NomerZakaza:=StringToUTF8(sNomerZakaza);
      RecordOrder.Vypolnen:=False;
      iId_Order := Database.Add(RecordOrder,true);
    finally
      RecordOrder.Free;
    end;
  end else
  begin
    RecordOrder:=TSQLRecordZakaz.Create(DataBase,iId_Order);
    RecordOrder.Vypolnen:=False;
    DataBase.Update(RecordOrder);
  end;

  s:=Database.OneFieldValue(Model['Tip'],'ID',Format('NAMETIPOISP=''%s''',[StringToUTF8(stipoisp)]));
  if not TryStrToInt(s,iId_Tip) then
  begin
    RecordTip:=TSQLRecordTip.Create;
    try
      RecordTip.NameTipoisp:=StringToUTF8(stipoisp);
      iId_Tip := Database.Add(RecordTip,true);
    finally
      RecordTip.Free;
    end;
  end;

  RecordDevice:=TSQLRecordDevice.Create;
  try
    RecordDevice.IDZakaza:=TSQLRecordZakaz(iId_Order);
    RecordDevice.IDTipoisp:=TSQLRecordTip(iId_Tip);
    iId_BD := Database.Add(RecordDevice,true);
  finally
    RecordDevice.Free;
  end;
end;

procedure LoadProtocolToDB(iId_BD:TID;aHTMLString: string; isProverkaSuccess: Boolean; dt: TDateTermoprAll);
var
  rec:TSQLRecordDevice;
  procedure AssignToOtchet(ADataReport:TDataReport);
  begin
    ADataReport.Href:='';// StringToUTF8(dt.sHref);
    ADataReport.Report:=aHTMLString;
    ADataReport.Result:=ifthen(isProverkaSuccess,'Success','Errors');
    ADataReport.DateTest:=DateTimeToStr(Now);
  end;
begin
  if (iId_BD=0) or (aHTMLString='') then Exit;

  rec:=TSQLRecordDevice.Create(Database,iId_BD);
  try
    case dt of
      Nastrk: AssignToOtchet(Rec.Otchety_nastrk);
      Termo0: AssignToOtchet(Rec.Otchety_termo0);
      Termo8: AssignToOtchet(Rec.Otchety_termo8);
      Termo16: AssignToOtchet(Rec.Otchety_termo16);
      Termo24: AssignToOtchet(Rec.Otchety_termo24);
      Termo36: AssignToOtchet(Rec.Otchety_termo36);
      Termo48: AssignToOtchet(Rec.Otchety_termo48);
      Termo72: AssignToOtchet(Rec.Otchety_termo72);
      Test: AssignToOtchet(Rec.Otchety_Test);

      KoeffDSP: AssignToOtchet(Rec.Otchety_Koeff);
      KoeffHTML: AssignToOtchet(Rec.Otchety_HtmKoeff);
    end;
    Database.Update(rec);
  finally
    Rec.free;
  end;
end;

var iId_BD:TID;
begin
  Model := CreateSampleModel;
  try
    Database := TSQLHttpClient.Create('localhost', '777',Model);
    try
      write('Press [Enter] to close the client.');
      CreateRecordDB('123','BE',iId_BD);
      LoadProtocolToDB(iId_BD,'<html></html>',true,Termo0);
      Readln;
    finally
      Database.Free;
    end;
  finally
    Model.Free;
  end;
end.

Offline

#2 2015-09-14 11:45:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Strange behavior of "GetJSONValues"

Please check http://synopse.info/forum/viewtopic.php … 686#p17686

Nested objects are stored as JSON objects, as TEXT in the database.
So if you retrieve directly the JSON from the DB, the nested objects are retrieved as a JSON string.

From a regular Delphi client, all this is automatically handled.

What is your exact issue?

Online

#3 2015-09-14 12:01:07

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

before update all worked ok

I writed new data to field "Otchety_termo0" and when I did update database, data writed

But now, when I write  field "Otchety_termo0" and update database then I see that data writed to other fields record and moreover its broken
for example: "Otchety_termo8":"{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"14.09.2015 14:21:06\"}",

Offline

#4 2015-09-14 12:39:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Strange behavior of "GetJSONValues"

Please try latest version.

Especially http://synopse.info/fossil/info/a372ca2b78

Online

#5 2015-09-14 13:17:04

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

i can not compile

appear error : too many actual parameters in row Call.OutBody := rec.GetJSONValues(true,true,soSelect,nil,true);

Offline

#6 2015-09-14 13:26:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Strange behavior of "GetJSONValues"

Are you sure your source folder is in synch?

I'm not able to reproduce the issue here.

Online

#7 2015-09-15 05:34:05

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

I took source from http://synopse.info/files/mORMotNightlyBuild.zip yesterday. I had to take in GitHub.

Today mORMotNightlyBuild.zip have been changed for actual version. I could to compile it.

But it doesn't help.

I saw in debug when execute inside function GetJSONValues(W: TJSONSerializer) adding colnames "Otchety_nastrk" immediately added rest colnames: Otchety_termo0... Otchety_Test. Is it ok?.

winXP, Delphi 2006

Last edited by Alek (2015-09-15 05:45:15)

Offline

#8 2015-09-21 11:12:30

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

Today tried to compile my example with Delphi XE2 and the same bad result

Offline

#9 2015-09-28 13:46:00

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

Anybody help, compile this code and look to the file "pserver.db.json", it is wrong, how i writed above

program pServer;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  StrUtils,
  SynCommons,
  mORMot,
  SynSQlite3Static,
  mORMotSQLite3,
  Classes,
  Forms;

var Model:TSQLModel;
    Database:TSQLRest;
    iId_BD:TID;


{------------------------------------------------------------------------------
 Model
 ------------------------------------------------------------------------------}


type
  TDateTermoprAll = (NoTest, Nastrk, Termo0, Termo8, Termo16, Termo24, Termo36, Termo48, Termo72, KoeffDSP, KoeffHTML, Test);
  TDateTermopr = Nastrk..Test;

const
//  Data name Blob field in DB
  strDateTermopr : array[TDateTermopr] of ShortString = ('Otchety_nastrk', 'Otchety_termo0', 'Otchety_termo8',
                                                         'Otchety_termo16','Otchety_termo24','Otchety_termo36',
                                                         'Otchety_termo48','Otchety_termo72','Otchety_Koeff','Otchety_HtmKoeff','Otchety_Test');
type
  /// here we declare the class containing the data
  // - it just has to inherits from TSQLRecord, and the published
  // properties will be used for the ORM (and all SQL creation)
  // - the beginning of the class name must be 'TSQL' for proper table naming
  // in client/server environnment

    TDataReport = class(TPersistent)
    private
      fHref     : RawUTF8;
      fReport   : RawUTF8;
      fResult   : RawUTF8;
      fDateTest : RawUTF8;
    public
      procedure Clear;
    published
      property Href     : RawUTF8       read fHref         write fHref;
      property Report   : RawUTF8       read fReport       write fReport;
      property Result   : RawUTF8       read fResult       write fResult;
      property DateTest : RawUTF8       read fDateTest     write fDateTest;
    end;

  TSQLRecordZakaz = class(TSQLRecord)
  private
    fNomerZakaza      : RawUTF8;
    fZakazchik        : RawUTF8;
    fVypolnen         : Boolean;
    FTimeVypoln       : TDateTime;
  published
    property NomerZakaza      : RawUTF8     read fNomerZakaza       write fNomerZakaza;
    property Zakazchik        : RawUTF8     read fZakazchik         write fZakazchik;
    property Vypolnen         : Boolean     read fVypolnen          write fVypolnen;
    property TimeVypoln       : TDateTime   read FTimeVypoln        write FTimeVypoln;
  end;

  TSQLRecordTip = class(TSQLRecord)
  private
    fNameTipoisp          : RawUTF8;
  published
    property NameTipoisp          : RawUTF8           read fNameTipoisp           write fNameTipoisp;
  end;

  TSQLRecordDevice = class(TSQLRecord)
  private
    fIDZakaza         : TSQLRecordZakaz;
    fIDTipoisp        : TSQLRecordTip;
    fSerNomer         : RawUTF8;

    fOtchety_nastrk     : TDataReport;
    fOtchety_termo0     : TDataReport;
    fOtchety_termo8     : TDataReport;
    fOtchety_termo16    : TDataReport;
    fOtchety_termo24    : TDataReport;
    fOtchety_termo36    : TDataReport;
    fOtchety_termo48    : TDataReport;
    fOtchety_termo72    : TDataReport;
    fOtchety_Koeff      : TDataReport;
    fOtchety_HtmKoeff   : TDataReport;
    fOtchety_Test       : TDataReport;
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property IDZakaza         : TSQLRecordZakaz   read fIDZakaza          write fIDZakaza;
    property IDTipoisp        : TSQLRecordTip     read fIDTipoisp         write fIDTipoisp;
    property SerNomer         : RawUTF8           read fSerNomer          write fSerNomer;

    property Otchety_nastrk     : TDataReport read fOtchety_nastrk  write fOtchety_nastrk;
    property Otchety_termo0     : TDataReport read fOtchety_termo0  write fOtchety_termo0;
    property Otchety_termo8     : TDataReport read fOtchety_termo8  write fOtchety_termo8;
    property Otchety_termo16    : TDataReport read fOtchety_termo16 write fOtchety_termo16;
    property Otchety_termo24    : TDataReport read fOtchety_termo24 write fOtchety_termo24;
    property Otchety_termo36    : TDataReport read fOtchety_termo36 write fOtchety_termo36;
    property Otchety_termo48    : TDataReport read fOtchety_termo48 write fOtchety_termo48;
    property Otchety_termo72    : TDataReport read fOtchety_termo72 write fOtchety_termo72;
    property Otchety_Koeff      : TDataReport read fOtchety_Koeff   write fOtchety_Koeff;
    property Otchety_HtmKoeff   : TDataReport read fOtchety_HtmKoeff write fOtchety_HtmKoeff;
    property Otchety_Test       : TDataReport read fOtchety_Test    write fOtchety_Test;
  end;


{ TSQLRecordDevice }

constructor TSQLRecordDevice.Create;
begin
  inherited;
  fOtchety_nastrk:=TDataReport.Create;
  fOtchety_termo0:=TDataReport.Create;
  fOtchety_termo8:=TDataReport.Create;
  fOtchety_termo16:=TDataReport.Create;
  fOtchety_termo24:=TDataReport.Create;
  fOtchety_termo36:=TDataReport.Create;
  fOtchety_termo48:=TDataReport.Create;
  fOtchety_termo72:=TDataReport.Create;
  fOtchety_Koeff:=TDataReport.Create;
  fOtchety_HtmKoeff:=TDataReport.Create;
  fOtchety_Test:=TDataReport.Create;
end;

destructor TSQLRecordDevice.Destroy;
begin
  fOtchety_nastrk.Free;
  fOtchety_termo0.Free;
  fOtchety_termo8.Free;
  fOtchety_termo16.Free;
  fOtchety_termo24.Free;
  fOtchety_termo36.Free;
  fOtchety_termo48.Free;
  fOtchety_termo72.Free;
  fOtchety_Koeff.Free;
  fOtchety_HtmKoeff.Free;
  fOtchety_Test.Free;
  inherited;
end;

{ TDataOtchet }

procedure TDataReport.Clear;
begin
  fHref:='';
  fReport:='';
  fResult:='';
  fDateTest:='';
end;

{------------------------------------------------------------------------------
 Create Record
 ------------------------------------------------------------------------------}

procedure CreateRecordDB(sNomerZakaza,stipoisp:RawUTF8;var iId_BD:TID);
var
  RecordOrder: TSQLRecordZakaz;RecordTip: TSQLRecordTip; RecordDevice: TSQLRecordDevice;
  iId_Order,iId_Tip: integer;
  s:RawUTF8;
begin
  s:=Database.OneFieldValue(Model['Zakaz'],'ID',Format('NOMERZAKAZA=''%s''',[sNomerZakaza]));
  if not TryStrToInt(s,iId_Order) then
  begin
    RecordOrder:=TSQLRecordZakaz.Create;
    try
      RecordOrder.NomerZakaza:=sNomerZakaza;
      RecordOrder.Vypolnen:=False;
      iId_Order := Database.Add(RecordOrder,true);
    finally
      RecordOrder.Free;
    end;
  end else
  begin
    RecordOrder:=TSQLRecordZakaz.Create(DataBase,iId_Order);
    RecordOrder.Vypolnen:=False;
    DataBase.Update(RecordOrder);
  end;

  s:=Database.OneFieldValue(Model['Tip'],'ID',Format('NAMETIPOISP=''%s''',[stipoisp]));
  if not TryStrToInt(s,iId_Tip) then
  begin
    RecordTip:=TSQLRecordTip.Create;
    try
      RecordTip.NameTipoisp:=stipoisp;
      iId_Tip := Database.Add(RecordTip,true);
    finally
      RecordTip.Free;
    end;
  end;

  RecordDevice:=TSQLRecordDevice.Create;
  try
    RecordDevice.IDZakaza:=TSQLRecordZakaz(iId_Order);
    RecordDevice.IDTipoisp:=TSQLRecordTip(iId_Tip);
    iId_BD := Database.Add(RecordDevice,true);
  finally
    RecordDevice.Free;
  end;
end;

{------------------------------------------------------------------------------
 Update Record
 ------------------------------------------------------------------------------}
procedure LoadProtocolToDB(iId_BD:TID;aHTMLString: RawUTF8; isProverkaSuccess: Boolean; dt: TDateTermoprAll);
var
  rec:TSQLRecordDevice;
  procedure AssignToOtchet(ADataReport:TDataReport);
  begin
    ADataReport.Href:='';// StringToUTF8(dt.sHref);
    ADataReport.Report:=aHTMLString;
    ADataReport.Result:=ifthen(isProverkaSuccess,'Success','Errors');
    ADataReport.DateTest:=DateTimeToStr(Now);
  end;
begin
  if (iId_BD=0) or (aHTMLString='') then Exit;

  rec:=TSQLRecordDevice.Create(Database,iId_BD);
  try
    case dt of
      Nastrk: AssignToOtchet(Rec.Otchety_nastrk);
      Termo0: AssignToOtchet(Rec.Otchety_termo0);
      Termo8: AssignToOtchet(Rec.Otchety_termo8);
      Termo16: AssignToOtchet(Rec.Otchety_termo16);
      Termo24: AssignToOtchet(Rec.Otchety_termo24);
      Termo36: AssignToOtchet(Rec.Otchety_termo36);
      Termo48: AssignToOtchet(Rec.Otchety_termo48);
      Termo72: AssignToOtchet(Rec.Otchety_termo72);
      Test: AssignToOtchet(Rec.Otchety_Test);

      KoeffDSP: AssignToOtchet(Rec.Otchety_Koeff);
      KoeffHTML: AssignToOtchet(Rec.Otchety_HtmKoeff);
    end;
    Database.Update(rec);
  finally
    Rec.free;
  end;
end;

function CreateSampleModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLRecordZakaz,TSQLRecordTip,TSQLRecordDevice]);
end;

begin
  Model := CreateSampleModel;
  try
    Database := TSQLRestServerDB.Create(Model, ChangeFileExt(Application.ExeName,'.db'));
    if not Assigned(Database) then raise Exception.Create('Error connect or create db');
    try
      TSQLRestServerDB(Database).CreateMissingTables(0);
      TSQLRestServerDB(Database).NoAJAXJSON:=False;

      CreateRecordDB('123','BE',iId_BD);
      LoadProtocolToDB(iId_BD,'<html></html>',true,Termo0);
      FileFromString(JSONReformat(Database.ExecuteJson([TSQLRecordDevice],'select * from Device')),'pServer.db.json');

      write('Press [Enter] to close the server.');
      Readln;
    finally
      Database.Free;
    end;
  finally
    Model.Free;
  end;
end.

Offline

#10 2015-09-28 14:05:03

miab3
Member
From: Poland
Registered: 2014-10-01
Posts: 188

Re: Strange behavior of "GetJSONValues"

@Alek

Delphi XE2-32(up4 hotfix1) mORMot 1.18.1928 - compiles and runs
Delphi 10 Seattle-32 mORMot 1.18.1928 - compiles and runs

Michal

Last edited by miab3 (2015-09-28 15:46:09)

Offline

#11 2015-09-29 05:39:01

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

I know, the application compiles and runs. And what about the content of the file "pserver.db.json". Is it ok?

   
what is most interesting is that the file is valid, but it is wrong

Last edited by Alek (2015-09-29 05:50:30)

Offline

#12 2015-09-29 07:04:45

miab3
Member
From: Poland
Registered: 2014-10-01
Posts: 188

Re: Strange behavior of "GetJSONValues"

For DXE2:

[
	{
		"ID": 1,
		"IDZakaza": 1,
		"IDTipoisp": 1,
		"SerNomer": "",
		"Otchety_nastrk": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo0": "{\"Href\":\"\",\"Report\":\"<html></html>\",\"Result\":\"Success\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo8": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo16": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo24": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo36": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo48": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_termo72": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_Koeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_HtmKoeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}",
		"Otchety_Test": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 08:59:09\"}"
	}
]

For DXE10

[
	{
		"ID": 1,
		"IDZakaza": 1,
		"IDTipoisp": 1,
		"SerNomer": "",
		"Otchety_nastrk": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo0": "{\"Href\":\"\",\"Report\":\"<html></html>\",\"Result\":\"Success\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo8": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo16": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo24": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo36": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo48": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_termo72": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_Koeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_HtmKoeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}",
		"Otchety_Test": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}cess\",\"DateTest\":\"2015-09-29 09:00:51\"}"
	}
]

Michal

Offline

#13 2015-09-29 07:23:20

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

thank you, but have to

[
	{
		"ID": 1,
		"IDZakaza": 1,
		"IDTipoisp": 1,
		"SerNomer": "",
		"Otchety_nastrk": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo0": "{\"Href\":\"\",\"Report\":\"<html></html>\",\"Result\":\"Success\",\"DateTest\":\"29.09.2015 10:35:52\"}",
		"Otchety_termo8": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo16": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo24": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo36": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo48": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_termo72": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_Koeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_HtmKoeff": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}",
		"Otchety_Test": "{\"Href\":\"\",\"Report\":\"\",\"Result\":\"\",\"DateTest\":\"\"}"
	}
]

I have code from 7 july 2015

Last edited by Alek (2015-09-29 07:40:09)

Offline

#14 2015-09-29 07:49:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Strange behavior of "GetJSONValues"

There was indeed an issue.

Should be fixed by http://synopse.info/fossil/info/69d8a117e2

Sorry for the delay.

Online

#15 2015-09-29 08:04:58

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 44

Re: Strange behavior of "GetJSONValues"

thank you very much, now it works very well

Last edited by Alek (2015-09-29 08:08:36)

Offline

Board footer

Powered by FluxBB