You are not logged in.
Pages: 1
lele9,
vSession.SystemUser := vUser.ID;
I've publish property of a type TSystemUser, not TId, so I need to assign instance of TSystemUser to it.
ab,
vSession.SystemUser := vUser.AsTSQLRecord;
See http://synopse.info/files/html/Synopse% … ml#TITL_70
So you should store the ID in the published property, not an instance:
vSession.SystemUser := vUser.AsTSQLRecord;
Thank you very much! Works like a charm!
Alexander.
Hi!
I'm stuck in creating new entity with link to already existing entity of other type.
My simplified model:
TSystemUser = class(TSQLRecord)
private
fUserName: string;
published
property UserName: string read fUserName write fUserName;
end;
TSystemSession = class(TSQLRecord)
private
fSystemUser: TSystemUser;
fStartTime: TDateTime;
published
property SystemUser: TSystemUser read fSystemUser write fSystemUser;
property StartTime: TDateTime read fStartTime write fStartTime;
end;
I'm loading user from DB (PostgreSQL with ZEOS) and creating user session like this:
var
vUser: TSystemUser;
vSession: TSystemSession;
begin
vUser := TSystemUser.CreateAndFillPrepare(fRestServer, 'username=?', ['volax']);
try
if vUser.FillOne then
begin
vSession := TSystemSession.Create;
try
vSession.StartTime := Now;
vSession.SystemUser := vUser;
// Adding user's session:
fRestServer.Add(vSession, True);
finally
vSession.Free;
end;
end;
finally
vUser.Free;
end;
After call to fRestServer.Add(vSession, True); the session created, but value of SystemUser field in SystemSession table looks to be pseudo-random value, StartTime seems to be correct.
Can anyone explain, what's wrong with my code?
Thank you!
Hi, all,
Next problem is that CreateSQLMultiIndex throws an exception on second program run.
As far as I know, there is no statement IF NOT EXISTS for index creation in Postgresql, hope I am wrong.
The problem with CreateSQLMultiIndex is in call to TSQLDBConnectionProperties.SQLAddIndex function, which generates index name.
TSQLDBConnectionProperties.SQLAddIndex contains a bug:
if length(FieldsCSV)+length(Table)>27 then
// sounds like if some DB limit the identifier length to 32 chars
IndexName := IndexName+'INDEX'+crc32cUTF8ToHex(Table)+
crc32cUTF8ToHex(FieldsCSV)+CardinalToHex(GetTickCount64) // BUG! GetTickCount64 randomizes index name!
else
IndexName := IndexName+'NDX'+Table+FieldsCSV;
Call to GetTickCount64 "randomizes" index name, so new indexes created again and again at every server restart, caused by failed index existence checks.
Removing "+CardinalToHex(GetTickCount64)" part of IndexName will do the trick:
if length(FieldsCSV)+length(Table)>27 then
// sounds like if some DB limit the identifier length to 32 chars
IndexName := IndexName+'INDEX'+crc32cUTF8ToHex(Table)+
crc32cUTF8ToHex(FieldsCSV)
else
IndexName := IndexName+'NDX'+Table+FieldsCSV;
Arnaud, is it possible to fix?
Thank you!
Best regards, Alexander.
Pages: 1