Updating contents of blob

Symptom

Customer extracted some PDFs (stored in a blob on a table pdfs) to a folder. The file names of the PDFs are the image sequence numbers of his pdfs entries. After modifying these PDFs he wishes to update his blob fields in the pdfs table.

Environment

  • Operating System: Any supported Windows version

  • PowerBuilder: Any supported version

Solution

The following steps will provide you with the desired functionality:

  1. Place an invisible ListBox (lb_pdfs)on your window (w_pfds).

  2. Add the following PowerScript to a command button or function that will provide the desired functionality:

    integer li_fnum, li_rtn
    blob pdfblob
    String ls_pdfdir = "<your PDF root directory>"
    String ls_pdfNames[], ls_pdfkeys[]
    
    //Get a list of PDF files and associated keys
    w_pdfs.lb_pdfs.DirList("*.PDF", 16400, ls_pdfdir)
    li_pdffiles = w_pdfs.lb_pdfs.TotalItems()
    FOR li_pdffile = 1 TO li_pdffiles
    ls_pdfname[li_pdffile] = w_pdfs.lb_pdfs.Item[li_pdffile]
    ls_pdfkey[li_pdffile] = Left(ls_pdfname[li_pdffile], Len(ls_pdfkey[li_pdffile]) - 4)
    NEXT
    
    // Update PDF database entries
    
    FOR li_pdffile = 1 TO li_pdffiles
    
    // Open PDF file
    li_fnum = FileOpen(ls_pdfdir + "/" + ls_pdfname[li_pdffile], StreamMode!)
    
    // Read PDF file
    FileReadEx(li_fnum, pdfblob)
    
    // Update PDF entry in database
    UPDATEBLOB pdfs SET pdfdata = :pdfblob WHERE pdfkey = ls_pdfkey[li_pdffile] USING SQLCA;
    IF SQLCA.SQLNRows> 0 THEN
    COMMIT USING SQLCA ;
    END IF
    
    NEXT
  3. The pdf entries in the pdfs table are now updated with the current PDF contents.