Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Storing PDF's into Sybase & showing them in PB8

401 views
Skip to first unread message

AR

unread,
Aug 30, 2006, 2:12:37 PM8/30/06
to
Can anybody suggest some clues to work on the below
requiremnt:
My client wants to store PDF docs in Sybase DB & retrieve
them in PB. We are using PB 8.

1. We want to load the PDF file into Sybase DB from PB.
2. Retrieved the Stored PDF doc from Sybase & display in PB
window.

Any clues would be highly appreciated.
Thnx
AR

Chris Pollach

unread,
Aug 30, 2006, 2:32:09 PM8/30/06
to
AR;

We do that in one of my client's systems. The PDF's are stored in an
"Image" data type and updated using the UpdateBlob syntax. For retrieval,
the SelectBlob is used and the information written to a file where you can
now use a Run ( ) command on the reconstituted PDF. To upload a new PDF, the
FileReadEx ( ) method is used to load the PDF into a Blob variable prior to
the UpdateBlob request.

If you want the PDF displayed directly in your PB application, use the
Acrobat ActiveX as an OLE control. For web browser display, return a byte
array to the JSP or ASP web page and issue a Response.WriteBinary ( ).

HTH

Regards ... Chris

<AR> wrote in message news:44f5d276.409...@sybase.com...

AR

unread,
Aug 30, 2006, 4:47:42 PM8/30/06
to
Chris,
thnx for responding. I tried the method u had mentioned. But
for some strange reason, the Updateblob is not working. It
is not giving any errors too. below is may table defn & the
code that I am using to Update the Image data type. can u
pl. verify & see if I have made any mistake.
Thnx
-----------------------------------------
CREATE TABLE dbo.pdf_test
(
id int NOT NULL,
pdf_doc image NULL
)
go
int fh
blob Emp_id_pic
fh = FileOpen("c:\Dotnet.pdf", StreamMode!)
IF fh <> -1 THEN
FileRead(fh, emp_id_pic)
FileClose(fh)
UPDATEBLOB pdf_test SET pdf_doc = :Emp_id_pic WHERE
id = 1
USING sqlca ;
END IF
-----------------------------------------

Terry Voth

unread,
Aug 30, 2006, 11:55:21 PM8/30/06
to
PMJI, but the first clue is that FileRead only reads a maximum of 32K.
Anything bigger than that, and you'll have to loop to read the entire
file.

PB10 has functions that will read an entire file in one call.

Good luck,

Terry [TeamSybase] and Sequel the techno-kitten

*********************************
PowerBuilder for $95? No.
Personal use PowerBuilder Enterprise *AND* PocketBuilder *AND* DataWindow.NET
*AND* Sybase IQ as free benefits of a $95 ISUG membership. See
http://www.isug.com/ISUG3/Membership_benefits.html for details.

*********************************
Click once a day to help the hungry
http://www.thehungersite.com
*********************************
User Manual
===========
TeamSybase <> Sybase employee
Forums = Peer-to-peer
Forums <> Communication with Sybase
IsNull (AnswerTo (Posting)) can return TRUE
Forums.Moderated = TRUE, so behave or be deleted
*********************************

Sequel's Sandbox: http://www.techno-kitten.com
Home of PBL Peeper, a free PowerBuilder Developer's Toolkit.
Version 3.0.02 now available at the Sandbox
PB Futures updated Apr 24/2006
See the PB Troubleshooting & Migration Guides at the Sandbox
^ ^
o o
=*=

AR

unread,
Aug 31, 2006, 1:03:28 PM8/31/06
to
Yes. I have a script that will loop thru the file. But even
before I can do this, I want to ensure that the UPDATBLOB is
a success. I have used the below code to update the DB with
a PDF doc. when I query with the FileRead, the image colom
is returning a NULL. I would be happy to see atleast 32 k.
That would confirm that the UPDATEBLOB was a success.

Is there anyway that I can reach Chris Polloch directly
since he seems to have implemnted this for one of his
clients?
A

Terry Voth

