Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert-update problem #3

Open
irupinax opened this issue May 28, 2018 · 0 comments
Open

insert-update problem #3

irupinax opened this issue May 28, 2018 · 0 comments

Comments

@irupinax
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant