CREATE TABLE [file] (
[file_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[file_name] VARCHAR(256),
[file_data] BLOB,
[parent_btn_id] INT);
;写入操作正常
_file_add(@ScriptDir & "\2.rar" ,5)
Func _file_add($file_full_path,$parent_btn_id)
Local $filename = FileGetName($file_full_path)
Local $fOpen = FileOpen($file_full_path ,16)
If $fOpen == -1 Then
FileClose($fOpen)
MsgBox(0,"","文件写入数据库出错")
Return -1
EndIf
Local $fBinaryData = FileRead($fOpen)
FileClose($fOpen)
Local $fsqliteData = _SQLite_Encode($fBinaryData)
_SQLite_Exec($hDb ,'Insert into file values (NULL,"'&$filename&'" ,'&$fsqliteData&','&$parent_btn_id&')')
EndFunc
;读出操作不正常,请问要怎么写
Local $result = _file_get_file_by_name("2.rar")
If $result <> -1 Then
Local $fOpen = FileOpen(@ScriptDir & "\dbfile.rar" ,18)
FileWrite($fOpen ,$result)
FileClose($fOpen)
EndIf
Func _file_get_file_by_name($filename)
Local $aRow
_SQLite_QuerySingleRow($hDb ,'select * from file where file_name = "' & $filename & '"',$aRow)
If IsArray($aRow) Then
Return $aRow[2]
EndIf
MsgBox(0,"","在数据库中找不到此文件")
Return -1
EndFunc
|