我有清理一堆舊的ColdFusion代碼的不幸任務。查詢到處都是,我正在努力將它們全部轉移到常用的CFC上,以便於維護。如何覆蓋ColdFusion中的SQL清理
我遇到了問題,因爲cfquery
會自動將單引號轉換爲雙引號。我如何覆蓋這種行爲?
更多具體信息如下。
因此,這裏是我開始與查詢:
<cfquery name="getObjectInfo" datasource="#BaseDS#">
SELECT groupName AS lastname, '[Group]' AS firstname
FROM groups
WHERE groups.group_id = #objectreference_id#
</cfquery>
這裏奇怪的是,文字被的,因爲我們希望它顯示(同樣的方式「選擇」,我沒我寫這個,我只是想把它清理一下)。所以,在公共功能,對於SELECT子句的可選參數:
<cffunction name="fSelGroup" access="public" returntype="query"
hint="Returns query selecting given group.">
<cfargument name="intGroupID" type="numeric" required="true"
hint="ID of group to be returned." />
<cfargument name="strSelectAttributes" type="string" required="false"
hint="Attributes to be selected in query"
default="*" />
<cfquery name="getObjectInfo" datasource="#Application.DataSource#">
SELECT #Arguments.strSelectAttributes#
FROM Groups
WHERE Group_ID = #Arguments.intGroupID#
</cfquery>
<cfreturn getObjectInfo />
</cffunction>
這是問題所在:當我通過在"GroupName AS LastName, '[Group]' AS FirstName"
爲strSelectAttributes參數,發送到數據庫的查詢是:
SELECT GroupName AS LastName, ''[Group]'' AS FirstName
FROM Groups
WHERE Group_ID = 4
您知道,我的引語被「消毒」爲無效查詢。
另請參閱http:// stackoverflow。com/questions/266586/coldfusion-adding-extra-quotes-when-construct-database-queries-in-strings – ale 2009-06-02 19:39:53