unread,
Aug 31, 2006, 1:10:44 PM8/31/06
to
There's no error checking after the UPDATEBLOB. If that's the point you're
troubleshooting, I'd think that would be crucial. It may end up being something
specific to your data or schema.

Good luck,

Terry [TeamSybase] and Sequel the techno-kitten

On 31 Aug 2006 10:03:28 -0700,
in sybase.public.powerbuilder.general

*AND* Sybase IQ as free benefits of am ISUG membership. See

Chris Pollach

unread,
Aug 31, 2006, 1:40:28 PM8/31/06
to
AR;

1) What database access mechanism are you using (We are using Sybase's Open
Client native drivers)?
2) In your SQL example below .. Does ID=1 exist?
3) You should check the DB return code after the UpdateBlob command.

Contact info: http://chrispollach.pbdjmagazine.com

Regards ... Chris

<AR> wrote in message news:44f713ba.4ca...@sybase.com...

AR

unread,
Aug 31, 2006, 2:35:17 PM8/31/06
to
Thnx a lot for responding Chris.
1. V R using Sybase 12.5 via ODBC drivers.
2. i am now able to update the column. I was able to verify
this by doing a Len() on the blob column after the
SELECTBLOB function & it is returning around 32k size.
3. I am using the following code to create a PDF file from
the Blob.
------------ Code Begin---------
Blob ls_pdf_doc
string ls_filename
integer li_filenum
long ll_filelen, ll_bytes_write

sqlca.AutoCommit = true

SELECTBLOB pdf_doc
INTO :ls_pdf_doc
FROM pdf_test WHERE id = 1 USING sqlca ;

ls_filename = "c:\tst.pdf"
ll_filelen = Len(ls_pdf_doc)
li_filenum =
FileOpen(ls_filename,STREAMMODE!,WRITE!,SHARED!,APPEND!)

ls_pdf_doc = BlobMid(ls_pdf_doc,1,32000)
ll_bytes_write = FileWrite(li_filenum,ls_pdf_doc )

FileClose(li_filenum)
------------ Code End---------

When I try to open the file, I am getting a "There was an
error opening the document. The file is damaged and could
not be repaired" Error msg & the file is not opening.

Were you able to creat a PDf file from the Blob?
===============================================

Chris Pollach

unread,
Sep 1, 2006, 8:10:35 AM9/1/06
to
AR;

1) Since you are using ODBC - be careful of the Blob limit. Make sure you
set the following parameters in the PBODBC.ini file ...
PBMaxBlobSize='32767' // or whatever max you expect!
PBMaxTextSize='32767'
2) Why are you doing a BlobMid ( ) ? I think this might be messing you up!
3) Use the FileWriteEx ( ) method
4) Use the LockWrite! option in the FileOpen ( ).

Chris


<AR> wrote in message news:44f72be5.45...@sybase.com...

AR

unread,
Sep 1, 2006, 12:05:10 PM9/1/06
to
1) i HAVE SET THE
PBMaxBlobSize='1048576'
PBMaxTextSize='1048576'
3) I am using PB 8 & hence using FileWrite()
4)Used the LockWrite! option.

I even tried to open a file with ".PDF" option & write a
string hoping to test if I am just able to create a PDF file
& write to it successfully. Even this is causing the same
error msg as before ("There was an error opening the
document. The file is damaged and could not be repaired" ).
The PDF is being created. But when I try to open the file, I
get the error msg. I am not using any BLOBs now.
Below is my SIMPLE code that has no rooms for any errors,
but still.....
------------------------------
ls_filename = "c:\tst.pdf"
li_filenum =
FileOpen(ls_filename,STREAMMODE!,WRITE!,LOCKWRITE!,APPEND!)

ll_bytes_write = FileWrite(li_filenum,"anil" )
FileClose(li_filenum)
------------------------------

Chris Pollach

unread,
Sep 1, 2006, 1:59:49 PM9/1/06
to

OK .. I am confused now .. why are you appending to a PDF?

For a simple test should you not 1) read the original PDF into a Blob
variable and then 2) write it to a new file. The new file should then open
OK under Acrobat.

<AR> wrote in message news:44f85a36.13c...@sybase.com...

0 new messages