[Solved] Greyhound and Firebird. lazarus / 16-Databases ---------------------------------------------------------------------- iru · 2022-03-18 03:56 Environment: Linux Mint 20 (all updates), LAZ 2.12 and FPC 3.2.2, greyhound-latest from LAZ, Firebird 3. Gentlefolk, I have a small application using 'greyhound' to access a small embedded firebird database. I have some code which deletes an entry in a table. Works well except when there is only ONE record in the table and then an error occurs. An exception ':Field ID is required, but not supplied' occurs. The table has a field 'ID' which contains a firebird generated numeric value to make the record unique. The code is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    EventData : TghSQLTable;     EventData := UG.Co.Tables['"EVENTDATA"'].Open;    EventData.Constraints.Clear;    EventData.Constraints.AddUnique(['ID']);     EventData.Edit;    EventData['ID'].AsLongInt := StrToInt(ModSGEvent.Cells[0, InOffset]); <-- Loads saved numeric 'ID'     // Note: The saved ID equals the value of record ID in the table.                                                                                                               EventData.Edit;    EventData.Delete;     EventData.Edit;    EventData.Post; <------- Error occurs here.    EventData.Commit;    Any suggestions, ideas, help??? Ian.                      [Edited to add code tags - please read How to use the Forums.] ---------------------------------------------------------------------- dseligo · 2022-03-18 09:00 What is purpose of those 'Edit' statements in lines 12 and 15? Try without them. ---------------------------------------------------------------------- dseligo · 2022-03-18 09:06 To explain a bit more. I don't think that row needs to be in 'edit' or 'insert' state to delete it. Error happens because you delete last row and then you try to put it in 'edit' state in line 15. There is no rows and you try to edit them, hence the error. You must use 'insert' if you want to add new row. ---------------------------------------------------------------------- iru · 2022-03-18 10:51 Thank you for the response. If I remove the line 12 EventData.Edit no impact/change. If I remove line 15 the process crashes with an exception EDataBaseError: Operation not allowed, "" is not in an edit or insert state. With line 15 in the code the original error ':Field ID is required, but not supplied' occurs'. We battle on.... Ian. ---------------------------------------------------------------------- dseligo · 2022-03-18 10:55 Oh, I am sorry. Remove line 16 as well. When you delete record, you don't have to post it. ---------------------------------------------------------------------- iru · 2022-03-18 11:19 Thank you, that solved the problem!!!!! Strange that with the 'post' in the code the error only occurred when there was only one record in the table.... Regards, Ian. ---------------------------------------------------------------------- dseligo · 2022-03-18 11:28 Quote from: iru on March 18, 2022, 12:19:25 pmStrange that with the 'post' in the code the error only occurred when there was only one record in the table.... That's because when you deleted e.g. row 2, 'cursor' automatically moved to some other existing row (e.g. row 1). After that you issued edit, changed nothing, and posted. Since nothing changed, you didn't noticed, and Firebird didn't complain since the row existed.