Insert a PDF BLOB into Firebird DB

413 views
Skip to first unread message

DETech

unread,
Jun 25, 2012, 11:36:18 AM6/25/12
to ra...@googlegroups.com
Trying this code but I am getting a lot of resistance:

<CFFILE action="upload" FILEFIELD="form.uplfile" DESTINATION="C:\temp\" NAMECONFLICT="makeunique">

<CFFILE ACTION="READ" file="c:\temp\#cffile.serverfile#" variable="pdffile">
<CFSET pdffile64=ToBase64(pdffile)>
<CFSET pdffile=ToBinary(pdffile64)>

<CFQUERY NAME="add" datasource="docs">
INSERT INTO document
(document_id,document_blob)
VALUES
(#idcount#,#pdffile#)
</CFQUERY>

This is the error I get
ODBC Firebird Driver][Firebird]Dynamic SQL Error
SQL error code = -104
Token unknown - line 6, column 15

--------------------------------
I have tried it this way

<CFFILE action="upload" FILEFIELD="form.uplfile" DESTINATION="C:\temp\" NAMECONFLICT="makeunique">

<CFFILE ACTION="READ" file="c:\temp\#cffile.serverfile#" variable="pdffile">
<CFSET pdffile64=ToBase64(pdffile)>
<CFSET pdffile=ToBinary(pdffile64)>

<CFQUERY NAME="add" datasource="docs">
INSERT INTO document
(document_id,document_blob)
VALUES
(#idcount#,'<cfqueryparam value="#pdffile#" cfsqltype="cf_sql_blob">')
</CFQUERY>

error I get
java.lang.UnsupportedOperationException

Any help on this would be appreciated TIA!

Gert Franz

unread,
Jun 25, 2012, 11:49:46 AM6/25/12
to ra...@googlegroups.com
Isn't it supposed to be:

> <CFQUERY NAME="add" datasource="docs">
> INSERT INTO document
> (document_id,document_blob)
> VALUES
> (#idcount#,'#pdffile#')
> </CFQUERY>


Or have you tried <cfqueryparam> instead?

Gert

Sent from my iPhone

DETech

unread,
Jun 25, 2012, 12:18:11 PM6/25/12
to ra...@googlegroups.com
In my original post I show both ways, so yes I did try cfqueryparam.

Matt Quackenbush

unread,
Jun 25, 2012, 12:20:09 PM6/25/12
to ra...@googlegroups.com
In your non-cfqueryparam'd version, you are *not* wrapping #pdffile# in single quotes.  In your cfqueryparam version, you are.  Use the cfqueryparam version, but remove the single quotes wrapping the <cfqueryparam> tag.

Scott Busche

unread,
Jun 25, 2012, 12:20:43 PM6/25/12
to ra...@googlegroups.com
You don't use quotes around a cfqueryparam, have you tried it without them?


<CFQUERY NAME="add" datasource="docs">
> INSERT INTO document
> (document_id,document_blob)
> VALUES
> (#idcount#,<cfqueryparam value="#pdffile#" cfsqltype="cf_sql_blob">)
> </CFQUERY>

On Mon, Jun 25, 2012 at 11:18 AM, DETech <rtuin...@gmail.com> wrote:

DETech

unread,
Jun 25, 2012, 12:37:49 PM6/25/12
to ra...@googlegroups.com
Just tried it without the quotes and same error

java.lang.UnsupportedOperationException

This is my current version of the code:

<CFFILE action="upload"
FILEFIELD="form.uplfile"
DESTINATION="C:\temp\"
NAMECONFLICT="makeunique">

<CFFILE ACTION="READ" file="c:\temp\#cffile.serverfile#" variable="pdffile">
<CFSET pdffile64=ToBase64(pdffile)>
<CFSET pdffile=ToBinary(pdffile64)>

<CFQUERY NAME="add" datasource="docs">
INSERT INTO
document
(document_id,document_blob)
VALUES
(#idcount#,<cfqueryparam value="#pdffile#" cfsqltype="cf_sql_blob">)
</CFQUERY>

Peter Boughton

unread,
Jun 25, 2012, 1:21:17 PM6/25/12
to ra...@googlegroups.com
DETech wrote:
> Just tried it without the quotes and same error
>
> java.lang.UnsupportedOperationException
>

What are the full error details?


Also, you should use cfqueryparam for idcount too (and all dynamic values).

DETech

unread,
Jun 25, 2012, 1:24:33 PM6/25/12
to ra...@googlegroups.com
Railo 3.3.3.001 Error (java.lang.UnsupportedOperationException)
Message java.lang.UnsupportedOperationException
Cause java.lang.UnsupportedOperationException
Stacktrace The Error Occurred in
 D:\railo\tomcat\webapps\ROOT\upload.cfm: line 15
13: (document_id,document_blob)
14: VALUES
15: (1,<cfqueryparam value="#pdffile#" cfsqltype="cf_sql_blob">)
16: </CFQUERY>

Java Stacktrace java.lang.UnsupportedOperationException 
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setBlob(Unknown Source):-1 
   at railo.runtime.db.SQLCaster.setValue(SQLCaster.java:144):144 
   at railo.runtime.type.QueryImpl.setItems(QueryImpl.java:321):321 
   at railo.runtime.type.QueryImpl.<init>(QueryImpl.java:230):230 
   at railo.runtime.tag.Query.executeDatasoure(Query.java:622):622 
   at railo.runtime.tag.Query.doEndTag(Query.java:474):474 
   at upload_cfm$cf.call(D:\railo\tomcat\webapps\ROOT\upload.cfm:15):15 
   at railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:799):799 
   at railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:751):751 
   at railo.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:35):35 
   at railo.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:24):24 
   at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2035):2035 
   at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2002):2002 
   at railo.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:297):297 
   at railo.loader.servlet.CFMLServlet.service(CFMLServlet.java:32):32 
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722):722 
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305):305 
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210):210 
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225):225 
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169):169 
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168):168 
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98):98 
   at mod_cfml.core.invoke(core.java:121):121 
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927):927 
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118):118 
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407):407 
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999):999 
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565):565 
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309):309 
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source):-1 
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source):-1 
   at java.lang.Thread.run(Unknown Source):-1 

