Error with Evaluate Function - coldfusion

I have the following legacy code which is causing a stange issues just recently, we upgraded to coldfusion 9
<cfquery name="qCheck" datasource="#ds#">
select * from authentication
where id = #val(url.ID)#>
</cfquery>
so the above query does return a row and it has stored value in one of its field which is following as:
columnName - vchevalemailaddress
Value as - session.email
<cfset a = Evaluate(qCheck.vchevalemailaddress)
<cfoutput>#a#</cfoutput>
Now i am getting an error as:
Element EMAIL is undefined in SESSION.

Related

Issue with ColdFusion Query of Query after upgrading ColdFusion server from CF9 to CF21

I cannot figure this out. My company recently upgraded our ColdFusion Server from CF9 to CF2021. One of my pages uses queries of queries to run. Prior to the upgrade the page worked fine. However after the upgrade the query of query where statement is not returning any results. Even though the original query has the data. The data is coming from DB2 data source in case that changed with the new version.
<cfquery name = "query_data_sample" dbtype="query">
SELECT
SAMPLE_DATE
, SAMPLE_NBR
, SAMPLE_MISC_NBR
, SUM (RECD_QTY) AS TTL_RECD_QTY
, SUM (MISC_QTY_1) AS TTL_MISC_QTY_1
, SUM ( 1 ) AS TTL_COUNT
FROM original_query_result
WHERE 1=1
AND SAMPLE_DATE = <cfqueryparam value = "#original_query_result.SAMPLE_DATE#" cfsqltype = "CF_SQL_DATE">
AND SAMPLE_NBR = <cfqueryparam value = "#trim(original_query_result.SAMPLE_NBR)#" cfsqltype = "CF_SQL_CHAR">
AND SAMPLE_MISC_NBR = <cfqueryparam value = "#trim(original_query_result.SAMPLE_MISC_NBR)#" cfsqltype = "CF_SQL_CHAR">
GROUP BY
SAMPLE_DATE
, SAMPLE_NBR
, SAMPLE_MISC_NBR
</cfquery>
When I comment out the AND statements and dump out the above query I can see the output of the original_query_result with all the TTL values and Sample rows. However if I want to grab just one row with the AND statements then the query comes back as not finding the row. I am doing a cfoutput query = original_query_result and trying to get the total quantity to display on each row in my output grid table.
Any help would be greatly appreciated. I have been trying to figure this out for more then a week now.
I saw something similar a while back and found this post:
https://web.archive.org/web/20180210052449/http://blog.dkferguson.com/index.cfm/2010/2/17/Using-Querie-of-Queries-with-CFDirectory
Basically I had to CAST the date and use cfqueryparam (as you are):
SAMPLE_DATE = CAST(<cfqueryparam value="#original_query_result.SAMPLE_DATE#" cfsqltype="CF_SQL_DATE"> AS date)
The post said they had to cast both sides but I didn't find this.

issues with CF query of queries with new patch on coldfusion 11

I did a recent update on coldfusion 11 to latest patch. Before the patch, the following code was working perfectly fine, but after the update I am getting the following error. Please note the columns I am outputting has nothing related with date
Query Of Queries runtime error.
Type cast exception: Failed to cast object of type java.lang.String to java.util.Date.
<cfset QueryAddColumn(data,"IsaString",ArrayNew(1))>
<cfloop query="data">
<cfset querySetCell(data, "IsaString", "YES", data.currentRow) />
</cfloop>
<cfquery name="getCustomersbasedContacts" dbtype="query">
SELECT CAST(contact_id as varchar) + '~' + CAST(IsaString as varchar) + '~' + CAST(contact_name as varchar) as id,
contact_name + '-' + email as text
FROM data
where status = 'active'
</cfquery>
where data represents a query

Coldfusion Query loop works in cf10 but not 9

Why does the following work in CF10 but not CF9?
<cfset out="">
<cfif isQuery( arguments.values ) >
<cfloop query="#arguments.values#" >
<cfset out = '#out#<option value="#value#">#label#</option>'>
</cfloop>
</cfif>
CF9 states that "Complex object types cannot be converted to simple values." for the line containing the cfloop. I'm using the Coldbox framework and it's debugger information shows that arguments.values is a query with Label & Value columns.
Prior to CF10, the query attribute of cfloop can only be a string - the name of the query - not the variable itself.
So, when you put #arguments.values# it is trying to convert the complex query object to a string, to obtain a name, which is where the error comes from.
It works in CF10 because the attribute has been updated to also allow a query value.
side notes:
This line of code can be simplified:
<cfset out = '#out#<option value="#value#">#label#</option>'>
to:
<cfset out &= '<option value="#value#">#label#</option>'>
Also you very likely should be using HtmlEditFormat* on at least label, and perhaps value too.
*(or encodeForHtml if it only needs to work in CF10+)

CF QoQ is throwing runtime error. "Column reference is not a column in any of the tables of the FROM table list."

