#1 2015-09-01 08:02:04

xotox
Member
Registered: 2015-02-07
Posts: 18

FillPrepare() not working as expected with TSQLRestServerFullMemory

Hi Arnaud!

Following code works as expected if I am using a TSQLRestServerDB instance.

type
  TSQLPerson=class(TSQLRecord)
  private
    fWeight: integer;
    fFirstname: RawUTF8;
    fLastname: RawUTF8;
  published
    property Firstname: RawUTF8 read fFirstname write fFirstname;
    property Lastname: RawUTF8 read fLastname write fLastname;
    property Weight: integer read fWeight write fWeight;
  end;

procedure TTestDomSession.TestBasis;
const
  MAX=100;
var
  rest: TSQLRestServer;
  model:TSQLModel;
  person: TSQLPerson;
  db: string;

  procedure TestInsert;
  var
    i: integer;
  begin
    for i:=1 to MAX do
    begin
      person.Firstname := FormatUTF8('Firstname-%', [i]);
      person.Lastname := FormatUTF8('Lastname-%', [i]);
      person.Weight := i;
      Check(rest.Add(person,true)<>0);
    end;
  end;

  function TestCountAll: integer;
  begin
    result := 0;
    person.FillPrepare(rest, '', []);
    while person.FillOne do
      result:=result+1;
  end;

  function TestSelectCount(aFormat:RawUTF8; const aParams: array of const): integer;
  begin
    result := 0;
    person.ClearProperties;
    person.FillPrepare(rest, aFormat, [], aParams);
    while person.FillOne do begin
      result := result+1;
    end;
  end;
begin
  db := ChangeFileExt(ParamStr(0), '.db3');
  if FileExists(db) then
    Check(SysUtils.DeleteFile(db));
  model := TSQLModel.Create([TSQLPerson]);
  rest := TSQLRestServerDB.Create(model, db, true);
  //rest := TSQLRestServerFullMemory.Create(model, true);
  rest.CreateMissingTables();
  person := TSQLPerson.Create;
  try
    TestInsert;
    Check(TestCountAll=MAX);
    Check(TestSelectCount('', [])=MAX);
    Check(TestSelectCount('Firstname=?', ['Firstname-1'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-2'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-3'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-3'])=1);
    Check(TestSelectCount('Weight=?', [1])=1);
    Check(TestSelectCount('Weight>=?', [1])>=1);
    Check(TestSelectCount('Weight>=?', [MAX+1])=0);
    Check(TestSelectCount('Weight>?', [50])=50);
    Check(TestSelectCount('Lastname LIKE ?', ['Lastname-3'])=1);
    Check(TestSelectCount('Lastname LIKE ?', ['Lastname-3%'])>0);
  finally
    person.Free;
    rest.Free;
    model.Free;
  end;
end;

If using a TSQLRestServerFullMemory instance, then the test does not pass:

procedure TTestDomSession.TestBasis;
[...]
begin
[...]
  //rest := TSQLRestServerDB.Create(model, db, true);
  rest := TSQLRestServerFullMemory.Create(model, true); // <- use FullMemory Rest Server
  rest.CreateMissingTables();
  person := TSQLPerson.Create;
  try
    TestInsert;
    Check(TestCountAll=MAX);
    Check(TestSelectCount('', [])=MAX);
    Check(TestSelectCount('Firstname=?', ['Firstname-1'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-2'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-3'])=1);
    Check(TestSelectCount('Lastname=?', ['Lastname-3'])=1);
    Check(TestSelectCount('Weight=?', [1])=1);
    Check(TestSelectCount('Weight>=?', [1])>=1);  // <- This test does not pass when using FullMemory Rest Server!
    Check(TestSelectCount('Weight>=?', [MAX+1])=0);
    Check(TestSelectCount('Weight>?', [50])=50);
    Check(TestSelectCount('Lastname LIKE ?', ['Lastname-3'])=1);
    Check(TestSelectCount('Lastname LIKE ?', ['Lastname-3%'])>0);
  finally
    person.Free;
    rest.Free;
    model.Free;
  end;
end;

It looks like if ">", "<=", "LIKE ?", etc statements are not working with TSQLRestServerFullMemory. What am I doing wrong here?

King regards,
xotox.

Offline

#2 2015-09-01 16:32:45

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

Re: FillPrepare() not working as expected with TSQLRestServerFullMemory

These statements are indeed not supported by TSQLRestServerFullMemory yet.

Offline

Board footer

Powered by FluxBB