You are not logged in.
Pages: 1
Hello,
I do encounter a strange problem, and do not know what to think of it.
System: latest mORMot, Win64, FPC32
I have an email record:
TEmail = type RawUTF8;
TEmailAddress = class(TSynPersistent)
protected
fEmail: TEmail;
public
constructor Create(aEmail:string); reintroduce;
published
property Email: TEmail read fEmail write fEmail;
end;
TEmailAddressObjArray = array of TEmailAddress;
and a person
TName = type RawUTF8;
TSQLPerson = class(TSQLRecord)
private
fName: TName;
public
fEmail: TEmailAddressObjArray;
published
property Name: TName read fName write fName;
property Email: TEmailAddressObjArray read fEmail write fEmail;
end;
The database is filled with TSQLPerson data (10 records). The data looks good with an external (SQLite3) viewer. Nice JSON arrays in the Email field.
The data is read back:
fConnectionOk:=DataRecord.FillPrepare(RestClient);
if ConnectionOk then
begin
SQLTable:=DataRecord.FillTable;
DataRecord.FillRow(SQLTable.RowFromID(4));
writeln(InttoStr(4)+': '+TSQLPerson(DataRecord).Email[0].Email);
DataRecord.FillRow(SQLTable.RowFromID(5));
writeln(InttoStr(5)+': '+TSQLPerson(DataRecord).Email[0].Email);
DataRecord.FillRow(SQLTable.RowFromID(6));
writeln(InttoStr(6)+': '+TSQLPerson(DataRecord).Email[0].Email);
DataRecord.FillRow(SQLTable.RowFromID(5));
write(InttoStr(5)+': '+TSQLPerson(DataRecord).Email[0].Email);
DataRecord.FillRow(SQLTable.RowFromID(4));
writeln(InttoStr(4)+': '+TSQLPerson(DataRecord).Email[0].Email);
end;
The result:
4: dummy4@dummy.com
5: dummy5@dummy.com
6: dummy6@dummy.com
5: dummy6@dummy.com
4: dummy6@dummy.com
As you can see: the last two lines are wrong.
And I do not know why ?!
Offline
I just did the same test with Delphi XE8 for Win32.
Exactly the same result.
Obviously, I do not understand the use of T*ObjArray fully.
The server:
aServer:=TSQLRestServerDB.Create(aModel,'data.db3',False);
aServer.DB.Synchronous := smNormal;
aServer.DB.LockingMode := lmExclusive;
aServer.CreateMissingTables;
The client:
aRestClient := TSQLRestClientDB.Create(aServer AS TSQLRestServerDB);
Result:
4: dummy4@dummy.com
5: dummy5@dummy.com
6: dummy6@dummy.com
5: dummy6@dummy.com
4: dummy6@dummy.com
Offline
For anybody interested: a program based on Sample 2 showing this behavior can be found here:
Offline
I think you have to use another approach. This worked as expected for me.
procedure TForm1.Button1Click(Sender: TObject);
begin
FindButtonClick(StrToInt(Edit1.text),StrToInt(Edit2.text),self);
end;
procedure TForm1.FindButtonClick(myId, aID: integer; Sender: TObject);
var
Rec: TSQLSampleRecord;
fConnectionOk:boolean;
SQLTable:TSQLTable;
CurrentRow: integer;
begin
Rec := TSQLSampleRecord.Create;
fConnectionOk:=Rec.FillPrepare(Database);
try
SQLTable:=Rec.FillTable;
CurrentRow := SQLTable.RowFromID(aID);
Rec.FillRow(CurrentRow);
QuestionMemo.Lines.Append(InttoStr(myID)+': '+Rec.Email[0].Email);
finally
Rec.Free;
end;
end;
Last edited by warleyalex (2015-10-26 16:01:18)
Offline
@warleyalex
Thanks for your effort.
But your example gets a new table for every request for a new ID.
I need to use the existing table for a new ID.
@ab
1)
Could you comment on this behavior.
(see included example in previous post)
And, when doing something wrong, could you please enlighten me !
2)
While using mORMot, I did encounter a case sensitivity problem.
Would it be possible to do something like this (inside mORMot.pas):
{$ifndef CASE}
' TEXT COLLATE NOCASE, ',
' TEXT COLLATE SYSTEMNOCASE, ',
{$else}
' TEXT, ',
' TEXT, ',
{$endif}
3)
Would you mind changing the name of SynDBZEOS.pas into SynDBZeos.pas (lowercase last thee characters).
Otherwise, my app will not compile on Mac.
Thanks.
Offline
1) Is SQLTable.RowFromID() working, or is it a problem of SQLTable.RowFromID().
2) You could use SetCustomCollationForAll() at runtime, when creating the model.
See http://synopse.info/files/html/api-1.18 … C_8CF7118A
3) Done for fossil and git repositories.
Offline
1)
This (still the same simple sample 2 code with email object array):
Rec := TSQLSampleRecord.Create;
fConnectionOk:=Rec.FillPrepare(Database);
SQLTable:=Rec.FillTable;
Rec.FillRow(4);
QuestionMemo.Lines.Append(InttoStr(4)+': '+Rec.Email[0].Email);
Rec.FillRow(5);
QuestionMemo.Lines.Append(InttoStr(5)+': '+Rec.Email[0].Email);
Rec.FillRow(6);
QuestionMemo.Lines.Append(InttoStr(6)+': '+Rec.Email[0].Email);
Rec.FillRow(5);
QuestionMemo.Lines.Append(InttoStr(5)+': '+Rec.Email[0].Email);
Rec.FillRow(4);
QuestionMemo.Lines.Append(InttoStr(4)+': '+Rec.Email[0].Email);
also results into
4: dummy4@dummy.com
5: dummy5@dummy.com
6: dummy6@dummy.com
5: dummy6@dummy.com
4: dummy6@dummy.com
So there is no difference in calling rows directly or via RowFromID.
Still the same behavior !
2) Thanks !
3) Thanks !
Edit 3):
SynDBZeos still has a reference to the Windows unit, that is, AFAIK, not needed.
Last edited by AOG (2015-11-10 11:59:26)
Offline
I tried to reproduce the issue.
See http://synopse.info/fossil/info/1d770e9d23a0e2b
No problem reported at this level....
But I identified a potential issue in TSQLPropInfoRTTIDynArray.SetValue when the same JSON input buffer is re-used.
So it should be fixed by http://synopse.info/fossil/info/66d9745378
Offline
Your new mORMot.pas solves all reported problems !
The old mORMot.pas still shows the reported effect !
So, thanks very much !!
Offline
Pages: 1