将图片保存到数据库的blob,image等字段中
//////////////////////////////////////将图片文件转换为blob类型
函数名:of_file2blob(vs_filename) return blob
//函数内容
integer li_FileNum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b
// Get the file length, and open the file
flen=FileLength(vs_filename)
li_FileNum=FileOpen(vs_filename,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
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
return tot_b
/////////////////////////////////////////////////////////blob变量转换为文件!
函数名:of_blob2file(bolb vb_blob,string vs_filename) return long
//
函数内容:
integer li_filenum,i,loops,li_write
long blob_len,ll_writed,ll_end
blob lb_buf
li_FileNum = FileOpen(vs_filename,StreamMode!, Write!, Shared!, replace!)
blob_len=len(vb_blob)
// 计算写文件次数
IF blob_len> 32765 THEN
IF Mod(blob_len, 32765) = 0 THEN
loops = blob_len/32765
ELSE
loops = (blob_len/32765) + 1
END IF
ELSE
loops = 1
END IF
// 写文件
FileSeek(li_FileNum,0,FromBeginning!)
ll_writed=FileWrite(li_FileNum,vb_blob)
FOR i = 1 to loops - 2
lb_buf=blobmid(vb_blob,i*32765+1,32765)
FileSeek(li_FileNum,0, FromCurrent!)
li_write=FileWrite(li_FileNum,lb_buf)
ll_writed=ll_writed+li_write
NEXT
ll_end=blob_len - ll_writed
lb_buf=blobmid(vb_blob,i*32765+1,ll_end)
FileSeek(li_FileNum,0, FromCurrent!)
li_write=FileWrite(li_FileNum,lb_buf)
ll_writed=ll_writed+li_write
FileClose(li_FileNum)
//返回文件长度
return ll_writed
////////////////////////////////////////////////////////////////////////从数据库中查询,显示图片
将数据库中的image变量转换为图片
blob lb_photo
string ls_photofile
selectblob p_photo
into :lb_photo
from personinfo
where p_no = :ls_pno
using sqlca;
Sqlca.autocommit = false
if len(lb_photo) > 10 then //存在‘’的可能,所以用>10字节判断
ls_photofile = gs_applicationdir + '\temp\photo.jpg'
of_blob2file(lb_photo,ls_photofile)
end if
///////////////////////////////////////////存储图片
of_file2blob(ls_photofile)
if len(lbl_photo) > 0 then
updateblob personinfo set p_photo = :lbl_photo where p_no = :ls_no;
end if
阅读(514) | 评论(0) | 转发(0) |