[yunqa.de] Re: How to save in-memory DB?

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Mon, 31 May 2010 17:49:26 +0200

At 14:54 31.05.2010, Gregory Whitesides wrote:

>  { create in-memory DB }
>  FDb := TDISQLite3Database.Create(nil);
>  try
>    FDb.DatabaseName := ':memory:'; 
>    FDb.CreateDatabase;
>    FDb.Execute16('PRAGMA locking_mode=exclusive');
>    FDb.Execute16('PRAGMA synchronous=off');
>    FDb.Execute16(SQL_CREATE_DB);
>  except
>    //...
>  end;
>
>  // ... Filling the DB with data
>
>How to save this DB to local disk? 

With DISQLite3 Pro, you can save in-memory databases to file using the online 
backup API as described here:

  DISQLite3 Help -> SQLite3 Documentation -> Online Backup

A backup operation involves the following functions:

1. sqlite3_backup_init() is called once to initialize the backup,

2. sqlite3_backup_step() is called one or more times to transfer the data 
between the two databases, and finally

3. sqlite3_backup_finish() is called to release all resources associated with 
the backup operation.

There is an example project to backup a file database in

  DISQLite3_Install\Demos\DISQLite3_Backup\

You can easily reuse this code to save your memory database to disk.

Ralf

PS: The online backup API is unavailable in DISQLite3 Personal.  

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



Other related posts: