The query of query ( QoQ ) with order by return duplicate column after update12 Coldfusion 2018 - coldfusion

I've updated my coldfusion 2018 server with most recent update12 by Adobe. As soon as I've updated the server I've wrote some QoQ for my application with ORDER BY in my QoQ. Whenever I use order by in QoQ then the result data have some duplicate columns.
For my simple sample query as example,
<cfquery name="testRead" datasource="testmssql">
SELECT * FROM loginDetails
</cfquery>
<cfdump var="#testRead#" label="Main Query">
<cfquery name='readSub' dbtype="query">
SELECT userID, Username FROM testRead
ORDER BY userid DESC
</cfquery>
<cfdump var="#readSub#" label="QoQ Result" abort="true">
**Output:** Refer my image please.
Here you can see the second QoQ dump have two userID column. I'm not sure why we are having it here & where it's come from. ? If I add one more column in ORDER BY list then that column also get duplicated in result query. For example, If add ORDER BY userid DESC, userName then the query dump query having userID,userid,userName,username.
Note : It's not happening before my update12. And it's not happening for main query.
Any thoughts ? Please share. Thank you advance !.

This is a known issue with the update and a bug has been filed with Adobe. I would recommend you add a comment and vote for the bug.
Adobe Bug Tracker - CF-4212383
Duplicate columns with the same name in a Query of Queries which contains an ORDER BY clause.
Description from that bug:
Problem Description:
After applying CF 2021 Update 2, when using an ORDER BY clause in a QoQ, the fields in the ORDER BY clause have become case sensitive, and if they don't match exactly the case of the fields in the SELECT list, then a duplicate column is added to the resultant query, resulting in a query that has two (or more) columns with the same name.
Further, if no fields are added to the SELECT list and * is used instead, the fields in the ORDER BY clause must be upper case, otherwise duplicate columns with the same name (but different case) again appear in the resultant query.
This showstopping behaviour has been introduced in CF 2021 Update 2. CF2021 Update 1 behaves as expected. (CF2016 also behaves as expected).
Even though the bug mentions CF 2021 Update 2, it also affects CF 2018 Update 12. As verified by bug CF-4212430 submitted for CF 2018 Update 12 which was closed as a duplicate of the CF 2021 bug.

Related

Column does not exist AWS Timestream Query error

