Skip to content

insert-update problem #3

@irupinax

Description

@irupinax

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions