我使用cfscript
語法創建查詢,並且我有兩個查詢參數是日期。我創建日期字符串使用使用cfscript在查詢對象addParam中投射日期的問題
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
我會以爲這將模擬在第一時間:
<cfqueryparam value="#createODBCDate(now())#" cfsqltype="cf_sql_date">
所以,當我運行查詢,我得到:
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value createODBCDate(now()) cannot be converted to a date.
好。所以,我創建了一個變量,
var currentDate = createODBCDate(now());
把它添加到
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
,並得到
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value currentDate cannot be converted to a date.
當我創建使用標準<cfquery ...
語法,它工作得很好查詢。
所以,我假設我做錯了什麼,但我不能爲我的生活找出那是什麼。
順便說一下,這實在是我第一次嘗試使用<cfscript>
語法創建查詢。
所以我想這是一個什麼時候在cfscript塊中使用'#'的問題。正如我所說,這是我第一次使用cfscript創建查詢。 –
不,它並不真正與'cfscript'相關。無論何時使用引號內的CF變量(即必須進行評估),您都需要#符號。請注意,您在'cfqueryparam'示例中使用了#號,因爲該函數嵌入在雙引號內。 – Leigh
我現在看到了。我只是覺得他們不需要在一個cfscript標籤內出於某種原因。謝謝。 –