sqlite3 one_file VFS失败
我试图从sqlite3 VFS示例运行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
,显然不是日志文件。 但是,我不明白它是如何实现的。
Edit2:嗯,删除源文件中的断言后:
assert(strcmp("-journal", &zPath[nName])==0);
代码似乎有效。 但是,我不是断言断言的忠实粉丝,因为很明显它会导致一些意想不到的行为。 作者有理由使用断言。
test_onefile.c
实现的VFS很旧,因此不支持WAL模式所需的其他文件。
为了使它适用于现代SQLite, fsDelete
函数应该忽略删除-wal
或-shm
文件的尝试。