On Fri, Sep 10, 2010 at 12:09:58PM -0700, Josh scratched on the wall:
> Hello all,
> 
> I think this is a simple question...
> 
> I am using the C api to open and read/write a SQLite database (ie. 
> sqlite3_open_v2() etc.). I would like to have a function in my program to 
> backup the database file (using the OSes copy command).

  You might also be able to use the backup APIs.

  See:  http://sqlite.org/c3ref/backup_finish.html

> I can guarentee 
> that my program will not write to the database. Do I need to sync or lock 
> the database file before I do the copy command?

  That would be a good idea.

> I believe that as long as 
> I have no open write transactions the file should be fine to copy, is this 
> correct?

  No, not exactly.  Transactions are normally lazy about getting locks.
  To force the transaction to get the locks, issue the command:

    BEGIN EXCLUSIVE

  If that works, you know nobody else can touch the database.  You're
  then free to copy it.  Once the copy is done, you can rollback the
  transaction.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to