You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies for raising this but I am trying to use ghorm and have a problem with the 'Update'. The problem may be my understanding of how to use the 'Insert' and 'Update'.
An 'update' updates the wrong record (wrong ID?) in the database.
A comment in TORM.Update(o: T) states that '// already has id,'.
I cannot see why/where and the wrong record in database is updated.
I have modified the unittest/tcUsersAndRoles to demonstrate the problem,the code is below.
Comments show the results on the record/s in the database.
So,have I got things wrong???? Any help appreciated.
Ian Upton, Melbourne Australia.
procedure TTestUsersAndRoles.TestInsertUser;
var
o: TUsers;
u: TUser;
id: Integer;
begin
o := TUsers.Create;
u := o.New;
u.Name := 'Mario';
u.Password := '123abc';
AssertTrue('Failed to insert user to database',o.Insert(u));
id := u.ID;
u.Free; // Mario123abc <<<< Record in DB
u := o.New;
u.Name := 'iru';
u.Password := '123';
AssertTrue('Failed to insert iru to database',o.Insert(u));
id := u.ID;
// u.Free; // iru123 Mario123abc <<<< Two records in DB
Environment: Mint 18.3, laz 1.8.3, fpc 3.05.
Apologies for raising this but I am trying to use ghorm and have a problem with the 'Update'. The problem may be my understanding of how to use the 'Insert' and 'Update'.
An 'update' updates the wrong record (wrong ID?) in the database.
A comment in TORM.Update(o: T) states that '// already has id,'.
I cannot see why/where and the wrong record in database is updated.
I have modified the unittest/tcUsersAndRoles to demonstrate the problem,the code is below.
Comments show the results on the record/s in the database.
So,have I got things wrong???? Any help appreciated.
Ian Upton, Melbourne Australia.
procedure TTestUsersAndRoles.TestInsertUser;
var
o: TUsers;
u: TUser;
id: Integer;
begin
o := TUsers.Create;
u := o.New;
u.Name := 'Mario';
u.Password := '123abc';
AssertTrue('Failed to insert user to database',o.Insert(u));
id := u.ID;
u.Free; // Mario123abc <<<< Record in DB
u := o.New;
u.Name := 'iru';
u.Password := '123';
AssertTrue('Failed to insert iru to database',o.Insert(u));
id := u.ID;
// u.Free; // iru123 Mario123abc <<<< Two records in DB
u.Password:= 'xxx';
o.Update(u); // iru123 iruxxx <<<< Wrong (?) record updated
The text was updated successfully, but these errors were encountered: