0

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 );
} 
1
  • Does this DB use WAL? What file system? Commented Jan 6, 2015 at 9:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.