Search code examples
coldfusionqoq

ColdFusion query of query strange type cast


<cfquery dbtype="query" name="LOCAL.modello">
SELECT 
    * 
FROM 
    modelliDelMarchio 
WHERE 
    marchioid = #ARGUMENTS.marchioid#  
    AND tipologia = #ARGUMENTS.tipo# 
    AND nome = '#ARGUMENTS.nome#'
</cfquery>

I have an error on the last query line.

It's:

Query Of Queries runtime error. Comparison exception while executing =. Unsupported Type Comparison Exception: The = operator does not support comparison between the following types: Left hand side expression type = "STRING". Right hand side expression type = "LONG".

I swear that:

  • ARGUMENTS.nome IS a string (I tried with javacast, too!)
  • modelliDelMarchio is a valid DB query, containing real data. "nome" is a varchar.

My version is 9.0.1.


Solution

  • You need to cfqueryparam all of your values. If you can't (or don't want to), then you need to write your expressions like so:

    marchioid = '#Arguments.marlchioid#'
    

    If you leave the quotes off and don't use cfqueryparam, the SQL engine will treat those values as either a numeric or boolean value. Strings must be in quotes, or cfqueryparams in order to be treated as strings.