Page 1 of 1

Problem with edit and post

Posted: 24.03.2007, 12:41
by cokotech
Hallo!

I have a big problem with the .edit and .post procedure.

The following programcode


Zquery1.SQL.Add('Select lastlogin from Benutzer where `Benutzername` = BINARY'''+AnsiToUTF8(konfig.benutzername)+''';')
If NOT form1.Zquery1.eof then
BEGIN
form1.ZQuery1.edit;
form1.Zquery1.FieldValues['lastlogin']:=Datum;
lastlogin:=datum;
form1.ZQuery1.post;
END;


becomes this sql code (i've logged it):

070324 12:23:01 170 Query Select lastlogin from Benutzer where `Benutzername` = BINARY'ScampiKutter'
170 Query UPDATE `GildenIdent Daten`.Benutzer SET lastlogin='2007-03-24 12:23:00' WHERE lastlogin='2007-03-24 12:21:34'



Now it changes more then one line.... t think the statemant should be something line .....'WHERE `PRIMARY`=xyz'

I use the newest Components but i tried it also with some older.....


Bye Sven!

Posted: 25.03.2007, 14:19
by mdaems
Hi,

Did you try to add the primary key columns to the query?
Like 'select Benutzername, lastlogin from Benutzer where ....'. This way Zeoslib should be able to decide which key to use.
Now we can't identify the row to update. So Zeos assumes Lastlogin is the key to use...

Mark

Posted: 25.03.2007, 15:13
by cokotech
Okay,

you mean i've to add the PRIMARY-Key in the select command even if i don't need it..... okay.... thanks!


Bye Sven!

Posted: 25.03.2007, 16:53
by mdaems
That depends on how you look at it. You need it for the update... I know you added it as a where-clause, but zeos isn't all-knowing and can't decide if it has to add your where clause. Here it would have worked, but not if the where clause had contained some random function.
When it recognizes the (full) PK in the columns and you choose TQuery.WhereMode := wmWhereKeyOnly (default) it only adds the PK to the where clause of the update statement. Otherwise all fields are used to make the update query as 'unique' as possible.