Solved

Using BLOB with CF/Oracle 8i

Posted on 2002-03-15
17
817 Views
Last Modified: 2013-12-24
My client wants that i store Word documents in the DB as BLOB. I can't find an easy way to do this... i found several solutions using for example java but not "direct solution" and clear answer ;(

So, could someone tell me if it's possible by using only CF(4.5.2 or 5) and Oracle (8i) ?

Thanks a lot,
Cyril
0
Comment
Question by:Cyril_H
  • 7
  • 6
  • 4
17 Comments
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
or just make a java object to do the insert/update for you and call it using CF.

CJ
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
Thanks CJ, it's one of the article i already read. But i was wondering if there was another easier solution by using only CF and Oracle ?
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Another article:
http://cfhub.com/contributions/oracle/

Uses Java too.

I am beginning to think it may be the only approach :-(

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Something I found:
You can do this in CF.  In your update or insert queries use <cfqueryparam>
and in CF Admin in the ODBC section under the Datasource for you DB, be sure
to click the option to Enable retrieval of long text.

Example query:
<CFQUERY NAME="qBLOB" DATASOURCE="#DSN#">
    Insert into {table_name}
    (col1, col2, col3, col4)
    Values
    (#value1#, #value2#, #value3#, <CFQUERYPARAM VALUE="#Value4#"
CFSQLType="CF_SQL_BLOB">)
</CFQUERY>
0
 
LVL 11

Expert Comment

by:jimmy282
Comment Utility
This is the code which should work but I when I run it on my SQl2k and CF5 I get an error while retrieving the data (I could Insert successfully)


<cffile action="ReadBinary"
 file="#ExpandPath(".")#\GD.DOC"
 variable="theDocFile">

 <cfset base64 = #toBase64(theDocFile)#>
<CFQUERY NAME="qBLOB" DATASOURCE="tajseed">
   Insert into Doctable
    Values
   (2,'#tobase64(theDocFile)#')
</CFQUERY>

<cfquery name="readDoc" datasource="tajseed">
 select docFile from DocTable where  id = 2;
</cfquery>

<cfset TempFile = GetTempFile("c:\temp\","tmpFile")>

<cffile action="Write"
 file="#TempFile#"
 output="#toBinary(readDoc.docFile)#"  
 addnewline="No">

<cfcontent type="application/msword" file="#TempFile#" deletefile="Yes">

Jimmy

0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
cheekycj,

it seems that CF5 does not recognise CF_SQL_BLOB ;) Here's the error message...

Error Diagnostic Information
CFSQLTYPE

'CF_SQL_BLOB' is not a valid CFSQLTYPE setting for CFQUERYPARAM. When specified, the CFSQLTYPE attribute must be set to one of the following: CF_SQL_BIGINT CF_SQL_BINARY CF_SQL_BIT CF_SQL_CHAR CF_SQL_CLOB CF_SQL_DATE CF_SQL_DECIMAL CF_SQL_DOUBLE CF_SQL_FLOAT CF_SQL_IDSTAMP CF_SQL_INTEGER CF_SQL_LONGVARBINARY CF_SQL_LONGVARCHAR CF_SQL_MONEY CF_SQL_MONEY4 CF_SQL_NUMERIC CF_SQL_REAL CF_SQL_REFCURSOR CF_SQL_SMALLINT CF_SQL_TIME CF_SQL_TIMESTAMP CF_SQL_TINYINT CF_SQL_VARBINARY CF_SQL_VARCHAR
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
jimmy,

i cannot insert the doc file in the dB ! I got the following message :

Error Diagnostic Information
Oracle Error Code = 1704

ORA-01704: string literal too long


Thanks,
Cyril
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Accepted Solution

by:
jimmy282 earned 200 total points
Comment Utility
1)You have to use CF_SQL_CLOB instead of CF_SQL_BLOB.

2)I used the ntext datatype in SQL server. I suppose its BLOB for ORacle. The doc should go in....I think.
0
 
LVL 11

Expert Comment

by:jimmy282
Comment Utility
I read few articles the other day which said that using ADODB.Stream, You can insert the Data in DB But then again you have to use CFOBJECT which is not purely CF solution.

I think Java is the best solution for it as CJ suggested.

Jimmy
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
jimmy,

i cannot insert the doc file in the dB ! I got the following message :

Error Diagnostic Information
Oracle Error Code = 1704

ORA-01704: string literal too long


Thanks,
Cyril
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
is the data type set as clob or blob?

Jimmy: Cyril would have to insert a file as a BLOB not a CLOB.  CLOB would be fine if just the data (text) was going to be inserted.

CJ
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
It works !!! Thanks a lot to everyone... Thanks Jimmy, thanks CJ !

I can insert a Word document (with pics embedded) in a CLOB field. Here's the full code for it. I'm using Oracle 8i and CF5 :

<!--- the form page - test.cfm --->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
</head>

<body>

<FORM name="test" method="post" action="test_action.cfm" enctype="multipart/form-data">

<input type="File" name="myFile">

<INPUT type="Submit">

</FORM>


</body>
</html>


<!--- the insert page test_action.cfm --->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
</head>

<body>

<CFFILE ACTION="ReadBinary"
    FILE="#MyFile#"
    VARIABLE="aBinaryObj">


<cfif isBinary(aBinaryObj)>
     <cfset base64 = toBase64(aBinaryObj)>
<cfelse>
     <cfabort showerror="The file doesnt seem to be a binary file">
</cfif>


<CFQUERY datasource="#myDSN#">
INSERT INTO EXPERTS(NAME,CV)
     VALUES ('Cyril',<CFQUERYPARAM VALUE="#base64#"
CFSQLType="CF_SQL_CLOB">)
</CFQUERY>

</body>
</html>


To view the word doc i need 2 pages.

<!--- the Select doc page --->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
</head>

<body>
<CFQUERY name="qryGetCV" datasource="#myDSN#">
SELECT CV
  FROM EXPERTS
 WHERE NAME = 'Cyril'
</CFQUERY>

<cffile action="WRITE" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#/tmp.doc" output="#toBinary(qryGetCV.CV)#" addnewline="No">

<cflocation url="result.cfm">

</body>
</html>


<!--- the view word doc page --->
<cfcontent type="application/msword" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#/tmp.doc" deletefile="Yes">
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
see my last comment.

Thanks to EE too ! ;)
0
 
LVL 11

Expert Comment

by:jimmy282
Comment Utility
So I was just missing the second file while viewing.
That explains it.
May be the headers are already passed thats why i couldnt get it working.....So now thigns are OK.

Thanks for the Points .

Jimmy
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
Glad you got it working!
0
 
LVL 2

Author Comment

by:Cyril_H
Comment Utility
Yep me too ;) And by the way, i try to make it work with gif files, and it works without any modifications ! ;)

Thanks again,
Cyril
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now