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

本文介绍了如何使用PowerBuilder进行文件的读取与写入操作,并详细展示了如何将文件数据保存到数据库及从数据库中读取文件数据的过程。涉及文件对话框、文件读写函数、数据库插入与更新操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、首先要写好两个函数,分别是文件的读取与写入:
参考 pb中读写文件的函数:http://blog.youkuaiyun.com/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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值