gpt4 book ai didi

c - sqlite3 one_file VFS 失败

转载 作者:太空宇宙 更新时间:2023-11-04 03:50:14 24 4
gpt4 key购买 nike

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

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,显然不是日志文件。但是,我不明白它是如何达到的。

编辑2:那么,在删除源文件中的断言之后:

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

代码似乎有效。但是,我不是断言删除的忠实拥护者,因为它显然会导致一些意外行为。作者有理由使用该断言。

最佳答案

test_onefile.c 实现的 VFS 比较老,因此不支持 WAL 模式所需的附加文件。

为了让它与现代 SQLite 一起工作,fsDelete 函数应该忽略删除 -wal-shm 文件的尝试。

关于c - sqlite3 one_file VFS 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com