Page 1 of 1

TZReadOnlyQuery<>TZQuery

Posted: 25.07.2006, 13:47
by Terence
I am little bit confused about there is a TZReadOnlyQuery and a "TZQuery.Readonly" option.
Do we need both, what is the difference, advantage- disadantage?

Posted: 25.07.2006, 14:18
by gto
Hello Terence :)
The main difference between TZReadOnlyQuery and TQuery is that ReadOnly inherits TZAbstractRODataSet (Abstract Read Only Dataset) and normal Query inherits TZAbstractDataSet (Abstract Dataset) which inherits from TZAbstractRODataSet .

In other words, the ReadOnly doesn't have the write/edit subsystem/properties (the TZAbstractDataset Object) then the communication between application and database skips one level.

Never did any test, but, IMHO, for searches and other ReadOnly operations, TZReadOnlyQuery is the best. Waiting for more technical reviews :)

Posted: 25.07.2006, 14:24
by Terence
Question is if ReadOnly Property in TZQuery is still usefull then`?

Posted: 25.07.2006, 16:50
by mdaems
Well Fabian, it actually is usefull when working with components. That way you can decide at runtime if the user is allowed to update the data or not. If not (because of some rule you programmed) just set the property to false and it's not possible for the user to change the data.

Mark

Posted: 25.07.2006, 17:44
by gto
mdaems wrote:Well Fabian, it actually is usefull when working with components. That way you can decide at runtime if the user is allowed to update the data or not. If not (because of some rule you programmed) just set the property to false and it's not possible for the user to change the data.

Mark
Just a complement: If you try to alter data on a ReadOnlyQuery or Query with ReadOnly set to true, RaiseReadOnlyError will be called. In my version, this procedure is:

Code: Select all

{**
  Raises an error 'Operation is not allowed in read-only dataset.
}
procedure TZAbstractRODataset.RaiseReadOnlyError;
begin
  raise EZDatabaseError.Create(SOperationIsNotAllowed2);
end;
And the string referenced here is:

Code: Select all

SOperationIsNotAllowed2 = 'Operation is not allowed in READ ONLY mode';
Note that, internally, ReadOnly is called RequestLive, which acts in reverse way. RequestLive True means ReadOnly False and vice-versa. Two internal functions of TAbstractRODataset do that conversion:

Code: Select all

{**
  Gets the ReadOnly property.
  @return <code>True</code> if the opened result set read only.
}
function TZAbstractRODataset.GetReadOnly: Boolean;
begin
  Result := not RequestLive;
end;

{**
  Sets a new ReadOnly property.
  @param Value <code>True</code> to set result set read-only.
}
procedure TZAbstractRODataset.SetReadOnly(Value: Boolean);
begin
  RequestLive := not Value;
end;

Posted: 25.07.2006, 21:43
by Terence
ok, tx for detailed help ;)