Page 1 of 1

problem with procedure TZGenericCachedResolver.PostUpdates

Posted: 20.01.2012, 18:10
by M56OBER
Hello !

problem with procedure TZGenericCachedResolver.PostUpdates

When i'm use an edit/post method and on the before post event an other edit/post

Sample

qy.Edit;
qy.FieldbyName('id').asInteger := Getid;
qy.post;

And the GetId method is

function getid:integer;
Var
qy : TZquery;
begin
qy := TZquery.Create(application);
qy.connection := Datamodule1.DATABASE;
qy.sql.text := 'select id from mytable where code="num" ';
qy.Open;
Result := qy.fieldbyName('id').asinteger + 1;
qy.edit
qy.fiedlbyname('id').asInteger := resut;
qy.post;
End;

In the procedure TZGenericCachedResolver.PostUpdates

...
if SQL <> '' then
begin

FillStatement(Statement, SQLParams, OldRowAccessor, NewRowAccessor);
// if Property ValidateUpdateCount isn't set : assume it's true
lValidateUpdateCount := (Sender.GetStatement.GetParameters.IndexOfName('ValidateUpdateCount') = -1)
or StrToBoolEx(Sender.GetStatement.GetParameters.Values['ValidateUpdateCount']); // modif O.B 21/01/2012 }

lUpdateCount := Statement.ExecuteUpdatePrepared;

if (lValidateUpdateCount)
and (lUpdateCount <> 1 ) then
raise EZSQLException.Create(Format(SInvalidUpdateCount, [lUpdateCount])); // modif O.B 21/01/2012}
end;
finally
SQLParams.Free;
end;


IN THAT CASE THE lUpdateCount = 2 do ERROR

Have you a similar problem?
Thank you for help

Posted: 07.02.2012, 20:46
by EgonHugeist
M56OBER,

do you use constraints or indices for your table? On designing the where-clause Zeos asks his MetaData for the best rowi dentifier to have min. one unique-update row. The problem you wrote about seems like the Metadata-informations can't bring up some identifiers and on executing the constructed select-Statement all rows with possible hits (no other fields changed in your example) where changed. On executing internal/prepared statements an Zeos error should be raised if the UpdateCount <>1.

This means there must be two rows in your where table field'ID'.AsInteger = qy.fieldbyName('id').asinteger + 1 ;

Generally its better to use better Unique/PrimaryKey-Constraints, Triggers(FB/IB), stored procedures, Generators or Autoincfields for ID fields..

correct me if i'm wrong...

best regards