Using Delete on Filtered TLiteTable is deleting ALL records in the table.

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jodyatfsec
Posts: 8
Joined: Wed 06 Nov 2013 13:41

Using Delete on Filtered TLiteTable is deleting ALL records in the table.

Post by jodyatfsec » Mon 24 Nov 2014 18:10

Last week I updated from LiteDac Standard to LiteDac Professional because I need to use encryption. I am using Delphi XE5. I updated Delphi at the same time since LiteDac Professional required the Delphi update. In program code that was previously running OK, I am now having trouble using TLitetable.Delete. When a table is filtered, it used to delete only the filtered records. Now it is deleting all the records. When I run code like the following then later open this table using a different TLiteTable component, the records have all been deleted. This looks like a bug to me.

example
with Search.ResTblLite do begin
Active := False;
TableName := RESTableName;
MasterFields := '';
IndexFieldNames := '';
Active := True;
Filter := 'PROJ_ID = ' + IntToStr(Global.Proj_ID);
Filtered := true;
First;
//I want it to delete old FILTERED records for this project
while not EOF do
delete;
end;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Using Delete on Filtered TLiteTable is deleting ALL records in the table.

Post by AlexP » Tue 25 Nov 2014 09:46

Hello,

We cannot reproduce the problem on the latest LiteDAC version 2.14.12. The code below works correctly, please modify this code so that the problem can be reproduced and send it to us:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, LiteAccess;

var
  LiteConnection: TLiteConnection;
  LiteTable: TLiteTable;
begin
  LiteConnection := TLiteConnection.Create(nil);
  try
    LiteConnection.ConnectString := 'Data Source=:memory:;LoginPrompt=False';
    LiteConnection.Connect;
    LiteConnection.ExecSQL( 'CREATE TABLE EMP (' + #13#10 +
                            'EMPNO INTEGER NOT NULL,' + #13#10 +
                            'ENAME VARCHAR(10),' + #13#10 +
                            'JOB VARCHAR(9),' + #13#10 +
                            'MGR INTEGER,' + #13#10 +
                            'HIREDATE TIMESTAMP,' + #13#10 +
                            'SAL REAL,' + #13#10 +
                            'COMM REAL,' + #13#10 +
                            'DEPTNO INT,' + #13#10 +
                            'PRIMARY KEY (EMPNO));' + #13#10 +
                            'INSERT INTO EMP VALUES (7369,''SMITH'',''CLERK'',7902,''1980-12-17'',800,NULL,20);' + #13#10 +
                            'INSERT INTO EMP VALUES (7499,''ALLEN'',''SALESMAN'',7698,''1981-2-20'',1600,300,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7521,''WARD'',''SALESMAN'',7698,''1981-2-22'',1250,500,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7566,''JONES'',''MANAGER'',7839,''1981-4-2'',2975,NULL,20);' + #13#10 +
                            'INSERT INTO EMP VALUES (7654,''MARTIN'',''SALESMAN'',7698,''1981-9-28'',1250,1400,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7698,''BLAKE'',''MANAGER'',7839,''1981-5-1'',2850,NULL,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7782,''CLARK'',''MANAGER'',7839,''1981-6-9'',2450,NULL,10);' + #13#10 +
                            'INSERT INTO EMP VALUES (7788,''SCOTT'',''ANALYST'',7566,''1987-7-13'',3000,NULL,20);' + #13#10 +
                            'INSERT INTO EMP VALUES (7839,''KING'',''PRESIDENT'',NULL,''1981-11-17'',5000,NULL,10);' + #13#10 +
                            'INSERT INTO EMP VALUES (7844,''TURNER'',''SALESMAN'',7698,''1981-9-8'',1500,0,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7876,''ADAMS'',''CLERK'',7788,''1987-7-13'',1100,NULL,20);' + #13#10 +
                            'INSERT INTO EMP VALUES (7900,''JAMES'',''CLERK'',7698,''1981-12-3'',950,NULL,30);' + #13#10 +
                            'INSERT INTO EMP VALUES (7902,''FORD'',''ANALYST'',7566,''1981-12-3'',3000,NULL,20);' + #13#10 +
                            'INSERT INTO EMP VALUES (7934,''MILLER'',''CLERK'',7782,''1982-1-23'',1300,NULL,10);');
    LiteTable := TLiteTable.Create(nil);
    try
      LiteTable.Connection := LiteConnection;
      LiteTable.TableName := 'EMP';
      LiteTable.Options.QueryRecCount := True;
      LiteTable.Open;
      Writeln(Format('Record Count Before Delete: %d',[LiteTable.RecordCount]));
      LiteTable.Filter := 'DEPTNO = 10';
      LiteTable.Filtered := True;
      Writeln(Format('Filtered Record Count: %d',[LiteTable.RecordCount]));
      while not LiteTable.Eof do
        LiteTable.Delete;
      LiteTable.Filtered := False;
      Writeln(Format('Record Count After Delete: %d',[LiteTable.RecordCount]));
    finally
      LiteTable.Free;
    end;
  finally
    LiteConnection.Free;
    readln;
  end;
end.

jodyatfsec
Posts: 8
Joined: Wed 06 Nov 2013 13:41

Re: Using Delete on Filtered TLiteTable is deleting ALL records in the table.

Post by jodyatfsec » Fri 05 Dec 2014 15:00

I installed the latest update and everything is working fine now. Thank you.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Using Delete on Filtered TLiteTable is deleting ALL records in the table.

Post by AlexP » Mon 08 Dec 2014 07:45

Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.

Post Reply