• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfset no longer works in 2016

New Here ,
Apr 01, 2016 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

735

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
community guidelines
Adobe Employee ,
Apr 01, 2016 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

Votes

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
community guidelines
New Here ,
Apr 01, 2016 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?

Votes

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
community guidelines
LEGEND ,
Apr 01, 2016 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.)

Votes

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
community guidelines
New Here ,
Apr 01, 2016 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.

Votes

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
community guidelines
Advocate ,
Apr 01, 2016 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.

Votes

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
community guidelines
LEGEND ,
Apr 01, 2016 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.)

Votes

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
community guidelines
Advocate ,
Apr 01, 2016 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.

Votes

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
community guidelines
Guide ,
Apr 01, 2016 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.

Votes

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
community guidelines
Community Expert ,
Apr 02, 2016 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")>

Votes

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
community guidelines
New Here ,
Apr 05, 2016 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..

Votes

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
community guidelines
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

I think that was a typo. Try

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

Votes

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
community guidelines
Guide ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

LATEST

Yup, my bad on the typo. Sorry.

Votes

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
community guidelines
Resources
Documentation