如何使用 ColdFusion 同时更新所有行中的数据

发布于 2024-11-08 22:01:43 字数 508 浏览 3 评论 0原文

我想问一下如何同时更新所有行的数据。这是我的 SQL:

<cfloop index="#form.ppp_id#">
    <cfquery name="viewPoint" datasource="#application.DataSource#">
        update PCRS_PHOTOPOINT set PPP_POINT_FROM = #form.point_from#, 
        PPP_POINT_UNTIL = #form.point_until#,
        PPP_UPDATE_DATE = SYSDATE, PPP_ICONS_NAME = '#form.icons_name#' 
        where PPP_ID = #form.ppp_id#
    </cfquery>
</cfloop>

我收到此错误:

标签“CFLOOP”的属性验证错误

I want to ask how to update data in all row at the same time. This is my SQL:

<cfloop index="#form.ppp_id#">
    <cfquery name="viewPoint" datasource="#application.DataSource#">
        update PCRS_PHOTOPOINT set PPP_POINT_FROM = #form.point_from#, 
        PPP_POINT_UNTIL = #form.point_until#,
        PPP_UPDATE_DATE = SYSDATE, PPP_ICONS_NAME = '#form.icons_name#' 
        where PPP_ID = #form.ppp_id#
    </cfquery>
</cfloop>

I got this error:

Attribute validation error for tag 'CFLOOP'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永不分离 2024-11-15 22:01:43

根本不需要使用循环。您可以使用 SQL 的 in 运算符而不是 = 一次性更新所有值列表,而不是在循环中执行 SQL 语句。另外,正如其他人已经提到的,您最好使用 cfqueryparam 而不是将用户提供的字符串直接传递到数据库。

<cfquery name="viewPoint" datasource="#application.DataSource#">
  update PCRS_PHOTOPOINT set
    PPP_POINT_FROM = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.point_from#">,
    PPP_POINT_UNTIL = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.point_until#">,
    PPP_UPDATE_DATE = SYSDATE,
    PPP_ICONS_NAME = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.icons_name#">
  where PPP_ID in (<cfqueryparam list="yes" cfsqltype="cf_sql_integer" value="#form.ppp_id#">)
</cfquery>

There's no need to use a loop at all. You can use SQL's in operator instead of = to update a list of values all at once, instead of executing a SQL statement in a loop. Also, as someone else already mentioned, you'd better be using cfqueryparam instead of passing user-supplied strings straight to the DB.

<cfquery name="viewPoint" datasource="#application.DataSource#">
  update PCRS_PHOTOPOINT set
    PPP_POINT_FROM = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.point_from#">,
    PPP_POINT_UNTIL = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.point_until#">,
    PPP_UPDATE_DATE = SYSDATE,
    PPP_ICONS_NAME = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.icons_name#">
  where PPP_ID in (<cfqueryparam list="yes" cfsqltype="cf_sql_integer" value="#form.ppp_id#">)
</cfquery>
吾性傲以野 2024-11-15 22:01:43

你应该这样做:

<cfloop list="#form.ppp_id#" index="iItems">
    <cfquery name="viewPoint" datasource="#application.DataSource#">
        update PCRS_PHOTOPOINT set PPP_POINT_FROM = "#form.point_from#", 
        PPP_POINT_UNTIL = "#form.point_until#",
        PPP_UPDATE_DATE = SYSDATE, PPP_ICONS_NAME = "#form.icons_name#" 
        where PPP_ID = #iItems#
    </cfquery>
</cfloop>

让我知道进展如何。

You should be doing it like this:

<cfloop list="#form.ppp_id#" index="iItems">
    <cfquery name="viewPoint" datasource="#application.DataSource#">
        update PCRS_PHOTOPOINT set PPP_POINT_FROM = "#form.point_from#", 
        PPP_POINT_UNTIL = "#form.point_until#",
        PPP_UPDATE_DATE = SYSDATE, PPP_ICONS_NAME = "#form.icons_name#" 
        where PPP_ID = #iItems#
    </cfquery>
</cfloop>

Let me know how it goes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文