Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-12

Master-Detail in sqldb broken?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Julio César Gázquez

Hi all.

I have a master detail form, I'm using SQLDB and running a current snapshot (Lazarus-0.9.29 rev 28828).

Retrieving data works Ok. Saving changes doesn't. Googling I found old comments in the mailing list saying primary keys must be integers. Is yet that the case? If it isn't, component declaration and relevant code follows.

Another issue, when the master have more than 1 record, if I edit the detail, then move around in the master, detail changes are lost. IIRC this works fine in dbExpress. It is a bug or a design limitation of sqldb?

   object PQConnection1: TPQConnection
     Connected = False
     LoginPrompt = False
     DatabaseName = 'contabilidad'
     KeepConnection = False
     Password = 'postgres'
     Transaction = SQLTransaction1
     UserName = 'postgres'
     HostName = '10.0.2.2'
     left = 444
     top = 12
   end
   object QueryMaster: TSQLQuery
     IndexName = 'DEFAULT_ORDER'
     Database = PQConnection1
     Transaction = SQLTransaction1
     ReadOnly = False
     SQL.Strings = (
       'SELECT *'
       'FROM asientos'
       'WHERE numejercicio = 1'
       ' AND numasiento = 13'
     )
     Params =
     left = 445
     top = 63
   end
   object QueryDetail: TSQLQuery
     IndexName = 'DEFAULT_ORDER'
     Database = PQConnection1
     Transaction = SQLTransaction1
     ReadOnly = False
     SQL.Strings = (
       'SELECT *'
       'FROM imputacionesasientos'
       'WHERE numejercicio = :numejercicio'
       ' AND numasiento = :numasiento'
       'ORDER BY numimputacion'
     )
     Params = <
       item
         DataType = ftUnknown
         Name = 'numejercicio'
         ParamType = ptUnknown
       end
       item
         DataType = ftUnknown
         Name = 'numasiento'
         ParamType = ptUnknown
       end>
     DataSource = SourceMaster
     left = 444
     top = 128
   end
   object SourceMaster: TDatasource
     DataSet = QueryMaster
     left = 376
     top = 63
   end
   object SourceDetail: TDatasource
     DataSet = QueryDetail
     left = 376
     top = 128
   end
   object SQLTransaction1: TSQLTransaction
     Active = False
     Action = caNone
     Database = PQConnection1
     left = 376
     top = 12
   end
procedure TForm1.FormCreate(Sender: TObject);
begin
   PQConnection1.Connected:=True;
   QueryMaster.Open;
   // Parameter property settings seems also broken in the best
dbExpress style!
   QueryDetail.Params.ParamByName('numejercicio').DataType:=ftSmallInt;
   QueryDetail.Params.ParamByName('numasiento').DataType:=ftLargeInt;
   QueryDetail.Open;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
   if QueryMaster.StatedsBrowse then
      QueryMaster.Post;
   if QueryDetail.StatedsBrowse then
      QueryDetail.Post;
   try
     QueryMaster.ApplyUpdates;
     QueryDetail.ApplyUpdates;
     SQLTransaction1.Commit;
   except
     SQLTransaction1.Rollback;
     raise;
   end;
end;
Ing. Julio C?sar G?zquez Mutual de Empleados del Banco Mitre 923 1? Piso - (S2000COS) Rosario Tel-Fax: 0341-4265010 411 0533

Reply by email

Michael Van Canneyt
to Julio César Gázquez
Julio C?sar G?zquez wrote 8 lines
Hi all. I have a master detail form, I'm using SQLDB and running a current snapshot (Lazarus-0.9.29 rev 28828). Retrieving data works Ok. Saving changes doesn't. Googling I found old comments in the mailing list saying primary keys must be integers. Is yet that the case? If it isn't, component declaration and relevant code follows.

Primary keys do not have to be integers.

Another issue, when the master have more than 1 record, if I edit the detail, then move around in the master, detail changes are lost. IIRC this works fine in dbExpress. It is a bug or a design limitation of sqldb?

This is because updates are cached by default.
You must save all updates (applyupdates) in the OnBeforeClose event of the detail dataset.

Michael.

Reply by email