cfqueryparam表现得很奇怪

时间:2012-08-13 15:01:51

标签: oracle coldfusion

我在coldfusion中运行更新查询时遇到问题。我收到一条错误,指出CFSQLTYPE CF_SQL_NUMERIC的数据无效。我知道数据是数字的,因为我在错误之前输出它并且它是正确的。我像这样设置变量:

<cfset itemID = FORM.itemID * 1> <!--- The * 1 is to force a numeric operation, and
therefore a numeric datatype, and like I said, it outputs right. --->

<!--- This is the line (45) the error says is bad --->
WHERE itemid = <cfqueryparam value="#itemID#" cfsqltype="CF_SQL_NUMERIC">

发生的一件奇怪的事情是,如果我将cfqueryparam更改为varchar,我仍会得到同样的错误!!

WHERE itemid = <cfqueryparam value="#itemID#" cfsqltype="CF_SQL_VARCHAR">

甚至更奇怪,当我完全取出cfqueryparam并使用一个数字时,出现了一个新的错误,说BEFORE(44)行现在很糟糕:

WHERE itemid = 20072 <!--- Changing to this produces a new error on the line before --->

<!--- Line 44, which is also using a cfqueryparam numeric. This new error is the same
as before, but on line 44 now instead of 45. --->
min_qty = <cfqueryparam value="#FORM.itemMinQuantity#" cfsqltype="CF_SQL_NUMERIC">

知道发生了什么事吗?

编辑更多代码......

<cfquery name="qUpdateItem" datasource="#thedb#">
UPDATE items_something
SET
    itemdesc = <cfqueryparam value="#FORM.itemDescription#" cfsqltype="CF_SQL_VARCHAR">,
    room = <cfqueryparam value="#FORM.itemRoom#" cfsqltype="CF_SQL_VARCHAR">,
    value = <cfqueryparam value="#FORM.itemValue#" cfsqltype="CF_SQL_NUMERIC">,
    categoryid = <cfqueryparam value="#FORM.categoryID#" cfsqltype="CF_SQL_NUMERIC">,
    keywords = <cfqueryparam value="#FORM.itemKeywords#" cfsqltype="CF_SQL_VARCHAR">,
    manufact = <cfqueryparam value="#FORM.itemManufacturer#" cfsqltype="CF_SQL_VARCHAR">,
    partno = <cfqueryparam value="#FORM.itemPartNumber#" cfsqltype="CF_SQL_VARCHAR">,
    itemtitle = <cfqueryparam value="#FORM.itemTitle#" cfsqltype="CF_SQL_VARCHAR">,
    qty = <cfqueryparam value="#FORM.itemQty#" cfsqltype="CF_SQL_NUMERIC">,
    assembly_draw_no = <cfqueryparam value="#FORM.itemAssemblyDrawingNo#" cfsqltype="CF_SQL_NUMERIC">,
    bin = <cfqueryparam value="#FORM.itemBin#" cfsqltype="CF_SQL_VARCHAR">,
    shelf = <cfqueryparam value="#FORM.itemShelf#" cfsqltype="CF_SQL_VARCHAR">,
    min_qty = <cfqueryparam value="#FORM.itemMinQuantity#" cfsqltype="CF_SQL_NUMERIC">
WHERE itemid = <cfqueryparam value="#itemID#" cfsqltype="CF_SQL_NUMERIC">

1 个答案:

答案 0 :(得分:2)

该问题可能与queryparam没有任何关系。执行语句最后一行的Oracle错误(通常是where,group by或order by子句)。如果你提供了ORA-错误,你的表格defs会有所帮助。

但是错误可能与queryparam没有任何关系。还有其他东西(连接中的相同列(例如,查询中的两个表中的ID列),缺少逗号等。)

修改

根据cfqueryparam帮助页面中的文本,您可能需要尝试CF_SQL_FLOAT或CF_SQL_DECIMAL,因为CF_SQL_NUMERIC似乎与Oracle没有直接关联。您也可以查看其他列。我不知道这是否可以解释它,但我似乎记得在过去看到这一点。