Scott Busche

unread,
Jun 25, 2012, 1:27:52 PM6/25/12
to ra...@googlegroups.com
Just to confirm, blobs are enabled in the datasource definition in Railo?

DETech

unread,
Jun 25, 2012, 1:31:32 PM6/25/12
to ra...@googlegroups.com
Good question, yes I made sure.

DETech

unread,
Jun 26, 2012, 1:44:43 AM6/26/12
to ra...@googlegroups.com
Ok figured it out:

<CFFILE action="upload"
FILEFIELD="form.uplfile"
DESTINATION="C:\temp\"
NAMECONFLICT="makeunique">

<CFFILE ACTION="readbinary" file="c:\temp\#cffile.serverfile#" variable="pdffile">

<CFQUERY NAME="add" datasource="docs">
INSERT INTO
document
(document_id,document_blob)
VALUES
(1,<cfqueryparam cfsqltype="CF_SQL_LONGVARBINARY" value="#pdffile#">)
</CFQUERY>


On Monday, June 25, 2012 10:27:52 AM UTC-7, Busche wrote:
Just to confirm, blobs are enabled in the datasource definition in Railo?

On Mon, Jun 25, 2012 at 12:24 PM, DETech <rtuin...@gmail.com> wrote:
Railo 3.3.3.001 Error (java.lang.UnsupportedOperationException)
Message java.lang.UnsupportedOperationException
Cause java.lang.UnsupportedOperationException
Stacktrace The Error Occurred in
 D:\railo\tomcat\webapps\ROOT\upload.cfm: line 15
13: (document_id,document_blob)
14: VALUES
15: (1,<cfqueryparam value="#pdffile#" cfsqltype="cf_sql_blob">)
016: </CFQUERY>
Reply all
Reply to author
Forward
0 new messages