Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top