Avatar of BlueKarana
 asked on

Classic ASP: store and retrieve CLOB in Oracle

I'm storing a long string, about 17,000 chars, (base64 of an image) in a CLOB field in an Oracle database.

How do I retrieve the CLOB into a string, that is, the same base64 image string?

Currently I'm only getting 996 chars, then it cuts off.

*** all code is classic ASP ***

Code for storing CLOB:
BinRead = Request.BinaryRead(ByteCount)
Dim ImageStr
ImageStr= BinaryToString(BinRead)
    Set rsVisitReservation = Server.CreateObject ("ADODB.Command")
    rsVisitReservation.ActiveConnection = MM_NetBadgeOracle_STRING
    rsVisitReservation.CommandText = "UPDATE netbadge.VISITORRESERVATION SET PHOTOCLOB=? WHERE PASSID = " & PassID
   rsVisitReservation.Prepared = true
    rsVisitReservation.Parameters.Append rsVisitReservation.CreateParameter("param2", 201, 1, len(ImageStr), ImageStr) ' adLongVarChar
   Set rsVR = rsVisitReservation.Execute

Open in new window

Code for retrieving CLOB:
	ConnectStr = MM_NetBadgeOracle_STRING
	set rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT PHOTOCLOB FROM netbadge.visitorreservation WHERE passid =1443"
	Set rs = Server.CreateObject("adodb.recordset")
	rs.Open SQL, ConnectStr, 2, 3
	Response.BinaryWrite rs("PHOTOCLOB")

Open in new window

So, how do I get rs("PHOTOCLOB") into a string without truncation?

I've read about using ADO getchunks, but I haven't figured out how to do that successfully. It still truncates.

like so:

    ' Copy the string to a variable in chunks
	Dim varScan
	Dim VarChunk
	Dim lngOffset
	Dim varImgStr
    lngLogoSize = Len(rs("PHOTOCLOB"))
    lngOffset = 0
    Do While lngOffset < lngLogoSize
        varChunk = rs("PHOTOCLOB").GetChunk(conChunkSize)
        varImgStr = varImgStr & varChunk
        lngOffset = lngOffset + conChunkSize
   response.write "varImgStr = "& varImgStr

Open in new window

(The BinaryWrite only writes out 996 characters.)

ASPOracle Database

Avatar of undefined
Last Comment

8/22/2022 - Mon
slightwv (䄆 Netminder)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Yep. Sittin' here in my beehive and horn-rimmed glasses, tappin' out the classic ASP :P

For those who follow in my antidiluvian wake:

Dim ImgBuffer
Dim amount_read
Set OO4OSession = CreateObject("OracleInProcServer.XOraSession") 
Set NBDb = OO4OSession.OpenDatabase("[dbname]", "[username]/[password]", 0) 
Set visitorreservation = NBDb.CreateDynaset("select PHOTOCLOB from netbadge.visitorreservation WHERE passid =1443", 0) 
Set ScanImage = visitorreservation.Fields("PHOTOCLOB").Value 
amount_read = ScanImage.Read(ImgBuffer)

Open in new window

Thanks for the nudge, slightwv.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck