• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

Using BLOB with CF/Oracle 8i

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
Cyril_H
Asked:
Cyril_H
  • 7
  • 6
  • 4
1 Solution
 
cheekycjCommented:
0
 
cheekycjCommented:
or just make a java object to do the insert/update for you and call it using CF.

CJ
0
 
Cyril_HAuthor Commented:
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
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
cheekycjCommented:
Another article:
http://cfhub.com/contributions/oracle/

Uses Java too.

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

CJ
0
 
cheekycjCommented:
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
 
jimmy282Commented:
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
 
Cyril_HAuthor Commented:
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
 
Cyril_HAuthor Commented:
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
 
jimmy282Commented:
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
 
jimmy282Commented:
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
 
Cyril_HAuthor Commented:
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
 
cheekycjCommented:
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
 
Cyril_HAuthor Commented:
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
 
Cyril_HAuthor Commented:
see my last comment.

Thanks to EE too ! ;)
0
 
jimmy282Commented:
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
 
cheekycjCommented:
Glad you got it working!
0
 
Cyril_HAuthor Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now