sqlite3 one_file VFS Fails

随声附和 提交于 2019-12-24 11:55:28

问题


I was trying to run test_onefile.c example from sqlite3 VFS examples, and I get the following failure:

test_onefile: test_onefile.c:693: fsDelete: Assertion `strpcmp("-journal", &zPath[nName])==0' failed.

I'm running the code as follows:

int retval;
fs_register();
int q_cnt = 5,q_size = 150,ind = 0;
char **queries = (char**) malloc(sizeof(char) * q_cnt * q_size);


sqlite3_stmt *stmt;
sqlite3 *handle;

retval =  sqlite3_open_v2( "sampledb.sqlite2", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE , "fs");       


  if(retval)
  {
      printf("Database connection failed\n");
      return -1;
  }
  printf("Connection successful\n");

  // Create the SQL query for creating a table
  char create_table[100] = "CREATE TABLE IF NOT EXISTS users (uname TEXT,pass TEXT NOT NULL,activated INTEGER)";

  // Execute the query for creating the table
  retval = sqlite3_exec(handle,create_table,0,0,0);

  // Insert first row and second row
  queries[ind++] = "INSERT INTO users VALUES('manish','mani',1)";
  retval = sqlite3_exec(handle,queries[ind-1],0,0,0);
  queries[ind++] = "INSERT INTO users VALUES('mehul','pulsar',0)";
  retval = sqlite3_exec(handle,queries[ind-1],0,0,0);

Edit: The file it fails on is sampledb.sqlite2-wal, clearly not a journal file. However, I don't understand how it reached it.

Edit2: Well, after removing the assertion in source file:

assert(strcmp("-journal", &zPath[nName])==0);

The code seems to work. However, I'm not a big fan of assertion deletion, as clearly it would lead to some unexpected behavior. The author had a reason to use the assertion.


回答1:


The VFS implemented by test_onefile.c is quite old, and therefore does not support the additional files required for WAL mode.

To make it work with a modern SQLite, the fsDelete function should just ignore attempts to delete -wal or -shm files.



来源:https://stackoverflow.com/questions/21279831/sqlite3-one-file-vfs-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!