以下Power Script是读取bitmap文件(包括大于32KB的bitmap文件),并插入到SQL SERVER 的TEST表中。
从SinglelineEdit中取bitmap的文件名。
如果大于32KB,则以32KB为单位读取并拼接在tot_b变量中。
在SQL SERVER中建TEST表,有两列id类型char,image类型image。
将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;
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。