--- Cyrus Durgin <[EMAIL PROTECTED]> wrote: > 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?
Patch below implements getting a file descriptor for a UNIX database using the existing sqlite3 API function sqlite3_file_control() and a new non-standard option SQLITE_FCNTL_FD. If the function succeeds SQLITE_OK is returned. Sample usage: // The second parameter to sqlite3_file_control is the database alias. // "main" is the default database alias. // If you ran the command "attach database 'test.db' as 'whatever';", // then "whatever" would be the second parameter. int fd = -1; if (SQLITE_OK == sqlite3_file_control(db, "main", SQLITE_FCNTL_FD, &fd)){ printf("\nSQLITE_FCNTL_FD = %d\n", fd); } Patch is OS dependent. To add Windows support, change winFileControl in os_win.c in the same way as unixFileControl below. _________________________________________________________________________ Index: src/os_unix.c =================================================================== RCS file: /sqlite/sqlite/src/os_unix.c,v retrieving revision 1.169 diff -u -3 -p -r1.169 os_unix.c --- src/os_unix.c 20 Sep 2007 10:02:54 -0000 1.169 +++ src/os_unix.c 10 Oct 2007 03:51:41 -0000 @@ -2018,6 +2018,10 @@ static int unixFileControl(sqlite3_file *(int*)pArg = ((unixFile*)id)->locktype; return SQLITE_OK; } + case SQLITE_FCNTL_FD: { + *(int*)pArg = ((unixFile*)id)->h; + return SQLITE_OK; + } } return SQLITE_ERROR; } Index: src/sqlite.h.in =================================================================== RCS file: /sqlite/sqlite/src/sqlite.h.in,v retrieving revision 1.266 diff -u -3 -p -r1.266 sqlite.h.in --- src/sqlite.h.in 3 Oct 2007 20:15:28 -0000 1.266 +++ src/sqlite.h.in 10 Oct 2007 03:51:42 -0000 @@ -557,6 +557,7 @@ struct sqlite3_io_methods { ** is defined. */ #define SQLITE_FCNTL_LOCKSTATE 1 +#define SQLITE_FCNTL_FD 64 /* ** CAPI3REF: Mutex Handle ____________________________________________________________________________________ Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------