본문 바로가기

PowerBuilder/Tip!

[파워빌더]DB에 저장된 이미지 다운로드 하기

string   ls_path, ls_file, ls_emp_cd

blob     lb_image, lb_temp

long     ll_filelen, ll_ret

integer  li_loop, i, li_file


ll_ret = dw_1.getrow() 

if ll_ret = 0 then return

ls_emp_cd = dw_1.getitemstring(ll_ret, 'as_emp_cd')


selectblob 

empnp_pic 

into 

:lb_image 

from 

inse98t1 

where 

empno = :ls_emp_cd 

using sqlca;


IF SQLCA.SQLCode = -1 THEN         

MessageBox("SQL error", SQLCA.SQLErrText)

END IF


ll_filelen = len(lb_image)

if ll_filelen > 32765 then

if mod(ll_filelen,32765) = 0 then

li_loop = ll_filelen / 32765

else

li_loop = (ll_filelen/32765) + 1

end if

else

li_loop = 1

end if

                                                   

GetFileSaveName ( "선택", ls_path, ls_file, "JPG","JPG Files, *.JPG")

li_file = FileOpen(ls_path, StreamMode!, Write!, Shared!, Append!)

for i = 1 to li_loop

if i = li_loop then

lb_temp = BlobMid(lb_image, (i - 1) * 32765 + 1)

else

lb_temp = BlobMid(lb_image, (i - 1) * 32765 + 1,32765)

end if

FileWrite(li_file, lb_temp)

next

Fileclose(li_file)