Bug – count() function in ColdFusion query of query


It has been a great time since I started working on ColdFusion. I must say that it is the easiest language in the world and yet it is a powerful and can be compared to any major programming language.

In last few days, I was using ColdBox and MockBox framework in our current project. I was using query of query which is very similar to SQL query, and we can use it over query object in ColdFusion.

Count() is a math function, but if we use it with select statement like count(*), it returns a number of rows fetched in select query. I used it query of query, and it was giving me the correct count if my select statement is returning some rows, but if it is not returning any row then ideally it should give 0 as output, but it gives [empty string].

I must need to come out of this issue, and I used a recordCount property of returning object, but you can also use CodlFusion function val() to convert the empty string to 0.

I can state that it is a bug base on the answer I get from the community. See my question on Stack Overflow Community. Still I will wait for some time if it is appropriate I’ll report it to ColdFusion bug tracking system.


One thought on “Bug – count() function in ColdFusion query of query

  1. Without knowing the specifcs of the code, it sounds lke you need an isnull parameter in your SQL call, it is not a coldfusion issue. What you are returning that appears to be a blank is actually a null value returned by SQL. To fix this add the following to your SQL code, with the specfics modified to fit your application:
    select ISNULL (check_expression,replacement_value ) from TABLENAME.
    So for example, “select isnull(id,0) as id from members where x=0”. So if none of your members have x set to zero the id would be null, but you would return a zero as the value.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s