I am trying to apply WHERE clause on DIMENSION of the AWS Timestream records. However, I got the error: Column does not exist
Here is my table schema:
The table schema
The table measure
First, I will show all the sample data I put in the table
SELECT username, time, manual_usage
FROM "meter-reading"."meter-metrics"
ORDER BY time DESC
LIMIT 4
The result:
Result
What I wanted to do is to query and filter the records by the Dimension ("username" specifically).
SELECT *
FROM "meter-reading"."meter-metrics"
WHERE measure_name = "OnceADay"
ORDER BY time DESC LIMIT 10
Then I got the Error: Column 'OnceADay' does not exist
I tried to search for any quotas for Dimensions name and check for error in my schema:
https://docs.aws.amazon.com/timestream/latest/developerguide/ts-limits.html#limits.naming
https://docs.aws.amazon.com/timestream/latest/developerguide/ts-limits.html#limits.system_identifier
But I didn't find that my "username" for the dimension violate any of the above rules.
I checked for some other queries by AWS Blog, the author used the WHERE clause for the Dimension filter normally:
https://aws.amazon.com/blogs/database/effective-queries-for-common-query-patterns-in-amazon-timestream/
I figured it out after I tried with the sample code. Turn out it was a silly mistake I believe.
Using apostrophe (') instead of single quotation marks ("") solved my problem.
SELECT *
FROM "meter-reading"."meter-metrics"
WHERE username = 'OnceADay'
ORDER BY time DESC LIMIT 10

Query to replace specific date range in a column

I have a table that houses information uploaded from a template (via another application). Well i noticed that the year was wrong (code in the application issue) and caused about 3000 lines of incorrect dates. My question is, how would i write a query to replace all the 20150101 (incorrect date) with 20160101 (correct date)? I am pretty sure its the UPDATE routine but i am not a SQL programmer so i am a tad lost. I am using latest SSMS.
Table: TRANS_USER_FORECAST_EDITS_FROM_EXCEL
Column Name: mo_day_year
DO A SELECT FIRST TO SEE HOW MANY RECORD YOU NEED TO UPDATE..
SELECT * FROM TRANS_USER_FORECAST_EDITS_FROM_EXCEL
WHERE mo_day_year = '20150101'
THEN COPY YOUR RESULT AND RUN THE QUERY BELOW TO UPDATE ALL THE RECORDS.
BEGIN TRAN
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL SET mo_day_year = '20160101'
WHERE mo_day_year = '20150101'
COMMIT
As you noted, it's indeed an update statement:
UPDATE TRANS_USER_FORECAST_EDITS_FROM_EXCEL
SET mo_day_year = 20150101
WHERE mo_day_year = 20160101

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.

Is there a way to escape and use ColdFusion query reserved words as column names in a query of query?

I'm working with a query that has a column named "Date."
The original query returns okay from the database. You can output the original query, paginate the original query, get a ValueList of the Date column, etc.
Query of Query
<cfquery name= "Query" dbtype= "query">
select
[Query].[Date]
from [Query]
</cfquery>
Response from ColdFusion
Query Of Queries syntax error. Encountered "Date. Incorrect Select
List,
Typically, I use descriptive names so I haven't run across this issue previously.
In this case, I'm working with a stored procedure that someone else wrote. I ended up modifying the stored procedure to use a more descriptive column name.
I have a service I use for transforming, searching and sorting queries with ColdFusion. I'm curious to know the answer to my original question, so that I can modify my service to either throw a better error or handle reserved words.
Is there a way to escape and use ColdFusion query reserved words as column names in a query of query?
The following code works fine for me:
<cfset query = queryNew("date")>
<cfdump var="#query#">
<cfquery name= "Query" dbtype= "query">
select
[Query].[Date]
from [Query]
</cfquery>
<cfdump var="#query#">
In standard mysql you'd "escape" the fields by using the ` character.
So for example:
select `query`.`date` from `query`
Try that and see if it works?

ColdFusion Executing Queries Parallel (Data not updating)

I do an update and then I try to get back the updated value of the field of which was updated. The issue however, is I am not getting the updated value, rather the prior value. I know the update works correctly because if I query it shows the returned data. I have tried cftransaction isolation="serializable" but it does not work.
My code is below, is there a way around this or will I have to make 2 AJAX request for simpe issue?
<cfquery datasource="#application.datasource#">
UPDATE gt_timesheet
SET
phaseid=<cfqueryparam value="#form.phase#" cfsqltype="CF_SQL_INTEGER">,
projectid=<cfqueryparam value="#form.project#" cfsqltype="CF_SQL_INTEGER">
WHERE
timesheetid=<cfqueryparam value="#form.timesheetid#" cfsqltype="CF_SQL_INTEGER">
</cfquery>
<cfquery name="phase" datasource="#application.datasource#">
SELECT status,
(
SELECT ROUND(sum(time_to_sec(duration))/3600,2)
FROM gt_timesheet
WHERE gt_timesheet.phaseid=gt_phases.phaseid
) as billedbillablehours,
(
SELECT ROUND(sum(time_to_sec(hours))/3600,2)
FROM gt_services
WHERE gt_phases.phaseid=gt_services.phaseid
) as billablehours
FROM gt_phases
WHERE phaseid=<cfqueryparam value="#form.phase#" cfsqltype="CF_SQL_INTEGER">
</cfquery>
This is making me go nuts because this language is constantly making tasks that should be simple tedious.
You don't have a CF problem, you have an SQL problem, and I think its the subqueries. First why a subquery and not a join?
Can you confirm that they are 1:1 relationships in the subqueries, because if they are one to many you are just going to get the first match.
I don't know your database schema, but doing it the way you currently are i think the SELECT needs to have the table match based on the form field you have just updated
<cfquery name="phase" datasource="#application.datasource#">
SELECT status,
(
SELECT ROUND(sum(time_to_sec(duration))/3600,2)
FROM gt_timesheet
WHERE gt_timesheet.phaseid=<cfqueryparam value="#form.phase#" cfsqltype="CF_SQL_INTEGER">
) as billedbillablehours,
(
SELECT ROUND(sum(time_to_sec(hours))/3600,2)
FROM gt_services
WHERE gt_services.phaseid=<cfqueryparam value="#form.phase#" cfsqltype="CF_SQL_INTEGER">
) as billablehours
FROM gt_phases
WHERE phaseid=<cfqueryparam value="#form.phase#" cfsqltype="CF_SQL_INTEGER">
</cfquery>
Hope that gets you somewhere, if not I think you need to explain the database schema more.
ColdFusion does not execute anything in the same request in Parallel unless you use <cfthread>
How is the duration updated after you run the first Update statement? Does it call a trigger? Possibly that is causing the update of the "duration" field to run after the second query. You could try adding a 1 second sleep after the first query to make sure the second query gets the correct value.
I guess you are missing something in the update statement. Why don't you re-evaluate the query's once again.