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
Related
I have some code that I am trying to make more efficient.
I am running a query and then looping through those results and running additional queries to drill down into my data even further. The code takes long to process and I'm sure that it is not as efficient as it could be and I believe that doing a query of queries would be more efficient, but I'm am not sure how to exactly implement that.
Here is my current code
My first query:
<!--- Get equipment Query --->
<cfquery name="get_equipment" datasource="#datasource#">
select *
from equipment_maintenance
where machine_type != 'unifi_site' AND machine_type != 'firewall' AND machine_type != 'dvr' AND machine_type != 'pbx' AND active = 'yes'
ORDER by #querySortType#
</cfquery>
Then I output my query and run additional queries:
<cfoutput query="get_equipment">
<!--- Get In-Progress Maintenance History --->
<cfquery name="get_in_progress_history" datasource="#datasource#">
select *
from service_ticket
where equipment_id=#id#
</cfquery>
OUTPUT SOME DATA
<!--- Update due date in the database for this machine --->
<cfquery name="dueDate#id#" datasource="#datasource#">
update equipment_maintenance
set maintenance_due_date = #dueDate#
where id = #id#
</cfquery>
OUTPUT SOME DATA
<cfquery name="get_history" datasource="#datasource#">
select *
from equipment_service_history
where equipment_id = #id#
</cfquery>
<cfquery name="get_history_ticket_detail" datasource="#datasource#">
select *
from closed_tickets
where equipment_id = #id#
order by ticket_id DESC
</cfquery>
OUTPUT SOME DATA
<cfloop query="get_history_ticket_detail">
OUTPUT SOME DATA
</cfloop>
</cfoutput>
There is a lot of HTML code in the middle for outputing my data, but that is the basic structure of my Coldfusion code.
I'm assuming that my multiple queries within my CFOUTPUT tag are what's causing the performance issues correct? How can that be fixed using QoQ?
-Brian
Here is an easy one to do. Change the update statement to
<cfquery datasource="#datasource#">
update equipment_maintenance
set maintenance_due_date = #dueDate#
where machine_type != 'unifi_site' AND machine_type != 'firewall' AND machine_type != 'dvr' AND machine_type != 'pbx' AND active = 'yes'
</cfquery>
There is no need to give it a name because it is not returning any data
In a ColdFusion 11 application, I have a query object that contains strings that include an opening square bracket character - [. I need to be able to do a query of queries (QoQ) search of that query object to find any records that include the [ character, but I can't seem to find a way to escape it.
The best suggestion I've found - LIKE '%[[]%' - returns no results.
This code returns an error message:
<cfquery name="temp" dbType="query">
SELECT *
FROM myQuery
WHERE myField LIKE '%[%'
</cfquery>
This code also returns an error message:
<cfquery name="temp" dbType="query">
SELECT *
FROM myQuery
WHERE myField LIKE '%\[%' ESCAPE '\'
</cfquery>
And this code returns no records at all, even though I know the character is there:
<cfquery name="temp" dbType="query">
SELECT *
FROM myQuery
WHERE myField LIKE '%[[]%'
</cfquery>
Any suggestions would be greatly appreciated. Thanks.
You were close. Using the link that gfrobenius posted, you get this:
<cfquery name="temp" dbType="query">
SELECT *
FROM myQuery
WHERE myField LIKE '%[\[ ]%'
</cfquery>
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.
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.
I'll explain the 'real life' application of this so it's easier to understand.
I'm working on an eCommerce app that has a category structure. It starts at the top level and gradually moves down through subcategories. For example Home > Electronics > TVs > Plasma
I'm using a single page for this, showing the 'home' page if no category is defined, the subcategories if there are any, and finally the products if there are no subcategories.
This all works fine, however when I get to the 2nd part - displaying subcategories, the page is a little empty. Therefore, I'd like to display a selection of products that span all of the subcategories applicable.
This is where I'm struggling - in most cases, there will be a few subcategories. However, I'm not sure how to structure the 'where' query using the results of the previous query (code snippets below for reference).
I don't believe QofQ would be worth exploring, and I've made a vain attempt at doing something with substrings, without success.
Any pointers much appreciated!
<cfquery name="getcategories">
SELECT p.ID AS CategoryID, p.Cat_Name as CategoryName, p.Cat_Shortname, c.ID AS SubCategoryID, c.Cat_Name as SubCategoryName, c.Cat_Shortname AS SubCatShortname
FROM product_categories p LEFT JOIN product_categories c ON p.ID = c.SubcategoryOf
WHERE p.SubcategoryOf = 0
</cfquery>
<cfif IsDefined('url.cat')>
<!--- Look for additional subcategories --->
<cfquery name="getsubcategories">
SELECT *
FROM product_categories
WHERE Subcategoryof='#url.cat#'
</cfquery>
<cfquery name="getproducts">
SELECT *
FROM products
WHERE categoryid='#url.cat#'
ORDER BY RAND()
</cfquery>
</cfif>
Assuming your products table contains a subcategoryID of some kind you can use the following to get a list of sub category IDs from the query getsubcategories:
<cfset subCategoryIDs = valueList(getsubcategories.subCategoryID) >
This will give you a list of all subCategoryIDs. You can the feed this into the getproducts query like so:
<cfquery name="getproducts">
SELECT *
FROM products
WHERE subCategoryID in (<cfqueryparam cfsqltype="cf_sql_integer" value="#subCategoryIDs#" list="true">)
ORDER BY RAND()
</cfquery>
You should always cfqueryparam your query parameters.
If i understand your database structure, this query should return all products in all subcategories.
<cfquery name="getallproducts">
SELECT *
FROM products p LEFT JOIN product_categories pc ON p.categoryID = pc.ID
WHERE pc.Subcategoryof= <cfqueryparam cfsqltype="cf_sql_integer" value="#url.cat#">
</cfquery>
note: you really do want to use cfqueryparam here.