Subject | Re: [IBO] TIBOQuery Problem |
---|---|
Author | Svein Erling Tysvær |
Post date | 2019-03-27T08:37:22Z |
This program simply starts deleting records from the front of a table. However, it gets intermittent errors saying it cannot find the row to delete even though there may be hundreds of rows left in the table. The table does not have a primary key.
The code contains a comment section showing the DDL for the table and a button to put 4 rows into the table. If you start with an empty table and put 4 rows into the table, then click the 'Go' button, the failure likely will occur trying to delete the first row. If you close the program after adding the 4 rows, restart the program and click 'Go', it will usually correctly delete all 4 rows. With many rows in the table, it will delete some rows and then get the error.
I have tried using a refresh after each delete, but it still fails.
I am using ibo5_10_1_b2808_Source and Embarcadero 10.3 Studio.
[code]
unit Delete;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IB_Components, IB_Access, IBODataset,
Data.DB, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Query2: TIBOQuery;
DB: TIBODatabase;
Button2: TButton;
Query: TIBOQuery;
QueryNUMBER: TIntegerField;
QueryENTERED: TDateTimeField;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ DDL for table 'Stuff'
CREATE TABLE Stuff
(
NUMBER INTEGER NOT NULL,
ENTERED TIMESTAMP NOT NULL
);
}
procedure TForm1.Button2Click(Sender: TObject);
var Idx: integer;
TS: TDateTime;
begin
Query.Filtered := false;
Query.Open;
for Idx := 1 to 3 do
begin
Query.Append;
QueryNUMBER.Value := Idx;
QueryENTERED.Value := Now;
Query.Post;
end;
// Duplicate record
TS := QueryENTERED.Value;
Query.Append;
QueryNUMBER.Value := 3;
QueryENTERED.Value := TS;
Query.Post;
ShowMessage('Added 4 rows to table.');
end;
procedure TForm1.Button1Click(Sender: TObject);
var Last_Number: integer;
begin
Query.First;
Last_Number := 0;
while not Query.Eof do
begin
if QueryNUMBER.Value = Last_Number then
begin
ShowMessage('Deleting Duplicate #' + QueryNUMBER.AsString);
Query.Delete;
continue;
end;
ShowMessage('Deleting # ' + QueryNumber.AsString);
Query.Delete;
end;
end;
end.[/code]