Problem with edit and post

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
cokotech
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 24.03.2007, 12:27

Problem with edit and post

Post 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!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
cokotech
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 24.03.2007, 12:27

Post 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!
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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.
Post Reply