<cfqueryparam> 显示“?”而不是数字
<cfqueryparam> shows "?" instead of number
这是我的 coldfusion 代码:
SELECT
MIN(legacy_sale_id) AS legacy_sale_id ,
cc_id ,
сс_name ,
sales_rep_name ,
original_sale_id ,
ls.id ,
<cfif ARGUMENTS.is_export neq 0>
CASE site_id
WHEN 4 THEN 'EU'
END as site_id,
<cfelse>
site_id ,
</cfif>
gp_order ,
SUM(item_price_usd * qty) AS value_usd,
SUM(item_price_original * qty) AS value_original,
co.total_sales_orders
FROM
ls
LEFT JOIN cc
ON
cc.company_id = ls.id
LEFT JOIN
(
SELECT
company_id,
COUNT(ll.id) AS total_sales_orders
FROM
ls ll
WHERE
cc_id IS NOT NULL
AND site_id IN (1,4)
GROUP BY
cc_id
) co
ON
co.company_id = ls.cc_id
WHERE
cc.deleted_timestamp IS NULL
<cfif ARGUMENTS.p_sales_order EQ "">
<cfif ARGUMENTS.p_date_type EQ "0">
AND when_created BETWEEN '#ARGUMENTS.p_date_from# 00:00:00' AND '#ARGUMENTS.p_date_to# 23:59:59'
<cfelse>
AND when_shipped BETWEEN '#ARGUMENTS.p_date_from# 00:00:00' AND '#ARGUMENTS.p_date_to# 23:59:59'
</cfif>
</cfif>
AND
site_id IN (#Replace("'" & ARGUMENTS.p_sites & "'", ",", "','", "ALL")#)
AND
ls.sage_roles_user_id IN (#Replace("'" & ARGUMENTS.p_user_id & "'", ",", "','", "ALL")#)
<cfif lst_exclude NEQ "">
AND
(
cc_id IS NULL
OR cc_id NOT IN (#Replace("'" & lst_exclude & "'", ",", "','", "ALL")#)
)
</cfif>
<cfif lst_custnmbr NEQ "">
AND
(
gp_custnmbr IS NULL
OR gp_custnmbr NOT IN (#Replace("'" & lst_custnmbr & "'", ",", "','", "ALL")#)
)
</cfif>
<cfif ARGUMENTS.p_customer_name NEQ "">
AND ls.сс_name LIKE <cfqueryparam value="%#ARGUMENTS.p_customer_name#%" cfsqltype="cf_sql_varchar">
</cfif>
<cfif ARGUMENTS.p_sales_order NEQ "">
AND ls.gp_order = <cfqueryparam value="#ARGUMENTS.p_sales_order#" cfsqltype="cf_sql_integer">
</cfif>
<cfif IsDefined('ARGUMENTS.p_country') AND ARGUMENTS.p_country NEQ "">
AND ls.country_id = <cfqueryparam value="#ARGUMENTS.p_country#" cfsqltype="cf_sql_integer">
</cfif>
GROUP BY
сс_name,
sales_rep_name ,
ls.id,
original_sale_id ,
site_id ,
gp_order,
cc_id,
total_sales_orders
这个coldfusion代码生成的sql是下一个:
SELECT
*
FROM
ls
SELECT
MIN(legacy_sale_id) AS legacy_sale_id ,
cc_id ,
сс_name ,
sales_rep_name ,
original_sale_id ,
ls.id ,
CASE site_id
WHEN 4
THEN 'EU'
END AS site_id,
gp_order ,
SUM(item_price_usd * qty) AS value_usd,
SUM(item_price_original * qty) AS value_original,
co.total_sales_orders
FROM
ls
LEFT JOIN
cc
ON
cc.company_id = ls.id
LEFT JOIN
(
SELECT
cc_id AS company_id,
COUNT(ll.id) AS total_sales_orders
FROM
ls ll
WHERE
cc_id IS NOT NULL
AND site_id IN (1,4)
GROUP BY
cc_id ) co
ON
co.company_id = ls.cc_id
WHERE
cc.deleted_timestamp IS NULL
AND when_created BETWEEN '07/28/2015 00:00:00' AND '07/29/2015 23:59:59'
AND site_id IN ('1',
'4')
AND ls.sage_roles_user_id IN ('33333',
'111111',
'222222',
)
AND (
cc_id IS NULL
OR cc_id NOT IN ('000000',
'111111',
'222222',
) )
AND ls.country_id = ?
GROUP BY
сс_name,
sales_rep_name ,
ls.id,
original_sale_id ,
site_id ,
gp_order,
cc_id,
total_sales_orders
我不明白为什么cfqueryparam returns“?”而不是数字:"ls.country_id = ?"
p.s。 Tnx注意,问题已解决
因为当您使用 <cfqueryparam>
时,您是在告诉 CF 将值 作为参数传递 ,而不是将其硬编码到 [=19] =] 字符串。这就是它的全部目的!
<cfqueryparam>
标记在 SQL 语句中的位置纯粹是为了标记值(?
)的占位符应该去哪里。一旦执行查询,SQL 服务器就知道要匹配传递给 SQL 语句中占位符的参数。
这是我的 coldfusion 代码:
SELECT
MIN(legacy_sale_id) AS legacy_sale_id ,
cc_id ,
сс_name ,
sales_rep_name ,
original_sale_id ,
ls.id ,
<cfif ARGUMENTS.is_export neq 0>
CASE site_id
WHEN 4 THEN 'EU'
END as site_id,
<cfelse>
site_id ,
</cfif>
gp_order ,
SUM(item_price_usd * qty) AS value_usd,
SUM(item_price_original * qty) AS value_original,
co.total_sales_orders
FROM
ls
LEFT JOIN cc
ON
cc.company_id = ls.id
LEFT JOIN
(
SELECT
company_id,
COUNT(ll.id) AS total_sales_orders
FROM
ls ll
WHERE
cc_id IS NOT NULL
AND site_id IN (1,4)
GROUP BY
cc_id
) co
ON
co.company_id = ls.cc_id
WHERE
cc.deleted_timestamp IS NULL
<cfif ARGUMENTS.p_sales_order EQ "">
<cfif ARGUMENTS.p_date_type EQ "0">
AND when_created BETWEEN '#ARGUMENTS.p_date_from# 00:00:00' AND '#ARGUMENTS.p_date_to# 23:59:59'
<cfelse>
AND when_shipped BETWEEN '#ARGUMENTS.p_date_from# 00:00:00' AND '#ARGUMENTS.p_date_to# 23:59:59'
</cfif>
</cfif>
AND
site_id IN (#Replace("'" & ARGUMENTS.p_sites & "'", ",", "','", "ALL")#)
AND
ls.sage_roles_user_id IN (#Replace("'" & ARGUMENTS.p_user_id & "'", ",", "','", "ALL")#)
<cfif lst_exclude NEQ "">
AND
(
cc_id IS NULL
OR cc_id NOT IN (#Replace("'" & lst_exclude & "'", ",", "','", "ALL")#)
)
</cfif>
<cfif lst_custnmbr NEQ "">
AND
(
gp_custnmbr IS NULL
OR gp_custnmbr NOT IN (#Replace("'" & lst_custnmbr & "'", ",", "','", "ALL")#)
)
</cfif>
<cfif ARGUMENTS.p_customer_name NEQ "">
AND ls.сс_name LIKE <cfqueryparam value="%#ARGUMENTS.p_customer_name#%" cfsqltype="cf_sql_varchar">
</cfif>
<cfif ARGUMENTS.p_sales_order NEQ "">
AND ls.gp_order = <cfqueryparam value="#ARGUMENTS.p_sales_order#" cfsqltype="cf_sql_integer">
</cfif>
<cfif IsDefined('ARGUMENTS.p_country') AND ARGUMENTS.p_country NEQ "">
AND ls.country_id = <cfqueryparam value="#ARGUMENTS.p_country#" cfsqltype="cf_sql_integer">
</cfif>
GROUP BY
сс_name,
sales_rep_name ,
ls.id,
original_sale_id ,
site_id ,
gp_order,
cc_id,
total_sales_orders
这个coldfusion代码生成的sql是下一个:
SELECT
*
FROM
ls
SELECT
MIN(legacy_sale_id) AS legacy_sale_id ,
cc_id ,
сс_name ,
sales_rep_name ,
original_sale_id ,
ls.id ,
CASE site_id
WHEN 4
THEN 'EU'
END AS site_id,
gp_order ,
SUM(item_price_usd * qty) AS value_usd,
SUM(item_price_original * qty) AS value_original,
co.total_sales_orders
FROM
ls
LEFT JOIN
cc
ON
cc.company_id = ls.id
LEFT JOIN
(
SELECT
cc_id AS company_id,
COUNT(ll.id) AS total_sales_orders
FROM
ls ll
WHERE
cc_id IS NOT NULL
AND site_id IN (1,4)
GROUP BY
cc_id ) co
ON
co.company_id = ls.cc_id
WHERE
cc.deleted_timestamp IS NULL
AND when_created BETWEEN '07/28/2015 00:00:00' AND '07/29/2015 23:59:59'
AND site_id IN ('1',
'4')
AND ls.sage_roles_user_id IN ('33333',
'111111',
'222222',
)
AND (
cc_id IS NULL
OR cc_id NOT IN ('000000',
'111111',
'222222',
) )
AND ls.country_id = ?
GROUP BY
сс_name,
sales_rep_name ,
ls.id,
original_sale_id ,
site_id ,
gp_order,
cc_id,
total_sales_orders
我不明白为什么cfqueryparam returns“?”而不是数字:"ls.country_id = ?" p.s。 Tnx注意,问题已解决
因为当您使用 <cfqueryparam>
时,您是在告诉 CF 将值 作为参数传递 ,而不是将其硬编码到 [=19] =] 字符串。这就是它的全部目的!
<cfqueryparam>
标记在 SQL 语句中的位置纯粹是为了标记值(?
)的占位符应该去哪里。一旦执行查询,SQL 服务器就知道要匹配传递给 SQL 语句中占位符的参数。