打印本文 打印本文 关闭窗口 关闭窗口
在Power Builder中读写SYBASE的Image数据
作者:武汉SEO闵涛  文章来源:敏韬网  点击数679  更新时间:2009/4/22 23:09:15  文章录入:mintao  责任编辑:mintao

在使用Power Builder开发应用时,已经有越来越多的用户注重Power Builder的像处理能力,尤其当你选择SYBASE SQL Server为数据源时,SYBASE支持Image数据类型的特性,使Power Builder处理图像的能力得到更好的发挥。SYBASE与Power Builder融洽的结合,为用户多媒体程序设计提供了最佳的解决方案。

  以下举例,给你提供一种思路解决读写图像的方法:

  以下Power Script是读取bitmap文件(包括大于32KB的bitmap文件),并插入到SQL SERVER 的TEST表中。

  1. 从SinglelineEdit中取bitmap的文件名。
  2. 如果大于32KB,则以32KB为单位读取并拼接在tot_b变量中。
  3. 在SQL SERVER中建TEST表,有两列id类型char,image类型image。
  4. 将tot_b的内容存入TEST表中。

string id="01" 
int fnum, i, loop, ctr, ret 
long flen ,bytes_read, new_pos=0 
blob b,tot_b 
flen = FileLength{"d:\pb3\" + trim(sle_1.text) + ".bmp") 
fnum = FileOpen ("d:\pb3\" + trim(sle_1.text) + ".bmp",streammode!) 
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 
FOR i = 1 to loops 
bytes_read = FileRead(fnum, b) 
tot_b = tot_b + b 
new_pos = new_pos + bytes_read 
FileSeek(fnum, new_pos, FromBeginning !) 
NEXT 
FileClose(fnum) 
connect; 
INSERT INTO test (id, image) 
values (:id, :tot_b) ; (Note: Field image cannot be NULL) 
disconnect; 
connect; 
UPDATEBLOB test SET image = :tot_b 
WHERE id = :id; 
disconnect; 

  以下PowerScript是从TEST表中读出image数据,并送到p_1(picture Conntrol)中

blob emp_id_pic 
string id = "01" 
int ctr 
connect ; 
SELECTBLOB. image 
INTO : emp_id_pic 
FROM test 
WHERE id = : id; 
disconnect ; 
ctr = SetPicture (p_1, emp_id_pic) 

  注:插入图像时,Transaction log增长相当快,所以要有大一些的log device而且常做Dump Tran database-name with truncate-only。

 

打印本文 打印本文 关闭窗口 关闭窗口