在cfquery中嵌入cfswitch

Jar*_*ede 3 coldfusion cfquery coldfusion-9

好的,我们试图通过使用包含已定义字段的数据库表来变得聪明:

(1) id, name, title, datemodified, dateadded
Run Code Online (Sandbox Code Playgroud)

然后将它们扩展为各种"对象"

联系表 (2) id, name, title, datemodified, dateadded, sitecode, contactid

要么:

条款表 (3) id, name, title, datemodified, dateadded, sitecode, articleid, votes

所以你会注意到(1)成为基础,(2)和(3)扩展.

我们有一个基础对象,在这些基本字段上进行数据库查询,然后我们尝试使用以下代码神奇地扩展它:

<cfquery name="local.qReturnQuery" datasource="#variables.sDSN#">   
     SELECT id, name, title, datemodified, dateadded, sitecode, contactid
       FROM tbl_#arguments.sPrefix# cb
      WHERE 1
        <cfif arrayLen(arguments.aExtendedParams) gt 0>
            <cfloop from="1" to="#arrayLen(arguments.aExtendedParams)#" index="local.x">
                 <cfscript>
                      local.sParamField = arguments.aExtendedParams[local.x][1];
                      local.sParamValue = arguments.aExtendedParams[local.x][2];
                      local.sParamType = arguments.aExtendedParams[local.x][3];
                      local.bParamIsList = arguments.aExtendedParams[local.x][4];
                      local.sParamCondition = arguments.aExtendedParams[local.x][5];            
                      local.bIsPositive = arguments.aExtendedParams[local.x][6];
                </cfscript>
                <cfswitch expression="#local.sParamType#">
                      <cfcase value="integer,boolean" delimiters="true">
                            #local.sParamCondition#
                           <cfif local.bParamIsList>
                                #local.sParamField# <cfif not local.bIsPositive>NOT </cfif>IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#local.sParamValue#" list="true">)
                           <cfelse>
                                #local.sParamField# <cfif not local.bIsPositive>!</cfif>= <cfqueryparam cfsqltype="cf_sql_integer" value="#local.sParamValue#"> 
                           </cfif>
                      </cfcase>
                      <cfcase value="string">
                            #local.sParamCondition#
                            <cfif local.bParamIsList>
                                  #local.sParamField# <cfif not local.bIsPositive>NOT </cfif>IN (<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#local.sParamValue#" list="true">)
                            <cfelse>
                                  #local.sParamField# <cfif not local.bIsPositive>!</cfif>= <cfqueryparam cfsqltype="cf_sql_longvarchar" value="#local.sParamValue#">
                            </cfif>                     
                      </cfcase>
                  </cfswitch>
              </cfloop>
          </cfif>
 </cfquery>
Run Code Online (Sandbox Code Playgroud)

不幸的是我的令人难以置信的代码似乎忽略了我的cfswitch输出查询,如:

SELECT id, name, title, datemodified, dateadded, sitecode, contactid
  FROM tbl_contact_thing cb
 WHERE 1
Run Code Online (Sandbox Code Playgroud)

我的数组看起来像:

arguments.aExtendedParams = [{1="contactid",2="44",3="integer",4="false",5="AND",6="true"}];
Run Code Online (Sandbox Code Playgroud)

所以应该看起来像:

SELECT id, name, title, datemodified, dateadded, sitecode, contactid
  FROM tbl_contact_thing cb
 WHERE 1
   AND contactid = 44
Run Code Online (Sandbox Code Playgroud)

我可能做错了什么(就此代码而言)

Ada*_*ron 6

我没有仔细检查代码,但我发现这是错误的:

<cfcase value="integer,boolean" delimiters="true">
Run Code Online (Sandbox Code Playgroud)

您的分隔符是不信t,r,u,e,它只是一个逗号.

这可能不是问题所在,但这是问题的一部分.

文件 <cfcase>