#1 2015-06-23 21:53:13

hnb
Member
Registered: 2015-06-15
Posts: 290

Loosing NULL value for Variant

NULL value for published Variant properties is stored correctly in DB but when data is received then NULL value is loosing (variant is unassigned).

Very painful especially for "database-first" approach (existing infrastructure, related to very big project, where I can't resign from the NULL).

Super simple test-case:

type
  TSQLtest = class(TSQLRecord)
  protected
    fv: Variant;
    fVersion: TRecordVersion;
  published
    property v: Variant read fv write fv;
    property Version: TRecordVersion read fVersion write fVersion;
  end;

function GetModel: TSQLModel;
begin
  Result := TSQLModel.Create([TSQLtest, TSQLRecordTableDeleted]);
end;

var
  MasterServer, SlaveServer: TSQLRestServerDB;
  Model: TSQLModel;
  t: TSQLtest;
begin
  Model := GetModel;

  MasterServer := TSQLRestServerDB.Create(Model, ':memory:');

  MasterServer.CreateMissingTables;

  t := TSQLtest.Create;
  t.v := NULL;
  WriteLn(VarTypeAsText(VarType(t.v)));

  MasterServer.Add(t, true);
  t.Free;

  t := TSQLtest.Create(MasterServer, 1);
  WriteLn(VarTypeAsText(VarType(t.v)));


  SlaveServer := TSQLRestServerDB.Create(Model,':memory:');
  SlaveServer.CreateMissingTables;
  SlaveServer.RecordVersionSynchronizeSlave(TSQLtest, MasterServer);

  t.free;
  t := TSQLtest.Create(SlaveServer, 1);
  WriteLn(VarTypeAsText(VarType(t.v)));

Output:

Null
Empty
Empty

anyway patch is attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing

other patch for "typo" bug:
https://drive.google.com/file/d/0B4PZhd … sp=sharing

output with first patch:

Null
Null
Null

best regards,
Maciej Izak


best regards,
Maciej Izak

Offline

#2 2015-06-24 06:25:47

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

Re: Loosing NULL value for Variant

Both patches applied.

Thanks for sharing!

Offline

Board footer

Powered by FluxBB