Reputation: 427
sqlite3_prepare function fails if DB is opened with SQLITE_OPEN_READONLY.
Error message: error #10: disk I/O error
Sqlite extended error code: SQLITE_IOERR_LOCK (3850)
Errno: EBADF 9 /* Bad file number */
Everything works fine if DB is opened with SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
SQLITE_OPEN_FULLMUTEX;
Any ideas on what may cause this problem?
rc=sqlite3_open_v2("example.db",&db,SQLITE_OPEN_READONLY,0);
sqlite3_busy_timeout(db,1000);
selectQuery = "select * from test;";
rc = sqlite3_prepare(db, selectQuery, strlen(selectQuery), &stmt, 0);
if(rc!=SQLITE_OK)
{
printf("sql error #%d: %s", rc, sqlite3_errmsg(db));
printf( "SQL ext error: %d\n", sqlite3_extended_errcode(db));
printf( "errno: %d\n", errno );
}
Upvotes: 0
Views: 591
Reputation: 427
The problem is in OS lock implementation. Fcntl() doesn't allow to lock file if it is opened with read only permissions. As a result - SQLite can't do anything in read only mode.
Upvotes: 1