In my code, I first create the Query Object:
<cfset memberData = QueryNew('slug,pos,firstname,lastname,email') />
<cfset temp = QueryAddRow(memberData, #numMembers#) />
<!--- LOOP POPULATES QUERY OBJECT --->
<cfloop...</cfloop>
I can then verify that it has been populated by running the following (which outputs as expected):
<cfoutput query="memberData">
#slug# - #pos#<br>
</cfoutput>
I then try to query the memberData Query Object and all hell breaks loose. If I run:
<cfquery name="members" dbtype="query">
SELECT slug,pos,firstname,lastname
FROM memberData
WHERE slug = #slug#
</cfquery>
I get this error:
Query Of Queries runtime error.
The select column reference [university] is not a column in any of the tables of the FROM table list.
In the output test mentioned above, I can verify that "university" is one of the values in the slug column. Clearly I'm missing something in my approach, but I'm baffled as to what it might be. Any help would be greatly appreciated!
Query Of Queries runtime error.
The select column reference
[university] is not a column in any of the tables of the FROM table
list
Your error was caused by absence of quotes in where clause and nothing else:
This expression find rows where the value in slug column equals the value in CF slug variable (String):
WHERE slug = '#slug#'
On the other hand this expression means find rows where value in the slug column equals the value contained in the column named in the CF slug variable (String):
WHERE slug = #slug#
The most likely cause of why you needed to change to SELECT * is CF query caching. So changing it back now should solve the problem. And always use <cfqueryparam .../> as suggested by "Al Everett"
Well, it's not quite answering the question asked, but it's close enough for what I needed:
<cfquery name="members" dbtype="query">
SELECT *
FROM memberData
WHERE slug = '#slug#'
</cfquery>
I had tried the wrapping #slug# in single quotes prior to posting with no success, but doing that plus changing the query to SELECT * fixed the issue. For my content, * only adds one more value retrieved, so not really a problem in slowing down the process.

How can I insert an expiration date into a table and having messages expire without breaking functionality?

I’m using Coldfusion 9,0,0,251028 on Windows 7 64-bit, with a Microsoft Access 97 database.
The code is for an application that takes a submitted message from a form and posts it to a different page (breakingnews.cfm). The form values are inserted into the "news" table on a database, including the date the message was submitted (mes_dat) and the date it should expire (exp_dat).
On the database, the is_current and display columns have a default value of 0.
The form action is new_process.cfm, which does two things:
1) Does <cfset expdate = createdate(end_year, end_month, end_day)>. End_year, end_month, and end_day are dropdown selectors that set the expiration date. A problem I have had is expdate not being able to be inserted by post_breaking.cfm, but only when it is put online, on my local testing server there seems to be no problem.
2) Includes a template named "post_breaking.cfm", which runs these queries:
<cfquery name="get_init_info" datasource="#db#">
select id
from news
where is_current = 1
</cfquery>
<cfquery name="update_info_1" datasource="#db#">
update news
set is_current = 0, scrollshow = 0
</cfquery>
<cfif get_init_info.recordcount NEQ 0>
<cfquery name="update_info_2" datasource="#db#">
update news
set display = 1
where id = #get_init_info.id#
</cfquery>
</cfif>
<cfquery name="put_in_info" datasource="#db#">
insert into news
(is_current, display, mes_dat,mes_tim,mes_sub,mes_text,scrollshow, exp_dat)
values
(1,0, #createodbcdate(now())#, #createodbctime(now())#, '#subject#', '#message#',1, #expdate#)
</cfquery>
The message is then displayed on breakingnews.cfm if the column is_current on the news table is 1. This is code I have inherited, so I'm not sure how it does it, but the code only allows 5 messages at a time to have is_current = 1.
The part I'm trying to make happen is having a query run when breakingnews.cfm loads that checks if exp_dat is between now() and mes_dat to set is_current to 1, while still maintaining only 5 items having an is_current of 1.
When breakingnews.cfm is accessed it runs these queries:
<cfquery name="get_info" datasource="#db#">
select *
from news
where
<cfif not isdefined("id")>
is_current = 1
<cfelse>
id = #id#
</cfif>
order by mes_dat desc, mes_tim desc
</cfquery>
<cfquery name="add_exp" datasource="#db#">
UPDATE news
SET is_current = 1
WHERE now() BETWEEN mes_dat AND exp_dat
</cfquery>
<cfquery name="remove_exp" datasource="#db#">
UPDATE news
SET is_current = 0
WHERE now() NOT BETWEEN mes_dat AND exp_dat
</cfquery>
This will cause the messages that have an exp_dat between now() and mes_dat to be displayed and otherwise not display on breakingnews.cfm.
However, when a new message is submitted, upon accessing breakingnews.cfm the first time, only the newly submitted message is displayed.
If the page is refreshed, the messages that were filtered correctly will be displayed under the new message, but there will now be six items displaying on the page when there should only be five.
How can I get the correct amount of messages, and have them display the first time without needing a refresh?
I've gotten advice to replace the get_init_info query with
<cfquery name="get_init_info" datasource="#db#">
select id
from news
where exp_dat > now()
</cfquery>
but that caused all other rows in is_current and scrollshow to be changed to 0 after creating a new message (though the new message's scrollshow and is_current are 1).
My fist thought is to change how the system gets the news to display, but since you sppear not to have control of that, here's my suggestion. Please bear in mind that I've never used Access, so I'm using MS-SQ syntax.
Get the ids of the 5 items you want
select top 5 id
from bews
where exp_date > #createodbcdate(now)#
and display = 1
Now, set display = 0 on all items.
Finally, re-display the ids you found earlier.
update news
set display = 1
where id in #valuelist(query, "id")
If you have questions or corrections, feel free to comment.