Mysql 选择和更新记录时查询为空错误?

Mysql 选择和更新记录时查询为空错误?,mysql,coldfusion,coldfusion-9,railo,Mysql,Coldfusion,Coldfusion 9,Railo,我想知道为什么在我检查SQLYG中正常工作的查询时出现这个错误“Query is Empty”。谁能帮我解释一下这个问题出了什么问题吗?任何帮助都将不胜感激 这是我的密码。我在Ubuntu上使用Railo4.2.0 <cfquery name="q" datasource="#getDSN()#"> SELECT is_nav_item, nav_order, MAX(nav_order) AS maxNavOrder FROM content WHERE

我想知道为什么在我检查SQLYG中正常工作的查询时出现这个错误
“Query is Empty”
。谁能帮我解释一下这个问题出了什么问题吗?任何帮助都将不胜感激

这是我的密码。我在Ubuntu上使用Railo4.2.0

<cfquery name="q" datasource="#getDSN()#">
    SELECT is_nav_item, nav_order, MAX(nav_order) AS maxNavOrder 
    FROM content
    WHERE id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#">
    OR site__id = <cfqueryparam value="#arguments.site__id#" />
</cfquery>

<cfquery datasource="#getDSN()#">
    <!--- 
       check to see if existing record has 0 and in arguments it is 
       passed as 1 then we are going to update the nav order by selecting 
       max nav order in the table then incrementing the maxNavOrder by 1
    --->
    <cfif q.is_nav_item EQ 0 AND arguments.is_nav_item EQ 1>
        UPDATE content
        SET nav_order = #q.maxNavOrder+1#
        WHERE id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_integer" />
        AND site__id = <cfqueryparam value="#arguments.site__id#" />
    </cfif>

    <!--- 
        check to see if the existing record have is_nav_item eq 1 and in 
        the arguments it is 0 if it is then its going to update the nav_order 
        to 0... so that we can prevent it being updating the nav order in case 
        someone not updating nav_item but something else
    --->
    <cfif q.is_nav_item EQ 1 AND arguments.is_nav_item EQ 0>
        UPDATE content
        SET nav_order = 0
        WHERE id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_integer" />
        AND site__id = <cfqueryparam value="#arguments.site__id#" />
        ;
    </cfif>
 </cfquery>

选择is_nav_项目、nav_订单、MAX(nav_订单)作为maxNavOrder
从内容
其中id=
或站点id=
更新内容
设置导航顺序=#q.maxNavOrder+1#
其中id=
和站点id=
更新内容
设置导航顺序=0
其中id=
和站点id=
;

查询中有if语句。。。如果两者的计算结果都不是true,那么您的查询可能是一个空查询

为什么不做一个IF并将整个查询放在IF语句中。。。这样,就不可能在没有任何文本的情况下获取CFQUERY

<!--- 
  check to see if existing record has 0 and in arguments it is passed as 1 
  then we are going to update the nav order by selecting max nav order in 
  the table then incrementing the maxNavOrder by 1
--->
<cfif q.is_nav_item EQ 0 AND arguments.is_nav_item EQ 1>
     <cfquery datasource="#getDSN()#">
        UPDATE content
        SET    nav_order = #q.maxNavOrder+1#
        WHERE  id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_integer" />
        AND site__id = <cfqueryparam value="#arguments.site__id#" />
     </cfquery>
</cfif>

<!--- 
    check to see if the existing record have is_nav_item eq 1 and in the 
    arguments  it is 0.  if it is then its going to update the nav_order 
    to 0... so that we can prevent it being updating the nav order in case 
    someone not updating nav_item but something else
--->
<cfif q.is_nav_item EQ 1 AND arguments.is_nav_item EQ 0>
    <cfquery datasource="#getDSN()#">
       UPDATE content
       SET    nav_order = 0
       WHERE  id = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_integer" />
       AND    site__id = <cfqueryparam value="#arguments.site__id#" />
    </cfquery>
</cfif>

更新内容
设置导航顺序=#q.maxNavOrder+1#
其中id=
和站点id=
更新内容
设置导航顺序=0
其中id=
和站点id=

事实上,我听说使用cfquery多次会导致性能问题,因为每当cfquery标记执行时,它都会调用数据库。如果这样做,第一次更新不起作用,第二次更新就起作用。如果使用1000次查询,是的,您会希望以某种方式对它们进行分组,但对于基本情况,像这样把他们分开是完全好的。它也使阅读更容易。如果第二个运行,它将覆盖第一个。。。所以两者都可以运行,但它们是相互对立的。(编辑)@GavinPickin-FYI,您可以使用代码按钮ie
{}
(或缩进4+空格)来发布cfml。谢谢Leigh,这是新的。。。但我只是想尽力帮忙。