You are not logged in.
Pages: 1
Hi!
I'm back to mORMot, I'm doing some test on nested array :
My business object is :
TTag = class;
// pas d objectlist ds Mormot seulement des array
TTagDynArray = array of TTag;
TTag = class(TSQLRecord)
private
FSubCat: TTagDynArray;
FDisplayStr: rawUTF8;
published
property SubCategory: TTagDynArray read FSubCat write FSubCat;
property DisplayStr: rawUTF8 index 200 read FDisplayStr write FDisplayStr;
end;
I try to use the ORM to store it on a DB
I create a tag sport wich has two subtags (bike and footing)
FServer := TDbUtility.CreateDb;
LTag := TTag.Create;
LTag.DisplayStr := 'Sport';
LTag2 := TTag.Create;
LTag2.DisplayStr := 'bike';
LTag.DynArray('SubCat').Add(LTag2);
LTag2 := TTag.Create;
LTag2.DisplayStr := 'footing';
LTag.DynArray('SubCat').Add(LTag2);
LID := FServer.Add(LTag, True);
FreeAndNil(LTag);
FreeAndNil(Ltag2);
LTag := TTag.Create(FServer, LID);
LTag2 := LTag.SubCat[1];
When i fetch the parent tag, the array Subcat[0] is good (bike) but the Subcat[1] always contain the parent tag (sport) himself.
Did i make a mistake somewhere?
Offline
OK, It's work better but with this code :
LTag := TTag.Create;
LTag.DisplayStr := 'Sport';
LTag2 := TTag.Create;
LTag2.DisplayStr := 'bike';
FServer.Add(LTag2, True);
LTag.DynArray('SubCat').Add(LTag2);
LTag2 := TTag.Create;
LTag2.DisplayStr := 'footing';
FServer.Add(LTag2, True);
LTag.DynArray('SubCat').Add(LTag2);
LID := FServer.Add(LTag, True);
FreeAndNil(LTag);
LTag := TTag.Create(FServer, LID);
// !subCat is empty!
LTag2 := LTag.SubCat[1];
The SubCat array is empty, i check the blob on Db it contain the Json object. May i miss someting?
Even if i think i'm going to use a pivot table for these kind of recursive data, i want to make it work for future object wich contains "regular" dynarray.
Offline
I think dynamic array are saved as BLOB in DB, so you need either to force the retreive by record:
LTag := TTag.Create(FServer, LID);
FServer.RetrieveBlobFields(LTag);
//Access your LTag.SubCat[1] here
or enable forceblobfield at table or DB level with TSQLRestClientURI.ForceBlobTransfert or TSQLRestClientURI.ForceBlobTransfertTable[]
By default, Blob fields aren't retrieved to save bandwith.
Offline
Infortunatly i tried RetrieveBlobFields but its not working either.
Offline
I notice something, the JSON response is not correct the array its a string like this : aXNwbGF5U3RyIjoiYmlrZSJ9LHsiSUQiOjg5LCJTdWJDYXQiOltdLCJEaXNwbGF5U3RyIjoiZm9vdGluZyJ9XQ==
Although if i inspect my blob as text on the DB the string is good : [{"ID":88,"SubCat":[],"DisplayStr":"bike"},{"ID":89,"SubCat":[],"DisplayStr":"footing"}]
Any suggestion?
Offline
you mean by doing this :
initialization
TJSONSerializer.RegisterObjArrayForJSON(TypeInfo(TTagDynArray), TTag);
Yes i did.
Offline
I use firebird
class function TDbUtility.CreateDb: TSQLRestServerDb;
var
FProp: TSQLDBZEOSConnectionProperties;
begin
FProp := TSQLDBZEOSConnectionProperties.Create
(TSQLDBZEOSConnectionProperties.URI(dFirebird, '',
'D:\Program Files\Firebird\Firebird_2_5\WOW64\fbclient.dll', False),
'D:\delphi\FriendZone\TestYoann.fdb', 'SYSDBA', 'masterkey');
VirtualTableExternalRegisterAll(TModelUtility.GetModel, FProp);
Result := TSQLRestServerDB.Create(TModelUtility.GetModel, 'Test.json');
Result.CreateMissingTables;
Offline
OK it's a firebird problem because if i use the standard SQLite without VirtualTableExternalRegisterAll, all works fine. I'me going to track what's the problem or switch to the in-built standard sqlite engine.
Last edited by nostroyo (2017-03-19 09:53:22)
Offline
Do you want me to provide my test application for debug?
Offline
Pages: 1