e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 程序开发 >> PowerBuilder教程 >> 如何存取二进制大对象(BLOBs) >> 教程正文
 
教程搜索
 
 
相关教程
  • 在PowerBuilder中利用DataStore实现查
  • 什么是“pbcat表?
  • 修改PB6的PBL,使之在PB5中可用
  • 使用日期格式时的一些问题
  • 如何存取二进制大对象(BLOBs)
  • 关于PowerBuilder的补丁包
  • 如果在isql中建立表或者增加表字段或者
  • PB高级开发环境配置
  • 动态设置Win95和NT的缺省打印机
  • PowerBuilder6.0运行环境文件列表
  • PowerBuilder、InfoMaker和HTML DataW
  • PB API调用原型
  • 如何用VC创建可在PB中调用的DLL
  • PB应用技巧——数据窗口自动折行
  • 为PB加入具有布局功能的容器组件
  • PB7.0通用选字段查询窗口的设计
 
 

图文教程


  • Windows抢了谁的饭碗 非主流操作系统To

  • 地球还是火星 平常心看“非主流”

  • 综合运用Office 2007批量制作奖状

  • 没有系统盘如何才能修复受损系统?

  • 巧妙运用Excel中边界的附加功能!
 
 
赞 助 商
 
 
如何存取二进制大对象(BLOBs)
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9
n Stored in a BLOB column without using OLE PowerScript provides you with a number of methods for dealing with Binary Long Objects without using Object Linking and Embedding. Here are a few examples of these methods, and a short explanation of what they do: Reading Data Into A Blob Column

/*This Script Reads In A File Exceeding 32766 Bytes In Size. The Same Script Can Be Used

To Read In Both Text And Bitmaps.*/

SetPointer(HOURGLASS!)// Let the user know that the script is doing something

int li_filenum, li_loops, li_counter long ll_filelen, ll_ll_bytes_read, ll_new_pos blob

lb_ourblob, lb_tot_b

ll_filelen = FileLength(sle_filename.text)

//Find out how long the file specified in sle_filename.text is

li_filenum = FileOpen(sle_filename.text,STREAMMODE!,READ!,LOCKREAD!)

//Assign Open for read, and assign a filenumber to the specified file

IF ll_filelen > 32766 THEN

IF Mod(ll_filelen,32766) = 0 THEN

li_loops = ll_filelen/32766

ELSE

li_loops = (ll_filelen/32766) + 1

END IF

ELSE

li_loops = 1

END IF

/*Determine how many FileReads will be necessary to read all of the file ...

You can't read in more than 32K at a time */

//read the file ...

FOR li_counter = 1 to li_loops

ll_bytes_read = FileRead(li_filenum,lb_our_blob )

lb_tot_b = lb_tot_b + lb_our_blob

ll_new_pos = ll_new_pos + ll_bytes_read

FileSeek(li_filenum,ll_new_pos,FROMBEGINNING!)

NEXT

FileClose(li_filenum)

//lb_tot_b now contains the contents of the file. You can do a SetPicture with

//it, if the file contained a Bitmap, or use the String function to convert it

//to text if it was a textual file.


//If it was a picture...

SetPicture(p_my_picture, lb_tot_b)

Now that you have the BLOB stored in a blob variable, you may write it to the database. If you are not going to use OLE, the you will need to make use of the SELECTBLOB, UPDATEBLOB functionality provided by PowerScript. In order to use these functions you must meet a couple of conditions:

1. Must have blob column defined in whatever your local equivalent is (i.e., Long Binary or Long Varchar in Watcom, Image in SQL Serer, long raw in Oracle, etc..)

5. SQL SERVER users must set AUTOCOMMIT to TRUE before doing any BLOB functions. (It may be set back to false after the blob function is finished, but none of the blob function will work on these databases if they are attempting to do transaction processing.)

For the purposes of our example let's say we have a simple lookup table called "blob_table" composed of a key field, of type integer, called "blob_id" and a blob column called "blob_col". We have defined the blob column as long binary (for Watcom) and set it to allow null values. Before we can update the blob to the database, we must insert the key value for the row we wish to update. In this case, let's say we have added a new row to the table with blob_col set to NULL and the blob_id set to 373. Having all of that the syntax needed to update the blob to the database is:

UPDATEBLOB blob_table SET blob_col = :lb_tot_b WHERE blob_id = 373 USING SQLCA;


IF sqlca.sqlcode < > 0 then

messagebox("UPDATEBLOB failed", sqlca.sqlerrtext)

END IF

The WHERE clause could also use a host variable, rather than having a hard-coded value.

The complement of UPDATEBLOB is SELECTBLOB. Using SELECTBLOB is exactly like using a regular SELECT INTO statement, except that you are dealing with Large Objects. For example:

//Assuming the existence of a blob variable lb_blob_var

SELECTBLOB blob_col INTO :lb_blob_var FROM blob_test WHERE blob_id = 423 USING SQLCA;

You can now manipulate the blob variable through Powerscript as you choose.

N.B.: While you can use UPDATEBLOB to update a number of BLOB rows to the same value, but you CAN NOT use the SELECTBLOB function to return more than one row. You must set up your WHERE clause such that the SELECTBLOB only returns ONE row. The SELECTBLOB is a singleton select.

When you have a Blob variable defined in PowerScript you can of course write to a file, in much the same way that you can read information from a file into a blob variable.

IV. Other Blob Functions

Three other functions which may be useful when working with Blobs are the functions Blob(), BlobEdit() and BlobMid(). These functions are explained on pages 10 -12 of the Function

上一页  1 2 3 4 下一页
  • 上一篇教程: 关于PowerBuilder的补丁包
  • 下一篇教程: 使用日期格式时的一些问题
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.