You are not logged in.
Another solution (IMO the best):
TSQLexample = class(TSQLRecord)
protected
ftest: Variant;
fstrtest: Variant;
published
property test: Variant index NULLABLE_INTEGER read ftest write ftest; // NULLABLE_INTEGER = -1, NULLABLE_DATETIME = -2 etc.
property strtest: Variant index 30 read fstrtest write fstrtest; // similar to property strtest: RawUTF8 index 30 (...)
end;IMO idea to use a "Nullable* = type variant" definition is more "Convention over configuration"
. Especially for mixing "database-first"/"code-first" ORM coding, where I have a tons of Nullable* columns.
Sadly we can't use TNullable<Integer>... FPC don't allow this kind of type in published section...
Solution with single sftVariant kind of field needs more (much more...) configuration from code level, for example:
// nt* = Nullable Type Enum
fModel.Props[TSQLRecordWithVariants].ExternalDB.
MapVariantFieldType('foo', ntInteger).
MapVariantFieldType('YearOfDeath', ntDateTime);Using few more types like sftVariant don't bring much more code.
The decision is yours.
I do not know whether the technique is correct (just a concept). Patch is ofc not finished. I ask before I start further work on this.
Hi,
Next episode for "NULL" story.
I really need use more precise ORM system for master/slave replication. For master is used "database-first" approach (PostgreSQL), but for slave client on android is used "code-first". The problem exist for "SlaveServer.CreateMissingTables". Slave table is very different from master table. All columns created for table from published variant property they are "TEXT", but I need them as TDateTime (TEXT COLLATE ISO8601) or as Integer, and I need to be able set theirs values to NULL from ORM.
My initial solution:
TSQLexample = class(TSQLRecord)
protected
ftest: NullableInteger;
published
property test: NullableInteger read ftest write ftest;
end;"draft patch" with NullableInteger and NullableDateTime attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing
Patch can be extended for new nullable types and type checking in new classes like TSQLPropInfoRTTINullableInteger, TSQLPropInfoRTTINullableDateTime etc.
regards,
Maciej Izak
NULL value for published Variant properties is stored correctly in DB but when data is received then NULL value is loosing (variant is unassigned).
Very painful especially for "database-first" approach (existing infrastructure, related to very big project, where I can't resign from the NULL).
Super simple test-case:
type
TSQLtest = class(TSQLRecord)
protected
fv: Variant;
fVersion: TRecordVersion;
published
property v: Variant read fv write fv;
property Version: TRecordVersion read fVersion write fVersion;
end;
function GetModel: TSQLModel;
begin
Result := TSQLModel.Create([TSQLtest, TSQLRecordTableDeleted]);
end;
var
MasterServer, SlaveServer: TSQLRestServerDB;
Model: TSQLModel;
t: TSQLtest;
begin
Model := GetModel;
MasterServer := TSQLRestServerDB.Create(Model, ':memory:');
MasterServer.CreateMissingTables;
t := TSQLtest.Create;
t.v := NULL;
WriteLn(VarTypeAsText(VarType(t.v)));
MasterServer.Add(t, true);
t.Free;
t := TSQLtest.Create(MasterServer, 1);
WriteLn(VarTypeAsText(VarType(t.v)));
SlaveServer := TSQLRestServerDB.Create(Model,':memory:');
SlaveServer.CreateMissingTables;
SlaveServer.RecordVersionSynchronizeSlave(TSQLtest, MasterServer);
t.free;
t := TSQLtest.Create(SlaveServer, 1);
WriteLn(VarTypeAsText(VarType(t.v)));Output:
Null
Empty
Emptyanyway patch is attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing
other patch for "typo" bug:
https://drive.google.com/file/d/0B4PZhd … sp=sharing
output with first patch:
Null
Null
Nullbest regards,
Maciej Izak
Hi,
when I am using "is null" in code like:
st := TSQLsometable.CreateAndFillPrepare(client, 'x is null');then I have got error from server side
First chance exception at $7607C42D. Exception class EZSQLException with message
'SQL Error: ERROR: syntax error at or near "nullnull"
LINE 1: ... from sometable where x is nullnullanyway patch is attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing
how can I add patch/attach file by http://synopse.info/fossil/ ?
or maybe can I send pull requests by https://github.com/synopse/mORMot ?
best regards,
Maciej Izak
Now works perfect. Even SendTimeout and ReceiveTimeout in TSQLHttpClientWinSock.InternalCheckOpen is now covered.
Thanks.
Why you have added ConnectTimeout optional parameter only for TSQLHttpClientRequest? I need ConnectTimeout for TSQLHttpClientWebsockets/TSQLHttpClientWinSock
.
Hi,
I am using mORMot for Android client (FPC 3.1.1 r30739). I have problem when server is unavailable (for TSQLHttpClientWebsockets/TSQLHttpClientWinSock).
aClient := TSQLHttpClientWebsockets.Create(cfg.IP, cfg.Port, aModel);
aPerson := TSQLperson.Create(aClient, someID); // this line is freezing application for more than 60 sec In windows client all works fine (the client application does not stop on the line mentioned above). Anyway i found solution (maybe not perfect but now is possible to set timeout in overloaded constructor in TSQLHttpClientWinSock). Patch attached:
https://drive.google.com/file/d/0B4PZhd … sp=sharing
best reagrds,
Maciej Izak
Thanks. Works like a charm.
Hi :)
mORMot is amazing, thanks for great work.
I have small problem. How can I save TDocVariant in a more human readable way?
I need this for settings. For example:
var
cfg: Variant;
begin
TDocVariant.New(cfg);
cfg.Host := eHost.Text;
cfg.Port := ePort.Text;
cfg.DBName := eDBName.Text;
cfg.User := eUser.Text;
cfg.Passwd := ePasswd.Text;
FileFromString(string(cfg), 'settings.json');
end;best regards,
Maciej Izak