Lazarus

Programming => Databases => Topic started by: TonyR500 on July 13, 2020, 09:53:55 am

Title: Problems with Deleting
Post by: TonyR500 on July 13, 2020, 09:53:55 am
Hi
I am having problems with deleting using DBNavigator. My lack of experience with Lazarus is contributing to the difficulty.

I am trying to rewrite a customer contact application that was originally done in Delphi (Delphi 7 I think).

I have a form on which there is a DBGrid, DBNavigator, SQLite3Connection, SQLTransaction,SQLQuery and DataSource. The database is SQLite with a single table.

I need to be able to select a record in the grid and delete when necessary also to add new customers as required.

In testing this I found that I could delete and insert and post with no problems using the Navigator buttons but, if I insert a new record and then follow this with a delete I get an error message: -

"An error occurred while applying the updates in SQLite3Connection. No delete query specified and failed to generate one. No field for inclusion in where statement"

It shows this without fail every time I follow a new record insertion with a delete.
I think it needs some code in either SQLQuery.AfterDelete or AfterInsert or elsewhere
but I don't know where and I don't know what.

Since users cannot be relied upon not to do this I have to fix it.

I would be glad of some help please.
AJR



Title: Re: PROBLEMS WITH DELETING
Post by: trev on July 14, 2020, 02:23:04 am
You might have a better response in the Databases sub-forum than here.
Title: Re: Problems with Deleting
Post by: skalogryz on July 14, 2020, 02:26:41 am
moved to "databases".
Replaced all caps title with a normal caps
Title: Re: Problems with Deleting
Post by: GetMem on July 14, 2020, 06:29:22 am
Hi TonyR500,
Quote
I am having problems with deleting using DBNavigator. My lack of experience with Lazarus is contributing to the difficulty.

I am trying to rewrite a customer contact application that was originally done in Delphi (Delphi 7 I think).

I have a form on which there is a DBGrid, DBNavigator, SQLite3Connection, SQLTransaction,SQLQuery and DataSource. The database is SQLite with a single table.

I need to be able to select a record in the grid and delete when necessary also to add new customers as required.

In testing this I found that I could delete and insert and post with no problems using the Navigator buttons but, if I insert a new record and then follow this with a delete I get an error message: -

"An error occurred while applying the updates in SQLite3Connection. No delete query specified and failed to generate one. No field for inclusion in where statement"

It shows this without fail every time I follow a new record insertion with a delete.
I think it needs some code in either SQLQuery.AfterDelete or AfterInsert or elsewhere
but I don't know where and I don't know what.

Since users cannot be relied upon not to do this I have to fix it.

I would be glad of some help please.
Please check the following thread: https://forum.lazarus.freepascal.org/index.php?topic=27642.0
Title: Re: Problems with Deleting
Post by: TonyR500 on July 14, 2020, 02:43:02 pm
Hi Thanks to all for responses.
Current situation is : -

I have been reading some previous posts on the same or very similar problem referred to me by GetMem. One of the responses to that problem was by ahiggins who suggested changing the SQLQuery.UpdateMode to upWhereAll (from upWhereChanged).

I thought this was worth a try
so I changed it. In my FormClose procedure I now have: -

  SQLQuery1.Edit;
  SQLQuery1.UpdateMode:=UpWhereAll;
  SQLQuery1.ApplyUpdates;
  SQLTransaction1.Commit;
  SQLQuery1.Close;
  SQLQuery1.Open; 
     
Previously the UpdateMode was upwherechanged
The result of making this change appears to be successful.   

The problem before was the error message when deleting after inserting. Now it seems I can insert and delete in any order without any errors appearing and the changes are all recorded in the database.

I have a lot more testing to do before I let this loose on users but at present it looks good.
I'll come back again if I get more problems.

Thanks once again to all.

TonyR500     
TinyPortal © 2005-2018