不知道這是否是一個錯誤,但錯誤來自sqlite3.h
包括sqlite包。
一看文件中顯示了這個
/*
** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
**
** If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite will be placed in that directory. If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** It is not safe to modify this variable once a [database connection]
** has been opened. It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been call and remain unchanged thereafter.
*/
SQLITE_EXTERN char *sqlite3_temp_directory;
所以它聲明爲一個外部。如此簡單的測試:
module Main where
import Database.SQLite
main
= do hwd <- openConnection "test"
closeConnection hwd
putStrLn "done"
這會在鏈接期間崩潰,如您所預期的錯誤與上面的錯誤。 所以我創建了一個小型的C測試文件foo.c
#include "sqlite-0.5.2.2\\include\\sqlite3-local.h"
char* sqlite3_temp_directory = "C:\\test2";
所以我定義temp_directory,然後我的哈斯克爾源
$ ghc test.hs foo.c
[1 of 1] Compiling Main (test.hs, test.o)
Linking test.exe ...
的編譯過程中通過C文件一起,然後運行它也返回預期結果
$ ./test
done
如此看來,你只需要給出的sqlite3_temp_directory,而如果將其設置爲A N的值ULL指針將使用SQLLITE手冊中定義的TMP/TEMP等變量。
編輯,跟進爲什麼它的工作在Linux上而不是在Windows
在源碼包,有個文件夾sqlite3.6下的文件sqlite3.c。這爲sqlite包提供了一堆默認值。
在linux上定義OS_UNIX時,在linux上使用OS_WIN下的定義。 我們感興趣的功能是設置臨時目錄的功能。對於unix,這將是unixGetTempname
和windows winGetTempname
。
如果你看看這兩個功能的實現,對於UNIX一個有目錄列表,它會嘗試
static const char *azDirs[] = {
0,
"/var/tmp",
"/usr/tmp",
"/tmp",
".",
};
它試圖訪問它們爲了和一個可以寫入它用來產生在一個臨時文件夾
對於windows然而,第一線中的一個是:
if(sqlite3_temp_directory){
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
}else if(isNT()){
所以對於窗戶sqlite3_temp_directory
是ACTU盟友使用。這就是它無法找到它時不編譯的原因。
我重寫了我的應用程序以使用HDBC-sqlite3及其工作正確。也許sqlite hackage有些問題。 – jdevelop 2012-07-09 10:44:13