Hi Richard,

All right, many thanks for that. So if I do, say, a SELECT just after opening 
the database, that's when the recovery will actually take place and the journal 
file will be replayed and deleted. 
Is my understanding correct?

Many thanks for your help!

Best regards,

  Fabrice

-----Original Message-----
From: Richard Hipp <d...@sqlite.org>
Sender: sqlite-users-bounces@sqlite.orgDate: Sat, 15 Feb 2014 08:07:57 
To: General Discussion of SQLite Database<sqlite-users@sqlite.org>
Reply-To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
Subject: Re: [sqlite] Question about how sqlite recovers after a power loss

On Fri, Feb 14, 2014 at 10:13 AM, <ftrib...@falcon-one.com> wrote:

> Hello,
>
> I would like to understand better at which moment does sqlite recovers
> from a previous power loss.
>
> Let's take the following scenario:
>  - sqlite3_open()
>  - BEGIN TRANSACTION;
>  - INSERT INTO SomeTable VALUES ("blah", "blah", blah");
>  => Power loss!
>  - sqlite3_open()
>
> What I notice, is that the 2nd sqlite3_open() succeeds, but the journal
> file is left intact and not deleted.
>
> I would like to know at what moment is the journal file actually deleted
> after a power loss.
>

When you first access the database.  sqlite3_open() does not actually open
the database file.  It just queues up the information.  The real open is
deferred until you actually try to read something out of the database.

The delay of open gives  the application time to run PRAGMA statements to
further setup the connection.  In particular, it allows the "key" PRAGMA to
run to set the encryption key for encrypted database files, which would
otherwise be unreadable.

-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to