Recent

Author Topic: TSQlite3Dataset doesn't raise exception when "database disk image is malformed"  (Read 2593 times)

swierzbicki

  • Full Member
  • ***
  • Posts: 177
Hello,

I have an issue with an SQLite 3 database. This database was corrupted but my function doesn't raise an exception when calling an PRAGMA Intigrity check.
Is this expected ?

The code bellow :

Code: [Select]
function TdtmMain.CleanSQLiteDatabase(const ADatabaseName: string): string;
var
  ASQLiteConnection: TSqlite3Dataset;

begin
  if not FileExists(ADatabaseName) then
    exit;
  Result := '';

  ASQLiteConnection := TSqlite3Dataset.Create(nil);
  try
    ASQLiteConnection.FileName := ADatabaseName;
    ASQLiteConnection.ExecSQL('BEGIN TRANSACTION;');
    try
     ASQLiteConnection.ExecSQL('PRAGMA integrity_check;'); //<--- exception should be raised here
      ASQLiteConnection.ExecSQL('VACUUM;');
      ASQLiteConnection.ExecSQL('REINDEX;');
      ASQLiteConnection.ExecSQL('COMMIT;');
      Result := '';
    except
      on e: Exception do
      begin
        if Assigned(frmSplash) then
          frmSplash.lblSynchroError.Caption := e.Message;
          ASQLiteConnection.ExecSQL('ROLLBACK');
      end;
    end;
  finally
    ASQLiteConnection.Free;
  end;
end;   
       
« Last Edit: November 28, 2014, 01:50:37 pm by swierzbicki »
Lazarus 1.6.2
fpc 3.0.0
wince/win32/win64
delphi berlin

swierzbicki

  • Full Member
  • ***
  • Posts: 177
This is a real problem ! Is it worth to submit this ?
Lazarus 1.6.2
fpc 3.0.0
wince/win32/win64
delphi berlin

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Are you sure about the exception?
PRAGMA integrity_check returns results if errors found and is not able to find all kind of errors
ref: [ http://www.sqlite.org/pragma.html#pragma_integrity_check ]
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
PRAGMA integrity_check returns rows, so you should do

ASQLiteConnection.Close;
ASQLiteConnection.SQL = 'PRAGMA integrity_check';
ASQLiteConnection.Open;
//verify the returned records

 

TinyPortal © 2005-2018