Guest User

SQLite shared cache READONLY error

a guest
Aug 4th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include "sqlite3.h"
  2.  
  3. #include <stdio.h>
  4.  
  5. void init_db()
  6. {
  7.   sqlite3* db;
  8.   sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
  9.   sqlite3_exec(db, "CREATE TABLE test (a INTEGER);", 0, 0, 0);
  10.   sqlite3_close(db);
  11. }
  12.  
  13. void handle_result(const char* tag, int result)
  14. {
  15.   if (result != SQLITE_OK)
  16.     printf("%s - %d\n", tag, result);
  17. }
  18.  
  19. void insert(sqlite3* db)
  20. {
  21.   int result = sqlite3_exec(db, "INSERT INTO test VALUES (42);", 0, 0, 0);
  22.   handle_result("insert", result);
  23. }
  24.  
  25. void select(sqlite3* db)
  26. {
  27.   int result = sqlite3_exec(db, "SELECT * FROM test;", 0, 0, 0);
  28.   handle_result("select", result);
  29. }
  30.  
  31. int main()
  32. {
  33.   sqlite3_enable_shared_cache(1);
  34.   init_db();
  35.  
  36.   sqlite3* dbRead;
  37.   sqlite3_open_v2("test.db", &dbRead, SQLITE_OPEN_READONLY, 0);
  38.  
  39.   sqlite3* dbWrite;
  40.   sqlite3_open_v2("test.db", &dbWrite, SQLITE_OPEN_READWRITE, 0);
  41.  
  42.   select(dbRead);
  43.   insert(dbWrite);
  44.  
  45.   sqlite3_close(dbRead);
  46.   sqlite3_close(dbWrite);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment