本帖最后由 caodongchun 于 2010-4-19 16:22 编辑 #include <SQLite.au3>
#include <SQLite.dll.au3>
$FileTABLE = "FileDATA"
_SQLite_Startup()
FileSaveToDataBase(@ScriptDir & "\BJ3.0 PWS.gif", "database.db")
FileLoadFromDataBase(@ScriptDir & "\1.gif", "database.db", "BJ3.0 PWS.gif")
_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
|