2014-01-22 36 views
1

我試圖從sqlite3 VFS examples運行test_onefile.c例子,我得到以下故障:sqlite3的one_file VFS失敗

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

的代碼似乎工作。然而,我並不是斷言刪除的忠實粉絲,顯然這會導致一些意想不到的行爲。作者有理由使用該斷言。

+0

可能會讓你斷言你的比較失敗(不匹配兩個字符串)。所以它從這一點上打破了執行。 –

+0

不是。確切的代碼適用於默認的VFS和演示VFS。它斷言失敗,因爲它試圖刪除一個'-wal'文件。 – Mattan

回答

1

test_onefile.c實施的VFS相當陳舊,因此不支持WAL模式所需的附加文件。

爲了使它適用於現代SQLite,fsDelete函數應該忽略嘗試刪除-wal-shm文件。

+0

有沒有辦法從C api中禁用沃爾瑪模式?我確定默認'WAL'模式被禁用。只有日記文件,我很好。爲了直接讀取/寫入裸設備(假設每個分區有一個分區),我沒有使用底層vfs(使用fs調用),我對'test_onefile.c'進行了更改。到目前爲止,沒有斷言,它似乎工作正常。不過,我有一種感覺,那些文件('wal','shm')會以某種方式拋出錯誤。 – Mattan

+1

問題不在於啓用了WAL模式,而是爲了確保新SQLite試圖刪除WAL文件。 –