pb在数据库中存取blob类型数据

来源:互联网 发布:装修注意事项知乎 编辑:程序博客网 时间:2024/05/16 15:55

一、首先要写好两个函数,分别是文件的读取与写入:
参考 pb中读写文件的函数:http://blog.csdn.net/xys_777/archive/2010/08/04/5787833.aspx

 

二、保存文件

li_value = GetFileOpenName("选择文件",ls_docname,ls_named)  
IF li_value = 1 THEN  
    if f_readfile(lb_fj,ls_docname)=1 then     
        ll_picid=gf_getid('T_Picture') //这是一个得到新增id的函数   
        //需要先插入这条数据的其他信息   
        INSERT INTO T_Svt_Picture ( PictureId,PicName,detaillogId )    
        VALUES ( :ll_picid,:ls_named, :ld_detaillogId);  
        if sqlca.sqlcode<0 then  
            rollback;  
            messagebox('系统提示','数据保存失败')  
            return  
        end if  
        //再用updateblob更新blob字段   
        updateblob T_Picture set PicBlob=:lb_fj where pictureid=:ll_picid;  
        if sqlca.sqlcode<0 then  
            rollback;  
            messagebox('系统提示','保存失败')  
            return  
        else  
            commit;  
        end if    
    end if  
end if  

 

三、打开文件

//用selectblob将blob类型数据赋值给blob变量 lb_fj   
selectblob PicBlob into :lb_fj from T_Picture where pictureid=:ll_picid;  
if sqlca.sqlcode<>0 then  
    messagebox('系统提示','资料读取失败')  
    return  
end if  
//需要将文件重新在磁盘里保存出来,需要在之前存数据库是记录文件名 dw_1.object.picname   
ls_docname='c:/worktemp'  
if not DirectoryExists(ls_docname) then CreateDirectory(ls_docname)  
ls_docname=ls_docname+dw_1.object.picname[row]  
if f_writefile(lb_fj,ls_docname)=1 then  
    //调用api打开文件   
    if ShellExecuteA(Handle(parent),ls_null,ls_docname,ls_null,ls_null, 1) > 32 then  
        return  
    else   
        messagebox('系统提示','系统打开文件出错')  
        return  
    end if  
end if  
  
  
//api定义   
Function long ShellExecuteA (ulong hwnd, string lpOperation, string lpFile,string lpParameters, string lpDirectory, long nShowCmd) library "shell32.dll"

0 0
原创粉丝点击