BDE, cache update, Interbase, validation error for column [long] 
Author Message
 BDE, cache update, Interbase, validation error for column [long]

i'm using cache update

in  OnUpdateError  i intercept the server error for showing a custom message

the problem is that i get two times the same error and that's
because OnUpdateRecord is called two times althought in cache there is still
one
record

How is it possible ?
What's i'm missing ?

As follow i post some code

*****************************************************************

+++++++++++++ code in DataModule +++++++++++++

procedure TdtmdDatiPartite.DPartiteDataChange(Sender: TObject; Field:
TField);
begin
   if dtsrcPartite.DataSet.State = dsBrowse then begin

      (Owner as TfrmPartite).AggiornaCampi;  // refresh form's Edit

      //
      // set some property's form
      //
      (Owner as TfrmPartite).Idx_Clienti :=
         dtsrcPartite.DataSet.FieldByName('IDX_CLIENTI').AsInteger;
      (Owner as TfrmPartite).Idx_ArticoloCliente :=
         dtsrcPartite.DataSet.FieldByName('IDX_ANAGCOMPCLI').AsInteger;
      (Owner as TfrmPartite).Idx_ColoreCliente :=

dtsrcPartite.DataSet.FieldByName('IDX_ANAGCOLORICOMPCLI').AsInteger;
      (Owner as TfrmPartite).Idx_Fornitori :=
         dtsrcPartite.DataSet.FieldByName('IDX_FORNITORI').AsInteger;
      (Owner as TfrmPartite).Idx_ArticoloFornitore :=
         dtsrcPartite.DataSet.FieldByName('IDX_ANAGCOMPFOR').AsInteger;
      (Owner as TfrmPartite).Idx_ColoreFornitore :=

dtsrcPartite.DataSet.FieldByName('IDX_ANAGCOLORICOMPFOR').AsInteger;
   end;
end;

{---------------------------------------------------------------------------
---}

