Recent

Author Topic: Problems with Deleting  (Read 556 times)

TonyR500

  • New Member
  • *
  • Posts: 11
Problems with Deleting
« 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



« Last Edit: July 14, 2020, 02:25:45 am by skalogryz »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1265
  • Former Delphi 1-7, 10.2 User
Re: PROBLEMS WITH DELETING
« Reply #1 on: July 14, 2020, 02:23:04 am »
You might have a better response in the Databases sub-forum than here.
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48688  macOS 11.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2558
    • havefunsoft.com
Re: Problems with Deleting
« Reply #2 on: July 14, 2020, 02:26:41 am »
moved to "databases".
Replaced all caps title with a normal caps
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

GetMem

  • Hero Member
  • *****
  • Posts: 3858
Re: Problems with Deleting
« Reply #3 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

TonyR500

  • New Member
  • *
  • Posts: 11
Re: Problems with Deleting
« Reply #4 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