Recent

Author Topic: What makes a dataset read-only?  (Read 6032 times)

AKCarlow

  • New Member
  • *
  • Posts: 45
What makes a dataset read-only?
« on: July 27, 2014, 04:30:54 pm »
I have two separate dbGrids on a form, each populated by its own SQLQuery, each showing data from different tables in the same local MySQL 5 database. On one of them I can edit a cell by clicking on it; when I ApplyUpdates the changes are written to the database.

On the other clicking a cell does highlight it, but I cannot edit it. One of the columns is for a TinyInt (boolean) field and is correctly showing as checkboxes. I have an OnClick handler for this grid - if I click anywhere in the grid, I get the pirate 1 message, and if I click in the Estimate (TinyInt) column I get pirate 1 and 2, but not 3, and the program crashes with a "dataset is read-only" error. As far as I can see, the settings for things like Active and Enabled on the various components are the same in both cases. What am I doing wrong?  >:D

Code: [Select]
procedure TfShareReg.dbgUsageCellClick(Column: TColumn);
begin
ShowMessage('pirate 1');
If Column.FieldName = 'Estimate' then
  begin
  ShowMessage('pirate 2');
  qUsage.Active:=true;
  qUsage.Edit;
  ShowMessage('pirate 3');
  if Column.Field.OldValue = 0 then
     begin //do estimate
     showmessage('make an estimate');
     Column.Field.NewValue := 1;
     end {do estimate}
  else
      begin {undo estimate}
      showmessage('put it back');
      Column.Field.Value:=0;
      end; {undo estimate}
  qUsage.ApplyUpdates;
  end;
end;     
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: What makes a dataset read-only?
« Reply #1 on: July 27, 2014, 04:32:50 pm »
Do the insertsql, deletesql and updatedsql properties contain the relevant SQL? If not (e.g. when you have a more complicated query than a simple select), you'll have to fill those properties yourself...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: What makes a dataset read-only?
« Reply #2 on: July 27, 2014, 04:52:30 pm »
In both cases InsertSQL etc are empty, but ParseSQL is true. Both cases have a parameterised WHERE clause - the parameter is set by a DataChange event handler in another data set eg
Code: [Select]
  qUsage.Close;
  qUsage.Params.ParamByName('paramShare').AsString:=dbtxtShareNo.Caption;
  qUsage.Open;

Both grids properly show the expected values for the selected row in the other dataset.
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: What makes a dataset read-only?
« Reply #3 on: July 28, 2014, 07:25:36 am »
What is in qUsage.SQL.Text ?

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: What makes a dataset read-only?
« Reply #4 on: July 29, 2014, 12:30:20 am »
select ShareNo,ReadingDate,Connection,Reading,Previous,Note,Estimate,Actual, Reading-Previous as M3Used from Connections join MeterReadings on ConnectionNo = Connection where ShareNo = :paramShare order by Connection,ReadingDate desc;       
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: What makes a dataset read-only?
« Reply #5 on: July 29, 2014, 07:09:23 am »
Then it is expected behavior, that dataset is ReadOnly.
If SQL is multi-table select (better say something else than single table select), then you must supply own InsertSQL, UpdateSQL, DeleteSQL to let sqlDB know which tables to update.

AKCarlow

  • New Member
  • *
  • Posts: 45
Re: What makes a dataset read-only?
« Reply #6 on: July 29, 2014, 12:16:39 pm »
Ahh, thank you. I can do that. Time to move on so and find the next hurdle!  :)
Using: OS-X 10.6.8, Lazarus 1.2.4, FPC 2.6.4,  MySQL 5.6.19 (32-bit)

 

TinyPortal © 2005-2018