[yunqa.de] Re: Progress bar for vacuum, integrity check.

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Mon, 08 Dec 2008 12:52:42 +0100

Clyde England wrote:

>I am currently using DiSqlite3 with the object layer (TDISQLite3Database and 
>TDISQLite3Statement ) and not the API directly.
>
>I have a few reasonable sized databases that I like to vacuum and or check the 
>integrity from time to time.
>
>Both these operations can take a long time with large databases and there is 
>no visual clue of progress. What I want to do is provide a progress bar so I 
>can visually see how things are going.
>
>I suspect it requires interfacing with a callback function of some sort, but I 
>am having trouble coming to grips with this and how to implement.
>
>Is this possible? Example?

sqlite3_progress_handler() is available to set up a progress handler which will 
be called periodically while SQLite is busy. It works fine for VACUUM but is 
surprisingly not invoked when doing the integrity check. I have created an 
SQLite ticked asking to fix this.

Anyway, here is some example Delphi code for an incremental progress bar to 
indicate that the database is currently busy:

//------------------------------------------------------------------------------

function TfrmMain.VacuumDatabase(
  const AFileName: UnicodeString): UnicodeString;
var
  Database: TDISQLite3Database;
begin
  ProgressBar.Position := 0;

  Database := TDISQLite3Database.Create(nil);
  try
    Database.DatabaseName := AFileName;
    Database.Connected := True;
    sqlite3_progress_handler(
      Database.Handle, $400, DbProgressFunc, Self);

    Database.Execute('vacuum');
  finally
    Database.Free;
  end;
end;

//------------------------------------------------------------------------------

function DbProgressFunc(UserData: Pointer): Integer;
begin
  TfrmMain(UserData).DoProgress;
  Result := 0;
end;

//------------------------------------------------------------------------------

procedure TfrmMain.DoProgress;
var
  i: Integer;
begin
  i := ProgressBar.Position;
  Inc(i);
  if i > ProgressBar.Max then
    i := ProgressBar.Min;
  ProgressBar.Position := i;
  Application.ProcessMessages;
end;

//------------------------------------------------------------------------------

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: