Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi ClientDataset Read-only

I am currently testing with:

  1. A SQLConnection which is pointed towards an IB database.
  2. A SQLDataset that has a SQLConnection field set to the one above.
  3. A DatasetProvider that has the SQLDataset in (2) as its Dataset field value.
  4. A ClientDataset, with the ProviderName field pointing to the provider in (3).

I use the following method (borrowed from Alister Christie) to get the data...

function TForm1.GetCurrEmployee(const IEmployeeID: integer): OleVariant; 
const 
  SQLSELEMP = 'SELECT E.* FROM EMPLOYEE E WHERE E.EMPLOYEEID = %s'; 
begin 
  MainDM.SQLDataset1.CommandText := Format(SQLSELEMP, [Edit1.Text]); 
  Result := MainDM.DataSetProvider1.Data; 
end;

Which populates the DBGrid with just one record. However, when I manually edit the record, click on Post, then try to commit the changes, using

MainDM.ClientDataset1.ApplyUpdates(0); // <<<<<< 

It bombs, with the message "SQLDataset1: Cannot modify a read-only dataset."

I have checked the ReadOnly property of the Provider, and of the ClientDataset, and the SQL has no joins.

What could be causing the error?


1 Answers

It appears that your ClientDataSet.Data property is being populated from the Data property of the DataSetProvider. With the setup you described, you should be able to simply call ClientDataSet.Open, which will get the data from the DataSetProvider.

BTW, the default behavior of the DataSetProvider when you call the ClientDataSet.ApplyUpdates method is to send a SQL query to the connection object, and not the DataSet from which the data was obtained (assuming a homogeneous query). Make sure that your DataSetProvider.ResolveToDataSet property is not set to true.

Finally, on an unrelated note, your code above appears to be open to a SQL injection attack (though I have not tested this). It is safer to use a parameter to define the WHERE clause. If someone enters the following into Edit1 you might be in trouble (assuming the InterBase uses the drop table syntax): 1;drop table employee;

like image 106
Cary Jensen Avatar answered Jul 22 '26 13:07

Cary Jensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!