Two approaches - use sqlite, or use OS code.

Use proper filesystem synchronization as appropriate for the given OS &
filesystem, where you guarantee that your db copy is the only one that
holds an exclusive lock.  Then do the file copy and release the lock.

The better approach, IMHO would be to create a new database with the
same schema, attach it to the existing db instance, and copy over the
data using transactions, then detach it.  This way, you've got access to
the original database and the database copy has a consistent,
thread-safe view of the data in the original.  Additionally, my guess
would be the copy would be vacuumed, which if you're using the copy for
backup purposes is great since it saves on disk space.

Cyrus Durgin wrote:
Maybe it would help to state my use case: without this functionality, what
is the proper way to copy a database using the C API without introducing a
race condition?

On 10/9/07, Robert Simpson <[EMAIL PROTECTED]> wrote:
-----Original Message-----
From: Cyrus Durgin [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 09, 2007 5:02 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] how to get file handle from sqlite3 object?

i'm wondering if there's a "standard" way to get an open file
handle from an
sqlite3 pointer using the C API.  anyone know?

There's no public way to get this, nor should there be.  The internal
implementation of the database should be kept separate from the logical
API
to access it.  Such a function would muddy the water between
implementation
and interface and hamper the ability to change the implementation without
changing the interface.

Not all filesystems would be able to return one, nor could it guarantee
that
the database is in fit state for someone to fiddle with its internal
handle.
Furthermore, it could not be guaranteed that once a caller obtained the
handle that the caller might then do something damaging to it or alter its
state.

Such a function definitely falls into the BAD IDEA category, IMO.

Robert




-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]

-----------------------------------------------------------------------------






-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to