#1 2019-03-18 07:33:19

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Persist TSQLRecord fields of type TInt64DynArray as JSON in the db?

Hello ab,

According to the document (https://synopse.info/files/html/Synopse … ml#TITL_26), any TSQLRecord-derived fields those are defined dynamic arrays, I guess including TInt64DynArray, will be **stored as BLOB format** in the database.

With the current implementation, is it possible (maybe via a setting) to store TInt64DynArray as JSON text value in the db?
That can introduce a lot of benefits, for example, one can take advantage of the JSON1 SQLite extension, one can view the values in plain text so makes debugging issues easier, and so on.

Last edited by edwinsn (2019-03-18 07:50:12)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2019-03-18 07:49:23

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Persist TSQLRecord fields of type TInt64DynArray as JSON in the db?

PS:
My currently planned solution is to define a child class from TRawUTF8ListHashed (which are stored as JSON text in the db according to the document, since it derives from TRawUTF8List) for storing int64 values, for example:

type 
  TInt64ListHashed = class(TRawUTF8ListHashed)
  public
    Add(aValue: Int64): PtrInt; overload;
    IndexOf(aValue: Int64): PtrInt; overload;
end;

and use this type as the field type.

Last edited by edwinsn (2019-03-18 07:50:49)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2019-03-18 07:53:18

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: Persist TSQLRecord fields of type TInt64DynArray as JSON in the db?

Instead of Declaring your property as a dynamic array, you can declare it as RawUTF8 and use TDynArray.SaveToJSON/LoadFromJSON.

Offline

#4 2019-03-18 08:41:57

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Persist TSQLRecord fields of type TInt64DynArray as JSON in the db?

pvn0 wrote:

Instead of Declaring your property as a dynamic array, you can declare it as RawUTF8 and use TDynArray.SaveToJSON/LoadFromJSON.

Hello pvn0, thanks for your good advise! I see TDynArray has the Sort method, so it definitely meets my requirements!


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB