sqlite3 one_file VFS失败 [英] sqlite3 one_file VFS Fails

查看:121
本文介绍了sqlite3 one_file VFS失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 sqlite3 VFS示例运行test_onefile.c示例,我得到了失败以下:

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.

我正在运行以下代码:

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);

失败的文件是sampledb.sqlite2-wal,显然不是日志文件.但是,我不知道它是如何达到的.

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.

推荐答案

test_onefile.c实现的VFS很旧,因此不支持WAL模式所需的其他文件.

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

要使其与现代SQLite一起使用,fsDelete函数应只忽略删除-wal-shm文件的尝试.

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

这篇关于sqlite3 one_file VFS失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