ColdFusion Query of Queries Creates BIGINT Values When Hard Coding Integers

Posted October 24, 2006 at 2:24 PM

Tags: ColdFusion

Just a minor thing that I came across today; ColdFusion query of queries defines hard-coded integer values as type BIGINT. While this is a very minor detail, it can cause some issues when performing a UNION as I had to do today (I had join a query to itself in a parent-child relationship query).

I had a query that looked like this:

 Launch code in new window » Download code as text file »

  • <!--- Query for top level vendors. --->
  • <cfquery name="qTopLevelVendor" dbtype="query">
  • (
  • SELECT
  • id,
  • name,
  • has_children
  • FROM
  • qVendor
  • WHERE
  • parent_id = 0
  • )
  •  
  • UNION
  •  
  • (
  • SELECT
  • parent_id,
  • parent_name,
  • ( 0 ) AS has_children
  • FROM
  • qVendor
  • WHERE
  • parent_id != 0
  • )
  • </cfquery>

This threw thew following error:

Query Of Queries runtime error. Cannot mix types "INTEGER" and "BIGINT" in a "compare" binary operation.

The problem was with this line of code:

 Launch code in new window » Download code as text file »

  • ( 0 ) AS has_children

In the original query, this was an integer value. The query of queries is making that a BIGINT, which cannot be compared properly. To overcome this, I had to convert one of the values:

 Launch code in new window » Download code as text file »

  • <!--- Query for top level vendors. --->
  • <cfquery name="qTopLevelVendor" dbtype="query">
  • (
  • SELECT
  • id,
  • name,
  • has_children
  • FROM
  • qVendor
  • WHERE
  • parent_id = 0
  • )
  •  
  • UNION
  •  
  • (
  • SELECT
  • parent_id,
  • parent_name,
  • CAST( 0 AS INTEGER ) AS has_children
  • FROM
  • qVendor
  • WHERE
  • parent_id != 0
  • )
  • </cfquery>

Notice that I am casting the hard coded value as an integer. That did the trick. It's not often that I really think about the data types of hard coded values, but this just goes to show that that is very important.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




Reader Comments

Jan 22, 2009 at 7:29 AM // reply »
16 Comments

Thanks Ben. I just fell into this exact same trap, and thankfully there you were to guide me out. Cheers


Jan 22, 2009 at 8:09 AM // reply »
6,516 Comments

@Matt,

Awesome. It's all about team work :)


Mar 16, 2009 at 9:24 PM // reply »
2 Comments

What Matt said!

Thanks Ben


Aug 22, 2009 at 1:19 AM // reply »
3 Comments

I know this is an old post but man did this stump me for a bit. Google searched the error message and your post was #1. Thanks.


Sep 6, 2009 at 1:27 PM // reply »
6,516 Comments

@Robert,

Sweeeeet!


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 21, 2009 at 6:47 PM
Hal Helms - Real World Object Oriented Development, Sarasota - Day Five
@charlie griefer, Thank you.. ... read »
Nov 21, 2009 at 5:15 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jose Galdamez, Oh heh yeah I didn't paste the whole code. I should have defined the vars -- my bad. It's fixed thou. Thanks. ... read »
Nov 21, 2009 at 4:49 PM
Styling The ColdFusion 8 WriteToBrowser CFImage Output
Great work yet again Ben! Whilst I didn't use this whole code, I copied some of your regex code for a similar problem with the lack of an alt attribute and unescaped ampersands in CFIMAGE for Railo 3 ... read »
Nov 21, 2009 at 1:13 PM
My First ColdFusion Builder Extension - Encrypting And Decrypting CFM / CFC Files
@Ben, Because I am pedantic, I just want to make sure that everyone knows there is absolutely no encryption going on. There is only encoding and obfuscation. The cfencode tool only obfuscates your C ... read »
Nov 21, 2009 at 12:28 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jody I can't seem to get your code sample to work. If you are still having problems, try this code out and see if it gets you what you wanted. <!--- Comma delimited list with various duplicates ... read »
Nov 21, 2009 at 11:03 AM
Groovy Operator Overloading Does Not Work In The ColdFusion Context
Hi Ben, Thanks for this informative post. Now I am reading ur old posts too ... read »
Nov 21, 2009 at 10:56 AM
HostMySite.com Has The Best ColdFusion Hosting
@Mehul, Yes very nice people, however several downtimes per day which was not acceptable. Hence we had to move out. I am glad you are having good luck with them so far. ... read »