Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfqueryparam problem

New Here ,
Aug 14, 2008 Aug 14, 2008
While cleaning up some sql injection problems, I found I had to rewrite how the inserts were working.
I do not know in advance what fields need to be populated for inserts so I mad a generic function
to make my inserts.

<cffunction name="insertIntoTable" access="private" returntype="void">
<cfargument name="table" type="string" required="yes">
<cfargument name="datasource" type="string" required="yes">
<cfargument name="keyValSet" type="struct" required="yes">

<cfset var keyList = structKeyList(keyValSet)>
<cfset var curKey = "">
<cfset var curVal = "">
<cfset var comma = "">
<cfset var insertIntoTable = "">

<cfquery datasource="#datasource#" name="insertIntoTable">
insert into #table# (#keyList#)
values (<cfloop list="#keyList#" index="curKey">#comma#<cfset comma = ","><cfset curVal = trim(keyValSet[curKey])><cfif len(curVal) eq 0><cfqueryparam null="yes"><cfelse><cfqueryparam value="#curVal#"></cfif></cfloop>)
</cfquery>
<cfreturn>
</cffunction>

I know before this call is made that the table names and the keylist is clean.
I found that I could not simply use a <cfqueryparam list="yes" ...> as some of
the entries may be null.

My current problem is when someone enters Joe's Crab Shack into a form field
the corresponding data record results in Joe''s Crab Shack.

I found a hotfix for CF MX 6.1 with something that sounded similar, however
we are running CF 7.02 on redhat. The db server is an old MS SQL Server (8.00).

227
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 15, 2008 Aug 15, 2008
It appears that the two single quotes problem occurs only when cfloop is used, which looks very similar to one of the problems the hotfix for CF MX 6.1 had.

Has anyone else come across this problem?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 15, 2008 Aug 15, 2008
LATEST
I tried to duplicate it but couldn't. However, my OS is different.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources