You are not logged in.
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