将文件或图片存入数据库
1.要自动提交关闭,
sqlca.autocommit = false
2。不能让image列内容为null,所以要先使用insert 或update便image列有个值
update t_membercard set photo='' where id=:l_id;
3.要记得先提交
commit;
3.使用updateblob更新blob类型数据, 一次只能更新一行
UPDATEBLOB 表名 SET image类型列 =:blob变量 WHERE id = :关键字;
4.还原自动提交
sqlca.autocommit = TRUE
例程:
////将图保存到数据库
long l_flength,l_count
int i_file,i_loops,i,i_byte
blob b_temp,b_sqlca
int i_row
long l_id
string s_pathname,s_fname
is_photoname=GetCurrentDirectory() +"\temptosave.jpg"
//----------delete the temporary
if(fileexists(is_photoname) ) then
filedelete(is_photoname)
end if
i_row=dw_card.getrow()
if(i_row<1) then
messagebox("","请先新增一条记录")
return -1
end if
dw_card.accepttext()
dw_card.update()
//event ue_savecard()
l_id=dw_card.getitemnumber(i_row,"id")
if(l_id <1) or isnull(l_id) then
messagebox("","不正确的文件")
return -1
end if
getfileopenname("选相片文件",s_pathname,s_fname,"图片(*.jpg),*.jpg,","jpg,*.jpg,jpeg,*.jpeg,gif,*.gif")
if trim(s_pathname)="" then return -1
filecopy(s_pathname,is_photoname,true)
l_flength= FileLength(is_photoname)
if(l_flength<1) then
messagebox("","文件不正确或扫描不成功,请重试")
return -1
end if
filecopy(s_pathname,is_photoname,true)
dw_card.object.p_1.fileName=is_photoname
i_file=fileopen(is_photoname, StreamMode!, Read!, LockRead!)
IF l_flength > 32765 THEN
IF Mod(l_flength, 32765) = 0 THEN
i_loops = l_flength/32765
ELSE
i_loops = (l_flength/32765) + 1
END IF
ELSE
i_loops = 1
END IF
FOR i = 1 to i_loops
i_byte = FileRead(i_file, b_temp)
b_sqlca = b_sqlca + b_temp
NEXT
FileClose(i_file)
l_flength=len(b_sqlca)
sqlca.autocommit = false
update t_membercard set photo='' where id=:l_id;
commit;
UPDATEBLOB t_membercard SET photo =:b_sqlca WHERE id = :l_id;
//messagebox("",string(sqlca.sqlcode))
if(sqlca.sqlcode<>0) then
messagebox("载入图时出错",sqlca.SQLErrText)
end if
commit;
sqlca.autocommit = TRUE
return 1