Solved

Coldfusion ImageGetBlob error

Posted on 2012-03-25
8
447 Views
Last Modified: 2012-03-27
Hi,

I'm trying to insert an image into an SQL database using "ImageGetBlob". From what I'm gathering, I've written the insert correctly, but I get some funny errors (details below).

So first up my code is this:

<cfimage source="image.jpg" name="myImage">

<cfquery name="insert_img" datasource="111">

    INSERT into table(fkDocumentTypeID2, document2)
    VALUES ('ea6ebc4f-201d-4da9-832f-33aae3eeb234',
    <cfqueryparam value="#ImageGetBlob(myImage)#" cfsqltype='cf_sql_blob'>)
    WHERE fkid = '7396dd97-de0c-4ba5-8ac9-6d213345fb8d'

</cfquery>

Open in new window


When I run this coldfusion brings back the following error:

"ErrorCode       156
Message       [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'WHERE'. "

So I add single quotes around the query param:

<cfimage source="image.jpg" name="myImage">

<cfquery name="insert_img" datasource="111">

    INSERT into table(fkDocumentTypeID2, document2)
    VALUES ('ea6ebc4f-201d-4da9-832f-33aae3eeb234',
    '<cfqueryparam value="#ImageGetBlob(myImage)#" cfsqltype='cf_sql_blob'>')
    WHERE fkid = '7396dd97-de0c-4ba5-8ac9-6d213345fb8d'

</cfquery>

Open in new window


Not sure if that is correct or not but the next error i get is this (could be caused by the single quotes?):

"ErrorCode       0
Message       [Macromedia][SQLServer JDBC Driver] Invalid parameter binding(s)."


So if anyone can help me out with this that would be much appreciated.
0
Comment
Question by:CurtinProp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 230 total points
ID: 37766501
you -don't use quotes around cfquery param.


at a quick look and guess, I think the issue is that you've used single quotes in the tag

<cfqueryparam value="#ImageGetBlob(myImage)#" cfsqltype='cf_sql_blob'>

should be

<cfqueryparam value="#ImageGetBlob(myImage)#" cfsqltype="cf_sql_blob">)
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 270 total points
ID: 37766743
Also INSERT statements can't have a WHERE clause. So make the changes Sid suggested above and remove the where clause.
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 37766803
ha - missed that completely. That's probably the issue. - single quote inside the cfqp tag are probably fine (if not standard)

the where in an insert would certainly be "Incorrect syntax near the keyword 'WHERE'. ""

:)
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 52

Expert Comment

by:_agx_
ID: 37766847
> single quote inside the cfqp tag are probably fine (if not standard)

Yeah, but not the way they have them ;-) I think that's at least part of the problem. Because it's like saying insert the literal words:

          (singlequote)<cfqueryparam value="...." cfsqltype="....">(singlequote)

         ... instead of it being evaluated as usual

          <cfqueryparam value="...." cfsqltype='...'>    <=== look ma, no surrounding quotes!
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 37766899
the first code snip just had them inside the tag (which should be ok), the second around the tag ("you -don't use quotes around cfquery param.")

as you noted the first snip should work -without- the where clause
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 270 total points
ID: 37767132
My take was they put them outside too. ie "So I add single quotes around the query param"

So they need both fixes:
1)Remove the single quotes around cfqueryparam
2) Remove the WHERE clause

ie
<cfquery name="insert_img" datasource="111">
    INSERT into table(fkDocumentTypeID2, document2)
    VALUES (
          <cfqueryparam value="ea6ebc4f-201d-4da9-832f-33aae3eeb234" cfsqltype="cf_sql_varchar">
         , <cfqueryparam value="#ImageGetBlob(myImage)#" cfsqltype="cf_sql_blob">
    )
</cfquery>

Open in new window

0
 
LVL 2

Author Comment

by:CurtinProp
ID: 37769871
Thanks guys, my brain was obviously fried at the time, I was in fact trying to perform an update not an insert which definitely threw a spanner in the works.

I'll be splitting the points as I feel you both contributed to the solution. Hope thats cool.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37771962
I'll be splitting the points as I feel you both contributed to the solution. Hope thats cool.

Totally. Thanks CurtinProp.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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