Highlighted

cfset no longer works in 2016

New Here ,
Apr 01, 2016

Copy link to clipboard

Copied

Hi,

Can anyone tell me please why this:

<cfquery name = "check" datasource="ds">SELECT Date FROM tbl</cfquery>

<cfset check.Date = DateFormat(check.Date, "short")>

results in the check.Date changing on versions before CF 2016 but not in CF 2016?

thanks.

Views

463

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

cfset no longer works in 2016

New Here ,
Apr 01, 2016

Copy link to clipboard

Copied

Hi,

Can anyone tell me please why this:

<cfquery name = "check" datasource="ds">SELECT Date FROM tbl</cfquery>

<cfset check.Date = DateFormat(check.Date, "short")>

results in the check.Date changing on versions before CF 2016 but not in CF 2016?

thanks.

Views

464

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 01, 2016 0
Adobe Employee ,
Apr 01, 2016

Copy link to clipboard

Copied

It's working. Can you try the below example.

<cfset abc= now()>

<cfoutput>value of abc = #abc#</cfoutput>

Regards,

Anit Kumar

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
New Here ,
Apr 01, 2016

Copy link to clipboard

Copied

Yes, <cfset abc = now()> does work however the example that I posted no longer works.

Why can you no longer overwrite a variable?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
LEGEND ,
Apr 01, 2016

Copy link to clipboard

Copied

Hi, BadMrFrosty,

My first suggestion would be to modify the SQL so that it returns the date in the format you desire, instead of modifying the query object contents.

I have not worked with CF2016, so I cannot say for sure.  Does the cfset generate an error in CF2016?  Is there anything in the CFAdmin logs that relates to your issue?

HTH,

^_^

(I am not, now, nor have I ever been an employee or consultant for Adobe Systems.

The views, opinions, or code examples I present are mine - except some code examples

may be retrieved from third-party sources - and cannot be construed as being expressly nor

implicitly the views, opinions, or code examples of Adobe Systems,

nor any affiliated, parent, or child entity of Adobe Systems.)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 1
Advocate ,
Apr 01, 2016

Copy link to clipboard

Copied

What version were you using before you upgraded to 2016?

It doesn't look like you have been able to do what you are trying since CF10. Your code does work as expected with Lucee though.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
New Here ,
Apr 01, 2016

Copy link to clipboard

Copied

I believe the application currently runs on CF9.

So how am i supposed to do this? The reason that I modify it in the query object is because I am just returning the query result via JSON back to a php application.

It's also a little crazy that it fails silently and doesn't pop an error.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
Advocate ,
Apr 01, 2016

Copy link to clipboard

Copied

Do the conversion in the SQL query instead of using CF.

Depending on what database you are using, it will have an ability to convert the date to a short as well.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
LEGEND ,
Apr 01, 2016

Copy link to clipboard

Copied

As haxtbh indicates, it depends upon which flavour SQL you're using.  MySQL does it one way; MS-SQL another; and yet another for Oracle.

HTH,

^_^

(I am not, now, nor have I ever been an employee or consultant for Adobe Systems.

The views, opinions, or code examples I present are mine - except some code examples

may be retrieved from third-party sources - and cannot be construed as being expressly nor

implicitly the views, opinions, or code examples of Adobe Systems,

nor any affiliated, parent, or child entity of Adobe Systems.)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
Most Valuable Participant ,
Apr 01, 2016

Copy link to clipboard

Copied

BadMrFrosty You shouldn't be able to update the value of a query "cell" that way.  It might help to think of a query result as an array of structs (it's actually more complicated under the hood, but in many ways it does behave this way).  Each row of the query is one item in the array, and the item is a struct containing key/value pairs matching your query columns and their values.  Even if your query only returns one row, it would still be an array (it would just have one struct item).  So to set the value of that cell, you would have to reference the location in the array (aka the row number).  So

<cfset check.Date = DateFormat(check.Date, "short")>

should be

<cfset check[1].Date = DateFormat(check.Date, "short")>

where check[1] references the first row of the query.  Unless, of course, the query has more than one row, in which case you have to specify the correct row (or more likely, loop over the query and do it to every row).


However, as haxtbh‌ and WolfShade‌ have indicated, it would be better to fix the formatting in the SQL statement.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2016 0
Adobe Community Professional ,
Apr 02, 2016

Copy link to clipboard

Copied

<cfset check.Date = DateFormat(check.Date, "short")>

My thoughts are similar to Carl's. Coldfusion, being weakly typed, tolerates plenty. But you shouldn't be doing that in the first place.

The left-hand side represents a column. Its type is coldfusion.sql.QueryColumn. The right-hand side is a string. Yet you are attempting to update the one with the other. Such code is bound to lead to inconsistency sooner or later. The fact that the code fails now is actually a blessing in disguise.

I would just do

<cfset checkDate = DateFormat(check.Date, "short")>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2016 0
New Here ,
Apr 05, 2016

Copy link to clipboard

Copied

<cfset check[1].Date = DateFormat(check.Date, "short")>


doesn't actually work with MS-SQL:

"Error","ajp-nio-8016-exec-7","04/05/16","08:33:20","appz","[Table (rows 1 columns DATE): [DATE: coldfusion.sql.QueryColumn@6d7bda52]] is not indexable by 1 The specific sequence of files included or processed is: C:\Intranet\public\yo.cfm, line: 3 "


just saying..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 05, 2016 0
Adobe Community Professional ,
Apr 05, 2016

Copy link to clipboard

Copied

I think that was a typo. Try

<cfset check.Date[1] = DateFormat(check.Date[1], "short")>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 05, 2016 0
Most Valuable Participant ,
Apr 05, 2016

Copy link to clipboard

Copied

Yup, my bad on the typo. Sorry.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 05, 2016 0