procedure TdtmdDatiPartite.qryPartiteUpdateRecord(DataSet: TDataSet;
  UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
begin
   if UpdateKind = ukInsert then begin

     //
     // get and set primary key
     //
     strdprcNew_Idx_Partite.ExecProc;
      DataSet.FieldByName('IDX').NewValue :=
         strdprcNew_Idx_Partite.ParamByName('NEW_IDX').Value;
   end;
   Self.UpdateSQLPartite.Apply(UpdateKind);
   UpdateAction := uaApplied;
end;

{---------------------------------------------------------------------------
---}

procedure TdtmdDatiPartite.qryPartiteBeforePost(DataSet: TDataSet);
var
  i : integer;

begin
   for i := 0 to (DataSet.FieldCount) - 1 do begin
      if DataSet.Fields[i].AsString = '' then
         DataSet.Fields[i].Clear;
   end;
end;

{---------------------------------------------------------------------------
---}

procedure TdtmdDatiPartite.UpdateMyDBase;
begin
   qryPartite.Database.StartTransaction;
   try
      qryPartite.ApplyUpdates;
      qryPartite.Database.Commit;
   except
      qryPartite.Database.Rollback;

      (Owner as TfrmPartite).dbgrdPartite.DataSource.DataSet.Edit;  // maybe
qryPartite.Edit is better

      (Owner as TfrmPartite).pgctrlDatiPartite.ActivePageIndex := 0;
      (Owner as TfrmPartite).edtCodicePartita.SetFocus;
   end;
   qryPartite.CommitUpdates;
end;

{---------------------------------------------------------------------------
---}

procedure TdtmdDatiPartite.qryPartiteBeforeScroll(DataSet: TDataSet);
begin
   if not (DataSet.State = dsInsert) then begin
      UpdateMyDBase;
   end;
end;

{---------------------------------------------------------------------------
---}

procedure TdtmdDatiPartite.qryPartiteUpdateError(DataSet: TDataSet;
  E: EDatabaseError; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
var
   i : integer;

begin
   if E is EDBEngineError then begin
      for i:=0 to (E as EDBEngineError).ErrorCount - 1 do begin
         case (E as EDBEngineError).Errors[i].NativeError of

           - 803 : begin
                      frmMyMessageDlg('Errore' , 'Codice gi inserito',
mtError, [mbOk], mrOk, 0);
                   end;

           - 625 : begin
                         frmMyMessageDlg('Errore' , 'Inserire tutti i campi
obbligatori', mtError, [mbOk], mrOk, 0);
                      end;
           else begin
                  frmMyMessageDlg('Errore',
                     'Numbers of errors: ' + IntToStr((E as
EDBEngineError).ErrorCount) + #13#10 +
                     'Message: ' + (E as EDBEngineError).Errors[i].Message +
#13#10 +
                     'Category: ' + IntToStr((E as
EDBEngineError).Errors[i].Category) + #13#10 +
                     'Error Code: ' + IntToStr((E as
EDBEngineError).Errors[i].ErrorCode) + #13#10 +
                     'Sub Code: ' + IntToStr((E as
EDBEngineError).Errors[i].SubCode) + #13#10 +
                     'Native Error: ' + IntToStr((E as
EDBEngineError).Errors[i].NativeError), mtError,
                      [mbOk], mrOk, 0);
           end
         end;
      end;
   end
   else begin
       frmMyMessageDlg('Errore' , E.Message, mtError, [mbOk], mrOk, 0);
   end;

   UpdateAction := uaAbort;
end;

+++++++++++++  code in Form  +++++++++++++

procedure TfrmPartite.DataSetInsertPartiteExecute(Sender: TObject);
begin
    dbgrdPartite.DataSource.DataSet.Append;
end;

{---------------------------------------------------------------------------
---}

procedure TfrmPartite.DataSetPostPartiteExecute(Sender: TObject);
begin

   //
   // setting dataset
   //
   dtmdDatiPartite.qryPartiteCODICEPARTITA.AsString :=
edtCodicePartita.Text;

   if  Idx_Clienti = 0 then begin
       //
       // during my test i force it to ''
       // so in  OnBeforePost i get a NULL value
       //
      dtmdDatiPartite.qryPartiteIDX_CLIENTI.AsString := '';
   end
   else begin
      dtmdDatiPartite.qryPartiteIDX_CLIENTI.AsInteger := Idx_Clienti;
   end;

   if Idx_ArticoloCliente = 0 then begin
      dtmdDatiPartite.qryPartiteIDX_ANAGCOMPCLI.AsString := '';
   end
   else begin
      dtmdDatiPartite.qryPartiteIDX_ANAGCOMPCLI.AsInteger :=
Idx_ArticoloCliente;
   end;

   if Idx_ColoreCliente = 0 then begin
      dtmdDatiPartite.qryPartiteIDX_ANAGCOLORICOMPCLI.AsString := '';
   end
   else begin
      dtmdDatiPartite.qryPartiteIDX_ANAGCOLORICOMPCLI.AsInteger :=
Idx_ColoreCliente;
   end;

   dtmdDatiPartite.qryPartiteCOTTA.AsString := edtCottaInterna.Text;
   dtmdDatiPartite.qryPartiteIDX_FORNITORI.AsInteger := FIdx_Fornitore;
   dtmdDatiPartite.qryPartiteIDX_ANAGCOMPFOR.AsInteger :=
FIdx_ArticoloFornitore;
   dtmdDatiPartite.qryPartiteIDX_ANAGCOLORICOMPFOR.AsInteger :=
FIdx_ColoreFornitore;
   dtmdDatiPartite.qryPartiteCOTTAFORNITORE.AsString :=
edtCottaFornitore.Text;
   dtmdDatiPartite.qryPartiteSTATUS.AsInteger   :=
rdgrpStatoPartita.ItemIndex;
   dtmdDatiPartite.qryPartiteNUMMAC.AsString    := ComprStr(ENumMac.Text);
   dtmdDatiPartite.qryPartitePRIORITA.AsString  := ComprStr(EPriorita.Text);
   dtmdDatiPartite.qryPartiteALTEZZA.AsFloat         :=
StrToFloat(ComprStr(edtHMin.Text));
   dtmdDatiPartite.qryPartiteMETRIPROVA.AsFloat      :=
StrToFloat(ComprStr(EMetriProva.Text));
   dtmdDatiPartite.qryPartiteSCRIVICIMOSSA.AsInteger :=
Ord(chkbxInserimentoCimossa.Checked);
   dtmdDatiPartite.qryPartiteANNOTA.AsString  := EAnnota.Text;
   dtmdDatiPartite.qryPartiteNOTE.AsString    := ENote.Text;

   dtmdDatiPartite.qryPartiteRIFDDT.AsString := ERifDDT.Text;
    //
    // end setting dataset
    //

   dtmdDatiPartite.UpdateMyDBase;
end;

*********************************************************

as follow i post the Call Stack since the Save button is cliccked
to the first OnUpdateRecord

TdtmdDatiPartite.qryPartiteUpdateRecord($B1FD4C,ukInsert,uaFail)
TBDEDataSet.CachedUpdateCallBack($B31584)
TBDECallback.Invoke(cbDELAYEDUPD,$B31584)
BdeCallBack(cbDELAYEDUPD,11767192,$B31584)
TBDEDataSet.ProcessUpdates(dbiDelayedUpdPrepare)
TBDEDataSet.ApplyUpdates
TdtmdDatiPartite.UpdateMyDBase
TfrmPartite.DataSetPostPartiteExecute(???)

going on in the execution the first exeception is raised

DbiError(9732)
Check(9732)
TQuery.GetQueryCursor(False)
TQuery.CreateCursor(False)
TQuery.ExecSQL
TUpdateSQL.ExecSQL(ukInsert)
TUpdateSQL.Apply(ukInsert)
TdtmdDatiPartite.qryPartiteUpdateRecord(???,???,uaFail)

going on in the execution the OnUpdateError is called the first time

TdtmdDatiPartite.qryPartiteUpdateError(???,$B3F338,ukInsert,uaFail)
TBDEDataSet.CachedUpdateCallBack($B31584)
TBDECallback.Invoke(cbDELAYEDUPD,$B31584)
BdeCallBack(cbDELAYEDUPD,11767192,$B31584)
TBDEDataSet.ProcessUpdates(dbiDelayedUpdPrepare)
TBDEDataSet.ApplyUpdates
TdtmdDatiPartite.UpdateMyDBase
TfrmPartite.DataSetPostPartiteExecute(???)

going on in the execution the OnUpdateErorr is called again
and that's make me crazy :((((

TdtmdDatiPartite.qryPartiteUpdateRecord($B1FD4C,ukInsert,uaFail)
TBDEDataSet.CachedUpdateCallBack($B31584)
TBDECallback.Invoke(cbDELAYEDUPD,$B31584)
BdeCallBack(cbDELAYEDUPD,11767192,$B31584)
TBDEDataSet.ProcessUpdates(dbiDelayedUpdCommit)
TBDEDataSet.CommitUpdates
TdtmdDatiPartite.UpdateMyDBase
TfrmPartite.DataSetPostPartiteExecute(???)

Any suggestion would be appreciate

Tahnks in advance,
Stefano Campri



Tue, 06 Dec 2005 02:52:44 GMT  
 BDE, cache update, Interbase, validation error for column [long]
Sorry !

I'm just a stupid man : i was missing a raise

Quote:

> procedure TdtmdDatiPartite.UpdateMyDBase;
> begin
>    qryPartite.Database.StartTransaction;
>    try
>       qryPartite.ApplyUpdates;
>       qryPartite.Database.Commit;
>    except
>       qryPartite.Database.Rollback;

>       (Owner as TfrmPartite).dbgrdPartite.DataSource.DataSet.Edit;  //
maybe
> qryPartite.Edit is better

>       (Owner as TfrmPartite).pgctrlDatiPartite.ActivePageIndex := 0;
>       (Owner as TfrmPartite).edtCodicePartita.SetFocus;

----->  here i was missing a raise

Quote:
>    end;
>    qryPartite.CommitUpdates;
> end;

Greetings,
Stefano Campri


Fri, 09 Dec 2005 03:17:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Operation Aborted (TQuery, SQL, Cached Updates) - Bit Long -

2. Cached Updates QUESTION: Sorting table of updated and non-updated records

3. Cached updates, Delphi, InterBase, NT3.51

4. Interbase components and cached updates

5. Problem with Delphi 2.0, Interbase and cached updates

6. Cached Updates - How to find row in error

7. Cached Updates; Identifying the row causing the error

8. Cached Updates Error???

9. Which record caused an error using cached updates?

10. BDE uses Paradox for handling cached updates?!

11. Prob: Cached updates and OldValue Method corrupts BDE buffers

12. Bug with BDE / Cached Updates

 

 
Powered by phpBB® Forum Software