Jan
Jan

Reputation: 85

Issue with ColdFusion 2018 Query When Enable Null is True

I have the issue with Coldfusion 2018 when i return my query results, it shows like this

enter image description here

problem is the null appearing in brackets, this is strange, previous coldfusion versions never showed like this and when the value is null, it is actually throwing null pointer exception issue

any idea, how can i fix it

Upvotes: 1

Views: 294

Answers (1)

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

The issue is in your main question.

issues with coldfusion query in Coldfusion 2018 having enable null equal to true

TLDR: You'll need to update your code to check for and account for nulls or you should turn that setting off until you can handle them correctly.

Details:

https://coldfusion.adobe.com/2018/07/null-support-in-coldfusion-2018/

Null is an important construct in modern programming languages, which improves language interoperability with other tech stack and programming languages.

Before the 2018 release of ColdFusion, a database null or a null returned from an external service was getting converted to empty string. Therefore, if you were to code for null or take decisions based on null value in your ColdFusion applications, there was no inherent way to achieve this.

Imagine a scenario where you want to have an empty string as a column value in a database table. Since null is also converted as empty string, there was no way to distinguish a null from an empty string. This behavior also affected json serialization and deserialization.

Given an actual need for null-based implementation, we decided to introduce null as part of language changes in ColdFusion (2018 release).

Now in your ColdFusion applications, you can assign null to a variable, as shown below:

<cfset price = null>

You can also use the function isNull to check if a value is null.

<cfdump var=”# isNull(price)#”> //prints yes

<cfif price == null> // resolves to true

<cfif price eq null> // resolves to true

You can turn this on in CF Admin for all applications on the server or you can turn this on at the application level so that only specific applications use the setting.

With this on, your queries are returning [null] instead of [empty string] when the value of a database column is null or an empty string.

https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-coldfusion-variables/data-types-developing-guide.html

<cfscript>
    myquery=querynew("id,name","integer,varchar",[[null,"hello"],[1,"null"],[null,"null"]]);
    writedump(myquery);
    writedump(format="text",var=#myquery#);
</cfscript>
  • Records 1 and 3 have a null for the ID.
  • Records 2 and 3 have the string "null" for the name.

Example of nulls in CF 2018

Upvotes: 6

Related Questions