Solved

Coldfusion ImageGetBlob error

Posted on 2012-03-25
8
438 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
  • 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
 
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
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

 
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

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

12 Experts available now in Live!

Get 1:1 Help Now