為什么我講多媒體資料存盤到SQL Server中image資料型別,提取出來的時候,只要大于32765的檔案都讀不全,都最多讀取32765?
我的用兩個函式分別存盤和讀取:
存盤代碼:
Global function blob f_readfile(string strfilename)
int intfileno //用于存放檔案句柄
int inttemp //用于回圈記數
int intcount //用于記錄檔案分塊數
long lngfilelength //用于存放檔案長度
blob blobret,blobtemp //用于完整和臨時分塊裝載檔案資料
lngfilelength=filelength(strfilename) //得到檔案長度
intcount=Ceiling(lngfilelength/32765) //得到檔案分塊數
intfileno=fileopen(strfilename,streammode!,Read!,Shared!) //得到檔案句柄
for inttemp=1 to intcount //將檔案轉換為BLOB型資料
fileread(intfileno,blobtemp) //在PowerBuilder中檔案讀寫函式,可以自動移動指標
blobret=blobret+blobtemp
next
fileclose(intfileno) //釋放檔案資源
return blobret //回傳BLOB型資料
讀取函式代碼:
Global subroutine f_writefile(blob blobvariable,string strfilename)
int intcount //用于記錄檔案分塊數
int inttemp //用于回圈計數
int intfileno //用于存放檔案句柄
blob blobtemp
intcount =ceiling(len(blobvariable)/32765) //得到BLOB資料的長度
intfileno=fileopen(strfilename,streammode!,write!,LockWrite!,replace!) //得到檔案句柄
for inttemp=1 to intcount //將BLOB型資料轉換為檔案
blobtemp=blobmid(blobvariable,32765*(inttemp - 1)+1,32765)
filewrite(intfileno,blobtemp)
next
fileclose(intfileno) //釋放檔案資源
uj5u.com熱心網友回復:
長度處理問題參考一下pb幫助中的例子
uj5u.com熱心網友回復:
能否說詳細點謝謝
uj5u.com熱心網友回復:
參考pb處理32K例子:This example reads a file exceeding 32,765 bytes. After the script has read the file into the blob tot_b, you can call the SetPicture or String function to make use of the data, depending on the contents of the file:
integer li_FileNum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b
// Set a wait cursor
SetPointer(HourGlass!)
// Get the file length, and open the file
flen = FileLength(sle_filename.Text)
li_FileNum = FileOpen(sle_filename.Text, &
StreamMode!, Read!, LockRead!)
// Determine how many times to call FileRead
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
// Read the file
new_pos = 1
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
uj5u.com熱心網友回復:
大于32k后,必須回圈讀uj5u.com熱心網友回復:
在這個檔案夾下C:\Program Files\Sybase\Shared\PowerBuilder
有一個
pbodbx0.ini
x對應你pb的版本
打開搜索
[Microsoft SQL Server]
修改
PBMaxBlobSize='32767'
改成你想要得大小,保存
發布的時候,記得把這個ini也發布了。
uj5u.com熱心網友回復:
//試試這個,把函式代碼改成如下代碼:Global subroutine f_writefile(blob blobvariable,string strfilename)
int intcount //用于記錄檔案分塊數
int inttemp //用于回圈計數
int intfileno //用于存放檔案句柄
blob blobtemp
Long ll_len
//intcount = ceiling(len(blobvariable)/32765) //得到BLOB資料的長度
//判斷長度是否大于32765 Begin
ll_len = ceiling(len(blobvariable))
if ll_len > 32765 then
intcount = (ll_len - 1)/32765 + 1
else
intcount = 1
end if
//判斷長度是否大于32765 End
intfileno=fileopen(strfilename,streammode!,write!,LockWrite!,replace!) //得到檔案句柄
for inttemp=1 to intcount //將BLOB型資料轉換為檔案
blobtemp=blobmid(blobvariable,32765*(inttemp - 1)+1,32765)
filewrite(intfileno,blobtemp)
next
fileclose(intfileno) //釋放檔案資源
uj5u.com熱心網友回復:
//試試這個,把函式代碼改成如下代碼:Global subroutine f_writefile(blob blobvariable,string strfilename)
int intcount //用于記錄檔案分塊數
int inttemp //用于回圈計數
int intfileno //用于存放檔案句柄
blob blobtemp
Long ll_len
//intcount = ceiling(len(blobvariable)/32765) //得到BLOB資料的長度
//判斷長度是否大于32765 Begin
ll_len = ceiling(len(blobvariable))
if ll_len > 32765 then
intcount = (ll_len - 1)/32765 + 1
else
intcount = 1
end if
//判斷長度是否大于32765 End
intfileno=fileopen(strfilename,streammode!,write!,LockWrite!,replace!) //得到檔案句柄
for inttemp=1 to intcount //將BLOB型資料轉換為檔案
blobtemp=blobmid(blobvariable,32765*(inttemp - 1)+1,32765)
filewrite(intfileno,blobtemp)
next
fileclose(intfileno) //釋放檔案資源
uj5u.com熱心網友回復:
//試試這個,把函式代碼改成如下代碼:Global subroutine f_writefile(blob blobvariable,string strfilename)
int intcount //用于記錄檔案分塊數
int inttemp //用于回圈計數
int intfileno //用于存放檔案句柄
blob blobtemp
Long ll_len
//intcount = ceiling(len(blobvariable)/32765) //得到BLOB資料的長度
//判斷長度是否大于32765 Begin
ll_len = ceiling(len(blobvariable))
if ll_len > 32765 then
intcount = (ll_len - 1)/32765 + 1
else
intcount = 1
end if
//判斷長度是否大于32765 End
intfileno=fileopen(strfilename,streammode!,write!,LockWrite!,replace!) //得到檔案句柄
for inttemp=1 to intcount //將BLOB型資料轉換為檔案
blobtemp=blobmid(blobvariable,32765*(inttemp - 1)+1,32765)
filewrite(intfileno,blobtemp)
next
fileclose(intfileno) //釋放檔案資源
uj5u.com熱心網友回復:
<P>承志軟體開發有限公司<BR>專業提供:</P><P>社區衛生服務管理系統<BR>醫院管理系統<BR>鄉鎮衛生院管理系統<BR>診所管理系統<BR>村衛生所管理系統<BR>婦幼保健管理系統<BR>新型農村合作醫療管理系統<BR>健康體檢管理系統<BR>計劃免疫管理系統<BR>汽配管理系統<BR>計劃生育管理系統<BR>酒店管理系統<BR>出生醫學證明管理系統</P>
<P>聯系人:張先生<BR>聯系電話:13541684271<BR>傳真:08135500851<BR>Email:[email protected]<BR>QQ:475754093<BR>網站:<A href="http://www.qmyb.net">http://www.qmyb.net</A> </P>
uj5u.com熱心網友回復:
謝謝各位大俠的幫助太謝謝了
uj5u.com熱心網友回復:
markuj5u.com熱心網友回復:
我如果從SQL Server中把存入的blob型別資料讀出來,并且大于32765,應該如何操作呢用selectblob是不是不能全讀出來如果大于32765
uj5u.com熱心網友回復:
可以的。uj5u.com熱心網友回復:
為什么我用selectblob讀出來的blob變數的大小都不大于32767呢我存盤再sqlserver中的都大于這個數,這個是再資料庫中驗證了的
請高手指點
uj5u.com熱心網友回復:
都是很好的建議! 值得學習轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/115095.html
標籤:數據庫相關
