SQLite数据库如何存储图片
SQLite数据库如何存储图片无果,结贴。
[ 本帖最后由 ymjssg109 于 2009-3-7 17:35 编辑 ] 将图片转成二进制。。 。。。。楼主意思不明确
我估计楼主是想存储文件的路径 谢谢楼上提醒,确实没有表达清楚。
应该是
如何把指定控件上的图片存入SQLite数据库 应该是把指定的图片存入sqlite,然后再用控件调用出来吧? 保存图片,一般就2种方法,读取文件原始值,也就是2进制码,然后保存到数据库里,或者把图片保存在某一个文件夹下,然后把路径保存到数据库里 有例子吗?放上来看看。. 专程二进制 本帖最后由 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 <> '' Then
$hFileSaveAs = FileOpen($FileSaveAs, 18)
FileWrite($hFileSaveAs, Binary($aRow))
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
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
Else
$sFileName = $sFileFullName
EndIf
Return $sFileName
EndFunc ;==>FileGetName
新手!!学习中!谢谢 正想学习的 正需要这个,下来用用看 正想看看如何存图片 新手!!学习中!谢谢
页:
[1]