本帖最后由 xiezhang6263 于 2011-6-4 21:14 编辑 #include <SQLite.au3>
#include <SQLite.dll.au3>
$FileTABLE = "FileDATA"
_SQLite_Startup()
FileSaveToDataBase(@ScriptDir & "\值班表.xls", "database.db")
FileLoadFromDataBase(@ScriptDir & "\值班表.xls", "database.db", "值班表.xls")
_SQLite_Shutdown()
Func FileLoadFromDataBase($FileSaveAs, $DB_Filename, $FileNameINDB)
Local $aRow
_SQLite_Open($DB_Filename)
_SQLite_QuerySingleRow(-1, "SELECT * FROM " & $FileTABLE & " WHERE FileName = '" & $FileNameINDB & "';", $aRow)
If $aRow[0] <> '' Then
$hFileSaveAs = FileOpen($FileSaveAs, 18)
FileWrite($hFileSaveAs, Binary($aRow[1]))
EndIf
_SQLite_Close()
EndFunc ;==>FileLoadFromDataBase
Func FileSaveToDataBase($File_Filename, $DB_Filename)
Local $hFile = FileOpen($File_Filename, 16), $aRow
$Binary = FileRead($hFile)
_SQLite_Open($DB_Filename)
_SQLite_Exec(-1, "CREATE TABLE IF NOT Exists " & $FileTABLE & " (FileName TEXT,DATE Binary);")
_SQLite_QuerySingleRow(-1, "SELECT FileName FROM " & $FileTABLE & " WHERE FileName = '" & FileGetName($File_Filename) & "';", $aRow)
$temp = $aRow[0]
If $temp = "" Then
$n = 1
While $n <= 100
$RT = _SQLite_Exec(-1, "Insert into " & $FileTABLE & " (FileName) values ('" & FileGetName($File_Filename) & "');")
If $RT = $SQLITE_OK Then
ExitLoop
Else
Sleep(300)
$n = $n + 1
EndIf
WEnd
If $RT <> $SQLITE_OK Then Return False
EndIf
_SQLite_Exec(-1, "UPDATE " & $FileTABLE & " SET FileName = '" & FileGetName($File_Filename) & "' , DATE = '" & $Binary & "';")
_SQLite_Close()
EndFunc ;==>FileSaveToDataBase
Func FileGetName($sFileFullName)
$sFileName = StringSplit($sFileFullName, '\', 2)
If IsArray($sFileName) Then
$sFileName = $sFileName[UBound($sFileName) - 1]
Else
$sFileName = $sFileFullName
EndIf
Return $sFileName
EndFunc ;==>FileGetName
如果删除掉存储于数据库中的不再需要的文件以压缩数据库的体积呢?希望能提供删除文件的方法,感谢了!
请问大家有没更加好的办法让文件存放在数据库里面,然后读取出来。谢谢!
先用二进制打开文件,然后用自带的sqlite数据库管理工具编辑数据库。问题解决了。 |